Skip to content

Commit 59e4e1f

Browse files
committed
gdal vector pipeline read --layer: make sure ExecuteSQL() forwards to the source dataset
1 parent daed887 commit 59e4e1f

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

apps/gdalalg_vector_read.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class GDALVectorPipelineReadOutputDataset final : public GDALDataset
6161

6262
void ResetReading() override;
6363

64+
OGRLayer *ExecuteSQL(const char *pszStatement, OGRGeometry *poSpatialFilter,
65+
const char *pszDialect) override;
66+
void ReleaseResultSet(OGRLayer *poResultsSet) override;
67+
6468
OGRFeature *GetNextFeature(OGRLayer **ppoBelongingLayer,
6569
double *pdfProgressPct,
6670
GDALProgressFunc pfnProgress,
@@ -137,6 +141,28 @@ void GDALVectorPipelineReadOutputDataset::ResetReading()
137141
m_srcDS.ResetReading();
138142
}
139143

144+
/************************************************************************/
145+
/* GDALVectorPipelineReadOutputDataset::ExecuteSQL() */
146+
/************************************************************************/
147+
148+
OGRLayer *
149+
GDALVectorPipelineReadOutputDataset::ExecuteSQL(const char *pszStatement,
150+
OGRGeometry *poSpatialFilter,
151+
const char *pszDialect)
152+
{
153+
return m_srcDS.ExecuteSQL(pszStatement, poSpatialFilter, pszDialect);
154+
}
155+
156+
/************************************************************************/
157+
/* GDALVectorPipelineReadOutputDataset::ReleaseResultSet() */
158+
/************************************************************************/
159+
160+
void GDALVectorPipelineReadOutputDataset::ReleaseResultSet(
161+
OGRLayer *poResultsSet)
162+
{
163+
m_srcDS.ReleaseResultSet(poResultsSet);
164+
}
165+
140166
/************************************************************************/
141167
/* GDALVectorPipelineReadOutputDataset::GetNextFeature() */
142168
/************************************************************************/

autotest/utilities/test_gdalalg_vector_pipeline.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,3 +1091,18 @@ def test_gdalalg_vector_pipeline_read_ds_take_ref(tmp_vsimem):
10911091
ds = ogr.Open(f"{tmp_vsimem}/out.shp")
10921092
lyr = ds.GetLayer(0)
10931093
assert lyr.GetFeatureCount() == 10
1094+
1095+
1096+
@pytest.mark.require_driver("GPKG")
1097+
def test_gdalalg_vector_pipeline_read_execute_sql(tmp_vsimem):
1098+
1099+
tmp_filename = tmp_vsimem / "tmp.gpkg"
1100+
gdal.alg.vector.convert(input="../ogr/data/poly.shp", output=tmp_filename)
1101+
1102+
gdal.alg.vector.pipeline(
1103+
pipeline=f'read {tmp_filename} --layer poly ! sql --sql "select * from poly group by eas_id" ! write {tmp_vsimem}/out.shp'
1104+
)
1105+
1106+
ds = ogr.Open(f"{tmp_vsimem}/out.shp")
1107+
lyr = ds.GetLayer(0)
1108+
assert lyr.GetFeatureCount() == 10

0 commit comments

Comments
 (0)