LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/generic - ogrlayerarrow.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 25 25 100.0 %
Date: 2026-01-21 22:42:07 Functions: 7 7 100.0 %

          Line data    Source code
       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        2280 :     inline OGRArrowArrayStream()
      57        2280 :     {
      58        2280 :         memset(&m_stream, 0, sizeof(m_stream));
      59        2280 :     }
      60             : 
      61             :     /** Destructor: call release() on the ArrowArrayStream if not already done */
      62        2280 :     inline ~OGRArrowArrayStream()
      63        2280 :     {
      64        2280 :         clear();
      65        2280 :     }
      66             : 
      67             :     /** Call release() on the ArrowArrayStream if not already done */
      68             :     // cppcheck-suppress functionStatic
      69        3420 :     inline void clear()
      70             :     {
      71        3420 :         if (m_stream.release)
      72             :         {
      73         167 :             m_stream.release(&m_stream);
      74         167 :             m_stream.release = nullptr;
      75             :         }
      76        3420 :     }
      77             : 
      78             :     /** Return the raw ArrowArrayStream* */
      79         167 :     inline ArrowArrayStream *get()
      80             :     {
      81         167 :         return &m_stream;
      82             :     }
      83             : 
      84             :     /** Get the schema */
      85             :     // cppcheck-suppress functionStatic
      86         334 :     inline int get_schema(struct ArrowSchema *schema)
      87             :     {
      88         334 :         return m_stream.get_schema(&m_stream, schema);
      89             :     }
      90             : 
      91             :     /** Get the next ArrowArray batch */
      92             :     // cppcheck-suppress functionStatic
      93         323 :     inline int get_next(struct ArrowArray *array)
      94             :     {
      95         323 :         return m_stream.get_next(&m_stream, array);
      96             :     }
      97             : 
      98             :     /** Move assignment operator */
      99        1140 :     inline OGRArrowArrayStream &operator=(OGRArrowArrayStream &&other)
     100             :     {
     101        1140 :         if (this != &other)
     102             :         {
     103        1140 :             clear();
     104        1140 :             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        1140 :             memset(&(other.m_stream), 0, sizeof(m_stream));
     108             :         }
     109        1140 :         return *this;
     110             :     }
     111             : 
     112             :   private:
     113             :     struct ArrowArrayStream m_stream
     114             :     {
     115             :     };
     116             : 
     117             :     OGRArrowArrayStream(const OGRArrowArrayStream &) = delete;
     118             :     OGRArrowArrayStream(OGRArrowArrayStream &&) = delete;
     119             :     OGRArrowArrayStream &operator=(const OGRArrowArrayStream &) = delete;
     120             : };
     121             : 
     122             : #endif  // OGRLAYERARROW_H_DEFINED

Generated by: LCOV version 1.14