15#ifndef OGR_GENSQL_H_INCLUDED
16#define OGR_GENSQL_H_INCLUDED
27#define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
28 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
30#define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
31 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
32 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + \
33 (poFDefn)->GetGeomFieldCount()))
35#define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
36 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
44class OGRGenSQLResultsLayer final :
public OGRLayer
49 std::unique_ptr<swq_select> m_pSelectInfo{};
51 std::string m_osInitialWHERE{};
52 bool m_bForwardWhereToSourceLayer =
true;
56 std::vector<OGRLayer *> m_apoTableLayers{};
59 std::vector<std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>>
64 std::vector<int> m_anGeomFieldToSrcGeomField{};
66 std::vector<GIntBig> m_anFIDIndex{};
67 bool m_bOrderByValid =
false;
70 std::unique_ptr<OGRFeature> m_poSummaryFeature{};
72 int m_iFIDFieldIndex = 0;
74 GIntBig m_nIteratedFeatures = -1;
75 std::vector<std::string> m_aosDistinctList{};
77 bool PrepareSummary();
79 std::unique_ptr<OGRFeature> TranslateFeature(std::unique_ptr<OGRFeature>);
80 void CreateOrderByIndex();
81 void ReadIndexFields(
OGRFeature *poSrcFeat,
int nOrderItems,
83 void SortIndexSection(
const OGRField *pasIndexFields,
GIntBig *panMerged,
84 size_t nStart,
size_t nEntries);
85 void FreeIndexFields(
OGRField *pasIndexFields,
size_t l_nIndexSize);
89 void ApplyFiltersToSource();
91 void FindAndSetIgnoredFields();
92 void ExploreExprForIgnoredFields(swq_expr_node *expr,
CPLHashSet *hSet);
93 void AddFieldDefnToSet(
int iTable,
int iColumn,
CPLHashSet *hSet);
95 int ContainGeomSpecialField(swq_expr_node *expr);
97 void InvalidateOrderByIndex();
99 int MustEvaluateSpatialFilterOnGenSQL();
105 std::unique_ptr<swq_select> &&pSelectInfo,
106 const OGRGeometry *poSpatFilter,
const char *pszWHERE,
107 const char *pszDialect);
108 virtual ~OGRGenSQLResultsLayer();
127 int bForce = TRUE)
override;
143 struct ArrowSchema *out_schema)
override;
146 friend struct OGRGenSQLResultsLayerArrowStreamPrivateData;
148 int GetArrowSchemaForwarded(
struct ArrowArrayStream *stream,
149 struct ArrowSchema *out_schema)
const;
152 struct ArrowArray *out_array)
override;
154 int GetNextArrowArrayForwarded(
struct ArrowArrayStream *stream,
155 struct ArrowArray *out_array);
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:495
Simple container for a bounding region (rectangle)
Definition: ogr_core.h:45
Definition of a feature class or feature layer.
Definition: ogr_feature.h:501
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:877
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:361
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:58
virtual void SetSpatialFilter(OGRGeometry *)
Set a new spatial filter.
Definition: ogrlayer.cpp:1472
virtual GIntBig GetFeatureCount(int bForce=TRUE)
Fetch the feature count in this layer.
Definition: ogrlayer.cpp:158
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE)
Fetch the extent of this layer.
Definition: ogrlayer.cpp:196
virtual bool GetArrowStream(struct ArrowArrayStream *out_stream, CSLConstList papszOptions=nullptr)
Get a Arrow C stream.
Definition: ogrlayerarrow.cpp:2445
virtual OGRFeature * GetNextFeature()=0
Fetch the next available feature from this layer.
virtual int GetNextArrowArray(struct ArrowArrayStream *, struct ArrowArray *out_array)
Default implementation of the ArrowArrayStream::get_next() callback.
Definition: ogrlayerarrow.cpp:1826
virtual OGRFeatureDefn * GetLayerDefn()=0
Fetch the schema information for this layer.
virtual void ResetReading()=0
Reset feature reading to start on the first feature.
virtual OGRErr SetNextByIndex(GIntBig nIndex)
Move read cursor to the nIndex'th feature in the current resultset.
Definition: ogrlayer.cpp:583
virtual OGRErr SetAttributeFilter(const char *)
Set a new attribute query.
Definition: ogrlayer.cpp:421
virtual OGRFeature * GetFeature(GIntBig nFID)
Fetch a feature by its identifier.
Definition: ogrlayer.cpp:529
virtual int GetArrowSchema(struct ArrowArrayStream *, struct ArrowSchema *out_schema)
Default implementation of the ArrowArrayStream::get_schema() callback.
Definition: ogrlayerarrow.cpp:374
virtual OGRGeometry * GetSpatialFilter()
This method returns the current spatial filter for this layer.
Definition: ogrlayer.cpp:1403
virtual int TestCapability(const char *)=0
Test if this layer supported the named capability.
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:36
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1030
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:199
Various convenience functions for working with strings and string lists.
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:371
Classes related to registration of format support, and opening datasets.
OGRFeature field attribute value union.
Definition: ogr_core.h:905