GDAL
ogrlayerarrow.h
1/******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Parts of OGRLayer dealing with Arrow C interface
5 * Author: Even Rouault, <even dot rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2023, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef OGRLAYERARROW_H_DEFINED
14#define OGRLAYERARROW_H_DEFINED
15
16#include "cpl_port.h"
17
18#include <map>
19#include <string>
20
21#include "ogr_recordbatch.h"
22
23constexpr const char *ARROW_EXTENSION_NAME_KEY = "ARROW:extension:name";
24constexpr const char *ARROW_EXTENSION_METADATA_KEY = "ARROW:extension:metadata";
25constexpr const char *EXTENSION_NAME_OGC_WKB = "ogc.wkb";
26constexpr const char *EXTENSION_NAME_GEOARROW_WKB = "geoarrow.wkb";
27constexpr const char *EXTENSION_NAME_ARROW_JSON = "arrow.json";
28
29std::map<std::string, std::string>
30 CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
31
32bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
33 const struct ArrowArray *array,
34 struct ArrowArray *out_array);
35
36bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
37 struct ArrowSchema *out_schema);
38
41{
42 public:
45 {
46 memset(&m_stream, 0, sizeof(m_stream));
47 }
48
51 {
52 clear();
53 }
54
56 // cppcheck-suppress functionStatic
57 inline void clear()
58 {
59 if (m_stream.release)
60 {
61 m_stream.release(&m_stream);
62 m_stream.release = nullptr;
63 }
64 }
65
67 inline ArrowArrayStream *get()
68 {
69 return &m_stream;
70 }
71
73 // cppcheck-suppress functionStatic
74 inline int get_schema(struct ArrowSchema *schema)
75 {
76 return m_stream.get_schema(&m_stream, schema);
77 }
78
80 // cppcheck-suppress functionStatic
81 inline int get_next(struct ArrowArray *array)
82 {
83 return m_stream.get_next(&m_stream, array);
84 }
85
88 {
89 if (this != &other)
90 {
91 clear();
92 memcpy(&m_stream, &(other.m_stream), sizeof(m_stream));
93 memset(&(other.m_stream), 0, sizeof(m_stream));
94 }
95 return *this;
96 }
97
98 private:
99 struct ArrowArrayStream m_stream
100 {
101 };
102
106};
107
108#endif // OGRLAYERARROW_H_DEFINED
C++ wrapper on top of ArrowArrayStream.
Definition: ogrlayerarrow.h:41
ArrowArrayStream * get()
Return the raw ArrowArrayStream*.
Definition: ogrlayerarrow.h:67
int get_next(struct ArrowArray *array)
Get the next ArrowArray batch.
Definition: ogrlayerarrow.h:81
int get_schema(struct ArrowSchema *schema)
Get the schema.
Definition: ogrlayerarrow.h:74
OGRArrowArrayStream & operator=(OGRArrowArrayStream &&other)
Move assignment operator.
Definition: ogrlayerarrow.h:87
OGRArrowArrayStream()
Constructor: instantiate an empty ArrowArrayStream
Definition: ogrlayerarrow.h:44
void clear()
Call release() on the ArrowArrayStream if not already done.
Definition: ogrlayerarrow.h:57
~OGRArrowArrayStream()
Destructor: call release() on the ArrowArrayStream if not already done.
Definition: ogrlayerarrow.h:50
Core portability definitions for CPL.