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: 2024-11-21 22:18:42 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             : constexpr const char *EXTENSION_NAME_ARROW_JSON = "arrow.json";
      28             : 
      29             : std::map<std::string, std::string>
      30             :     CPL_DLL OGRParseArrowMetadata(const char *pabyMetadata);
      31             : 
      32             : bool CPL_DLL OGRCloneArrowArray(const struct ArrowSchema *schema,
      33             :                                 const struct ArrowArray *array,
      34             :                                 struct ArrowArray *out_array);
      35             : 
      36             : bool CPL_DLL OGRCloneArrowSchema(const struct ArrowSchema *schema,
      37             :                                  struct ArrowSchema *out_schema);
      38             : 
      39             : /** C++ wrapper on top of ArrowArrayStream */
      40             : class OGRArrowArrayStream
      41             : {
      42             :   public:
      43             :     /** Constructor: instantiate an empty ArrowArrayStream  */
      44        1686 :     inline OGRArrowArrayStream()
      45        1686 :     {
      46        1686 :         memset(&m_stream, 0, sizeof(m_stream));
      47        1686 :     }
      48             : 
      49             :     /** Destructor: call release() on the ArrowArrayStream if not already done */
      50        1686 :     inline ~OGRArrowArrayStream()
      51        1686 :     {
      52        1686 :         clear();
      53        1686 :     }
      54             : 
      55             :     /** Call release() on the ArrowArrayStream if not already done */
      56             :     // cppcheck-suppress functionStatic
      57        2529 :     inline void clear()
      58             :     {
      59        2529 :         if (m_stream.release)
      60             :         {
      61         142 :             m_stream.release(&m_stream);
      62         142 :             m_stream.release = nullptr;
      63             :         }
      64        2529 :     }
      65             : 
      66             :     /** Return the raw ArrowArrayStream* */
      67         142 :     inline ArrowArrayStream *get()
      68             :     {
      69         142 :         return &m_stream;
      70             :     }
      71             : 
      72             :     /** Get the schema */
      73             :     // cppcheck-suppress functionStatic
      74         284 :     inline int get_schema(struct ArrowSchema *schema)
      75             :     {
      76         284 :         return m_stream.get_schema(&m_stream, schema);
      77             :     }
      78             : 
      79             :     /** Get the next ArrowArray batch */
      80             :     // cppcheck-suppress functionStatic
      81         283 :     inline int get_next(struct ArrowArray *array)
      82             :     {
      83         283 :         return m_stream.get_next(&m_stream, array);
      84             :     }
      85             : 
      86             :     /** Move assignment operator */
      87         843 :     inline OGRArrowArrayStream &operator=(OGRArrowArrayStream &&other)
      88             :     {
      89         843 :         if (this != &other)
      90             :         {
      91         843 :             clear();
      92         843 :             memcpy(&m_stream, &(other.m_stream), sizeof(m_stream));
      93             :             // Reset other content, in particular its "release" member
      94             :             // as per https://arrow.apache.org/docs/format/CDataInterface.html#moving-an-array
      95         843 :             memset(&(other.m_stream), 0, sizeof(m_stream));
      96             :         }
      97         843 :         return *this;
      98             :     }
      99             : 
     100             :   private:
     101             :     struct ArrowArrayStream m_stream
     102             :     {
     103             :     };
     104             : 
     105             :     OGRArrowArrayStream(const OGRArrowArrayStream &) = delete;
     106             :     OGRArrowArrayStream(OGRArrowArrayStream &&) = delete;
     107             :     OGRArrowArrayStream &operator=(const OGRArrowArrayStream &) = delete;
     108             : };
     109             : 
     110             : #endif  // OGRLAYERARROW_H_DEFINED

Generated by: LCOV version 1.14