Coverage Report

Created: 2026-02-14 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/ogr/ogrsf_frmts/generic/ogrlayerarrow.h
Line
Count
Source
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
23
constexpr const char *ARROW_EXTENSION_NAME_KEY = "ARROW:extension:name";
24
constexpr const char *ARROW_EXTENSION_METADATA_KEY = "ARROW:extension:metadata";
25
constexpr const char *EXTENSION_NAME_OGC_WKB = "ogc.wkb";
26
constexpr const char *EXTENSION_NAME_GEOARROW_WKB = "geoarrow.wkb";
27
28
// Cf https://github.com/apache/arrow/blob/main/docs/source/format/CanonicalExtensions.rst#json
29
constexpr 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
32
constexpr const char *EXTENSION_NAME_ARROW_TIMESTAMP_WITH_OFFSET =
33
    "arrow.timestamp_with_offset";
34
// ATSWO = Arrow TimeStamp With Offset
35
constexpr const char *ATSWO_TIMESTAMP_FIELD_NAME = "timestamp";
36
constexpr const char *ATSWO_OFFSET_MINUTES_FIELD_NAME = "offset_minutes";
37
38
// GetArrowStream(GAS) options
39
constexpr const char *GAS_OPT_DATETIME_AS_STRING = "DATETIME_AS_STRING";
40
41
std::map<std::string, std::string>
42
    CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
43
44
bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
45
                                const struct ArrowArray *array,
46
                                struct ArrowArray *out_array);
47
48
bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
49
                                 struct ArrowSchema *out_schema);
50
51
/** C++ wrapper on top of ArrowArrayStream */
52
class OGRArrowArrayStream
53
{
54
  public:
55
    /** Constructor: instantiate an empty ArrowArrayStream  */
56
    inline OGRArrowArrayStream()
57
0
    {
58
0
        memset(&m_stream, 0, sizeof(m_stream));
59
0
    }
60
61
    /** Destructor: call release() on the ArrowArrayStream if not already done */
62
    inline ~OGRArrowArrayStream()
63
0
    {
64
0
        clear();
65
0
    }
66
67
    /** Call release() on the ArrowArrayStream if not already done */
68
    // cppcheck-suppress functionStatic
69
    inline void clear()
70
0
    {
71
0
        if (m_stream.release)
72
0
        {
73
0
            m_stream.release(&m_stream);
74
0
            m_stream.release = nullptr;
75
0
        }
76
0
    }
77
78
    /** Return the raw ArrowArrayStream* */
79
    inline ArrowArrayStream *get()
80
0
    {
81
0
        return &m_stream;
82
0
    }
83
84
    /** Get the schema */
85
    // cppcheck-suppress functionStatic
86
    inline int get_schema(struct ArrowSchema *schema)
87
0
    {
88
0
        return m_stream.get_schema(&m_stream, schema);
89
0
    }
90
91
    /** Get the next ArrowArray batch */
92
    // cppcheck-suppress functionStatic
93
    inline int get_next(struct ArrowArray *array)
94
0
    {
95
0
        return m_stream.get_next(&m_stream, array);
96
0
    }
97
98
    /** Move assignment operator */
99
    inline OGRArrowArrayStream &operator=(OGRArrowArrayStream &&other)
100
0
    {
101
0
        if (this != &other)
102
0
        {
103
0
            clear();
104
0
            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
0
            memset(&(other.m_stream), 0, sizeof(m_stream));
108
0
        }
109
0
        return *this;
110
0
    }
111
112
  private:
113
    struct ArrowArrayStream m_stream{};
114
115
    OGRArrowArrayStream(const OGRArrowArrayStream &) = delete;
116
    OGRArrowArrayStream(OGRArrowArrayStream &&) = delete;
117
    OGRArrowArrayStream &operator=(const OGRArrowArrayStream &) = delete;
118
};
119
120
#endif  // OGRLAYERARROW_H_DEFINED