Coverage Report

Created: 2025-06-13 06:29

/src/gdal/ogr/ogrsf_frmts/generic/ogrlayerarrow.h
Line
Count
Source (jump to first uncovered line)
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
constexpr const char *EXTENSION_NAME_ARROW_JSON = "arrow.json";
28
29
// GetArrowStream(GAS) options
30
constexpr const char *GAS_OPT_DATETIME_AS_STRING = "DATETIME_AS_STRING";
31
32
std::map<std::string, std::string>
33
    CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
34
35
bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
36
                                const struct ArrowArray *array,
37
                                struct ArrowArray *out_array);
38
39
bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
40
                                 struct ArrowSchema *out_schema);
41
42
/** C++ wrapper on top of ArrowArrayStream */
43
class OGRArrowArrayStream
44
{
45
  public:
46
    /** Constructor: instantiate an empty ArrowArrayStream  */
47
    inline OGRArrowArrayStream()
48
0
    {
49
0
        memset(&m_stream, 0, sizeof(m_stream));
50
0
    }
51
52
    /** Destructor: call release() on the ArrowArrayStream if not already done */
53
    inline ~OGRArrowArrayStream()
54
0
    {
55
0
        clear();
56
0
    }
57
58
    /** Call release() on the ArrowArrayStream if not already done */
59
    // cppcheck-suppress functionStatic
60
    inline void clear()
61
0
    {
62
0
        if (m_stream.release)
63
0
        {
64
0
            m_stream.release(&m_stream);
65
0
            m_stream.release = nullptr;
66
0
        }
67
0
    }
68
69
    /** Return the raw ArrowArrayStream* */
70
    inline ArrowArrayStream *get()
71
0
    {
72
0
        return &m_stream;
73
0
    }
74
75
    /** Get the schema */
76
    // cppcheck-suppress functionStatic
77
    inline int get_schema(struct ArrowSchema *schema)
78
0
    {
79
0
        return m_stream.get_schema(&m_stream, schema);
80
0
    }
81
82
    /** Get the next ArrowArray batch */
83
    // cppcheck-suppress functionStatic
84
    inline int get_next(struct ArrowArray *array)
85
0
    {
86
0
        return m_stream.get_next(&m_stream, array);
87
0
    }
88
89
    /** Move assignment operator */
90
    inline OGRArrowArrayStream &operator=(OGRArrowArrayStream &&other)
91
0
    {
92
0
        if (this != &other)
93
0
        {
94
0
            clear();
95
0
            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
0
            memset(&(other.m_stream), 0, sizeof(m_stream));
99
0
        }
100
0
        return *this;
101
0
    }
102
103
  private:
104
    struct ArrowArrayStream m_stream
105
    {
106
    };
107
108
    OGRArrowArrayStream(const OGRArrowArrayStream &) = delete;
109
    OGRArrowArrayStream(OGRArrowArrayStream &&) = delete;
110
    OGRArrowArrayStream &operator=(const OGRArrowArrayStream &) = delete;
111
};
112
113
#endif  // OGRLAYERARROW_H_DEFINED