14#ifndef OGR_GENSQL_H_INCLUDED
15#define OGR_GENSQL_H_INCLUDED
26#define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
27 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
29#define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
30 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
31 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + \
32 (poFDefn)->GetGeomFieldCount()))
34#define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
35 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
43class OGRGenSQLResultsLayer final :
public OGRLayer
46 GDALDataset *m_poSrcDS =
nullptr;
47 OGRLayer *m_poSrcLayer =
nullptr;
48 std::unique_ptr<swq_select> m_pSelectInfo{};
50 std::string m_osInitialWHERE{};
51 bool m_bForwardWhereToSourceLayer =
true;
53 bool m_bSpatialFilterSetOnSourceLayer =
false;
56 std::vector<OGRLayer *> m_apoTableLayers{};
59 std::vector<std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>>
62 OGRFeatureDefn *m_poDefn =
nullptr;
64 std::vector<int> m_anGeomFieldToSrcGeomField{};
66 std::vector<GIntBig> m_anFIDIndex{};
67 bool m_bOrderByValid =
false;
70 mutable 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()
const;
79 std::unique_ptr<OGRFeature> TranslateFeature(std::unique_ptr<OGRFeature>);
80 void CreateOrderByIndex();
81 void ReadIndexFields(OGRFeature *poSrcFeat,
int nOrderItems,
82 OGRField *pasIndexFields);
83 void SortIndexSection(
const OGRField *pasIndexFields,
GIntBig *panMerged,
84 size_t nStart,
size_t nEntries);
85 void FreeIndexFields(OGRField *pasIndexFields,
size_t l_nIndexSize);
86 int Compare(
const OGRField *pasFirst,
const OGRField *pasSecond);
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(
const swq_expr_node *expr)
const;
97 void InvalidateOrderByIndex();
99 int MustEvaluateSpatialFilterOnGenSQL();
104 OGRGenSQLResultsLayer(GDALDataset *poSrcDS,
105 std::unique_ptr<swq_select> &&pSelectInfo,
106 const OGRGeometry *poSpatFilter,
const char *pszWHERE,
107 const char *pszDialect);
108 ~OGRGenSQLResultsLayer()
override;
110 OGRGeometry *GetSpatialFilter()
override;
112 void ResetReading()
override;
113 OGRFeature *GetNextFeature()
override;
115 OGRFeature *GetFeature(
GIntBig nFID)
override;
117 const OGRFeatureDefn *GetLayerDefn()
const override;
119 GIntBig GetFeatureCount(
int bForce = TRUE)
override;
121 OGRErr IGetExtent(
int iGeomField, OGREnvelope *psExtent,
122 bool bForce)
override;
124 int TestCapability(
const char *)
const override;
126 virtual OGRErr ISetSpatialFilter(
int iGeomField,
127 const OGRGeometry *)
override;
128 OGRErr SetAttributeFilter(
const char *)
override;
130 bool GetArrowStream(
struct ArrowArrayStream *out_stream,
133 int GetArrowSchema(
struct ArrowArrayStream *stream,
134 struct ArrowSchema *out_schema)
override;
137 friend struct OGRGenSQLResultsLayerArrowStreamPrivateData;
139 int GetArrowSchemaForwarded(
struct ArrowArrayStream *stream,
140 struct ArrowSchema *out_schema)
const;
142 int GetNextArrowArray(
struct ArrowArrayStream *stream,
143 struct ArrowArray *out_array)
override;
145 int GetNextArrowArrayForwarded(
struct ArrowArrayStream *stream,
146 struct ArrowArray *out_array);
This class represents a layer of simple features, with access methods.
Definition ogrsf_frmts.h:61
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition cpl_hash_set.h:35
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
Various convenience functions for working with strings and string lists.
int OGRErr
Type for a OGR error.
Definition ogr_core.h:388
Classes related to registration of format support, and opening datasets.