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";
27
28// Cf https://github.com/apache/arrow/blob/main/docs/source/format/CanonicalExtensions.rst#json
29constexpr const char *EXTENSION_NAME_ARROW_JSON = "arrow.json";
30
31// Cf https://github.com/apache/arrow/blob/main/docs/source/format/CanonicalExtensions.rst#timestamp-with-offset
32constexpr const char *EXTENSION_NAME_ARROW_TIMESTAMP_WITH_OFFSET =
33 "arrow.timestamp_with_offset";
34// ATSWO = Arrow TimeStamp With Offset
35constexpr const char *ATSWO_TIMESTAMP_FIELD_NAME = "timestamp";
36constexpr const char *ATSWO_OFFSET_MINUTES_FIELD_NAME = "offset_minutes";
37
38// GetArrowStream(GAS) options
39constexpr const char *GAS_OPT_DATETIME_AS_STRING = "DATETIME_AS_STRING";
40
41std::map<std::string, std::string>
42 CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
43
44bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
45 const struct ArrowArray *array,
46 struct ArrowArray *out_array);
47
48bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
49 struct ArrowSchema *out_schema);
50
53{
54 public:
57 {
58 memset(&m_stream, 0, sizeof(m_stream));
59 }
60
63 {
64 clear();
65 }
66
68 // cppcheck-suppress functionStatic
69 inline void clear()
70 {
71 if (m_stream.release)
72 {
73 m_stream.release(&m_stream);
74 m_stream.release = nullptr;
75 }
76 }
77
79 inline ArrowArrayStream *get()
80 {
81 return &m_stream;
82 }
83
85 // cppcheck-suppress functionStatic
86 inline int get_schema(struct ArrowSchema *schema)
87 {
88 return m_stream.get_schema(&m_stream, schema);
89 }
90
92 // cppcheck-suppress functionStatic
93 inline int get_next(struct ArrowArray *array)
94 {
95 return m_stream.get_next(&m_stream, array);
96 }
97
100 {
101 if (this != &other)
102 {
103 clear();
104 memcpy(&m_stream, &(other.m_stream), sizeof(m_stream));
105 // Reset other content, in particular its "release" member
106 // as per https://arrow.apache.org/docs/format/CDataInterface.html#moving-an-array
107 memset(&(other.m_stream), 0, sizeof(m_stream));
108 }
109 return *this;
110 }
111
112 private:
113 struct ArrowArrayStream m_stream{};
114
118};
119
120#endif // OGRLAYERARROW_H_DEFINED
C++ wrapper on top of ArrowArrayStream.
Definition ogrlayerarrow.h:53
ArrowArrayStream * get()
Return the raw ArrowArrayStream*.
Definition ogrlayerarrow.h:79
int get_next(struct ArrowArray *array)
Get the next ArrowArray batch.
Definition ogrlayerarrow.h:93
int get_schema(struct ArrowSchema *schema)
Get the schema.
Definition ogrlayerarrow.h:86
OGRArrowArrayStream & operator=(OGRArrowArrayStream &&other)
Move assignment operator.
Definition ogrlayerarrow.h:99
OGRArrowArrayStream()
Constructor: instantiate an empty ArrowArrayStream
Definition ogrlayerarrow.h:56
void clear()
Call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:69
~OGRArrowArrayStream()
Destructor: call release() on the ArrowArrayStream if not already done.
Definition ogrlayerarrow.h:62
Core portability definitions for CPL.