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
29// GetArrowStream(GAS) options
30constexpr const char *GAS_OPT_DATETIME_AS_STRING = "DATETIME_AS_STRING";
31
32std::map<std::string, std::string>
33 CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
34
35bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
36 const struct ArrowArray *array,
37 struct ArrowArray *out_array);
38
39bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
40 struct ArrowSchema *out_schema);
41
44{
45 public:
48 {
49 memset(&m_stream, 0, sizeof(m_stream));
50 }
51
54 {
55 clear();
56 }
57
59 // cppcheck-suppress functionStatic
60 inline void clear()
61 {
62 if (m_stream.release)
63 {
64 m_stream.release(&m_stream);
65 m_stream.release = nullptr;
66 }
67 }
68
70 inline ArrowArrayStream *get()
71 {
72 return &m_stream;
73 }
74
76 // cppcheck-suppress functionStatic
77 inline int get_schema(struct ArrowSchema *schema)
78 {
79 return m_stream.get_schema(&m_stream, schema);
80 }
81
83 // cppcheck-suppress functionStatic
84 inline int get_next(struct ArrowArray *array)
85 {
86 return m_stream.get_next(&m_stream, array);
87 }
88
91 {
92 if (this != &other)
93 {
94 clear();
95 memcpy(&m_stream, &(other.m_stream), sizeof(m_stream));
96 // Reset other content, in particular its "release" member
97 // as per https://arrow.apache.org/docs/format/CDataInterface.html#moving-an-array
98 memset(&(other.m_stream), 0, sizeof(m_stream));
99 }
100 return *this;
101 }
102
103 private:
104 struct ArrowArrayStream m_stream
105 {
106 };
107
111};
112
113#endif // OGRLAYERARROW_H_DEFINED
ArrowArrayStream * get()
Return the raw ArrowArrayStream*.
Definition ogrlayerarrow.h:70
int get_next(struct ArrowArray *array)
Get the next ArrowArray batch.
Definition ogrlayerarrow.h:84
int get_schema(struct ArrowSchema *schema)
Get the schema.
Definition ogrlayerarrow.h:77
OGRArrowArrayStream & operator=(OGRArrowArrayStream &&other)
Move assignment operator.
Definition ogrlayerarrow.h:90
OGRArrowArrayStream()
Constructor: instantiate an empty ArrowArrayStream.
Definition ogrlayerarrow.h:47
void clear()
Call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:60
~OGRArrowArrayStream()
Destructor: call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:53
Core portability definitions for CPL.