Skip to content

Commit b2bc307

Browse files
committed
Add 'gdal vector sql', as standalone or part of 'gdal vector pipeline'
1 parent 6332083 commit b2bc307

16 files changed

+814
-29
lines changed

apps/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_library(
3131
gdalalg_vector_read.cpp
3232
gdalalg_vector_filter.cpp
3333
gdalalg_vector_reproject.cpp
34+
gdalalg_vector_sql.cpp
3435
gdalalg_vector_write.cpp
3536
gdalinfo_lib.cpp
3637
gdalbuildvrt_lib.cpp

apps/gdalalg_abstract_pipeline.h

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "cpl_json.h"
2020
#include "gdalalgorithm.h"
2121

22+
#include <algorithm>
23+
2224
template <class StepAlgorithm>
2325
class GDALAbstractPipelineAlgorithm CPL_NON_FINAL : public StepAlgorithm
2426
{
@@ -44,6 +46,19 @@ class GDALAbstractPipelineAlgorithm CPL_NON_FINAL : public StepAlgorithm
4446
{
4547
}
4648

49+
~GDALAbstractPipelineAlgorithm() override
50+
{
51+
// Destroy steps in the reverse order they have been constructed,
52+
// as a step can create object that depends on the validity of
53+
// objects of previous steps, and while cleaning them it needs those
54+
// prior objects to be still alive.
55+
// Typically for "gdal vector pipeline read ... ! sql ..."
56+
for (auto it = std::rbegin(m_steps); it != std::rend(m_steps); it++)
57+
{
58+
it->reset();
59+
}
60+
}
61+
4762
virtual GDALArgDatasetValue &GetOutputDataset() = 0;
4863

4964
std::string m_pipeline{};

apps/gdalalg_vector.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "gdalalg_vector_pipeline.h"
1919
#include "gdalalg_vector_filter.h"
2020
#include "gdalalg_vector_reproject.h"
21+
#include "gdalalg_vector_sql.h"
2122

2223
/************************************************************************/
2324
/* GDALVectorAlgorithm */
@@ -43,6 +44,7 @@ class GDALVectorAlgorithm final : public GDALAlgorithm
4344
RegisterSubAlgorithm<GDALVectorPipelineAlgorithm>();
4445
RegisterSubAlgorithm<GDALVectorFilterAlgorithmStandalone>();
4546
RegisterSubAlgorithm<GDALVectorReprojectAlgorithmStandalone>();
47+
RegisterSubAlgorithm<GDALVectorSQLAlgorithmStandalone>();
4648
}
4749

4850
private:

apps/gdalalg_vector_pipeline.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "gdalalg_vector_clip.h"
1616
#include "gdalalg_vector_filter.h"
1717
#include "gdalalg_vector_reproject.h"
18+
#include "gdalalg_vector_sql.h"
1819
#include "gdalalg_vector_write.h"
1920

2021
#include "cpl_conv.h"
@@ -60,9 +61,12 @@ void GDALVectorPipelineStepAlgorithm::AddInputArgs(bool hiddenForCLI)
6061
AddInputDatasetArg(&m_inputDataset, GDAL_OF_VECTOR,
6162
/* positionalAndRequired = */ !hiddenForCLI)
6263
.SetHiddenForCLI(hiddenForCLI);
63-
AddArg("input-layer", 'l', _("Input layer name(s)"), &m_inputLayerNames)
64-
.AddAlias("layer")
65-
.SetHiddenForCLI(hiddenForCLI);
64+
if (GetName() != "sql")
65+
{
66+
AddArg("input-layer", 'l', _("Input layer name(s)"), &m_inputLayerNames)
67+
.AddAlias("layer")
68+
.SetHiddenForCLI(hiddenForCLI);
69+
}
6670
}
6771

6872
/************************************************************************/
@@ -94,10 +98,13 @@ void GDALVectorPipelineStepAlgorithm::AddOutputArgs(
9498
&m_appendLayer)
9599
.SetDefault(false)
96100
.SetHiddenForCLI(hiddenForCLI);
97-
AddArg("output-layer", shortNameOutputLayerAllowed ? 'l' : 0,
98-
_("Output layer name"), &m_outputLayerName)
99-
.AddHiddenAlias("nln") // For ogr2ogr nostalgic people
100-
.SetHiddenForCLI(hiddenForCLI);
101+
if (GetName() != "sql")
102+
{
103+
AddArg("output-layer", shortNameOutputLayerAllowed ? 'l' : 0,
104+
_("Output layer name"), &m_outputLayerName)
105+
.AddHiddenAlias("nln") // For ogr2ogr nostalgic people
106+
.SetHiddenForCLI(hiddenForCLI);
107+
}
101108
}
102109

103110
/************************************************************************/
@@ -178,6 +185,7 @@ GDALVectorPipelineAlgorithm::GDALVectorPipelineAlgorithm()
178185
m_stepRegistry.Register<GDALVectorClipAlgorithm>();
179186
m_stepRegistry.Register<GDALVectorReprojectAlgorithm>();
180187
m_stepRegistry.Register<GDALVectorFilterAlgorithm>();
188+
m_stepRegistry.Register<GDALVectorSQLAlgorithm>();
181189
}
182190

183191
/************************************************************************/

0 commit comments

Comments
 (0)