Skip to content

Commit

Permalink
Merge pull request #11827 from rouault/gdal_vector_sql
Browse files Browse the repository at this point in the history
Add 'gdal vector sql', as standalone or part of 'gdal vector pipeline'
  • Loading branch information
rouault authored Feb 10, 2025
2 parents 2409c7c + 40b4d5e commit 5935820
Show file tree
Hide file tree
Showing 16 changed files with 835 additions and 29 deletions.
1 change: 1 addition & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_library(
gdalalg_vector_read.cpp
gdalalg_vector_filter.cpp
gdalalg_vector_reproject.cpp
gdalalg_vector_sql.cpp
gdalalg_vector_write.cpp
gdalinfo_lib.cpp
gdalbuildvrt_lib.cpp
Expand Down
15 changes: 15 additions & 0 deletions apps/gdalalg_abstract_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "cpl_json.h"
#include "gdalalgorithm.h"

#include <algorithm>

template <class StepAlgorithm>
class GDALAbstractPipelineAlgorithm CPL_NON_FINAL : public StepAlgorithm
{
Expand All @@ -44,6 +46,19 @@ class GDALAbstractPipelineAlgorithm CPL_NON_FINAL : public StepAlgorithm
{
}

~GDALAbstractPipelineAlgorithm() override
{
// Destroy steps in the reverse order they have been constructed,
// as a step can create object that depends on the validity of
// objects of previous steps, and while cleaning them it needs those
// prior objects to be still alive.
// Typically for "gdal vector pipeline read ... ! sql ..."
for (auto it = std::rbegin(m_steps); it != std::rend(m_steps); it++)
{
it->reset();
}
}

virtual GDALArgDatasetValue &GetOutputDataset() = 0;

std::string m_pipeline{};
Expand Down
2 changes: 2 additions & 0 deletions apps/gdalalg_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "gdalalg_vector_pipeline.h"
#include "gdalalg_vector_filter.h"
#include "gdalalg_vector_reproject.h"
#include "gdalalg_vector_sql.h"

/************************************************************************/
/* GDALVectorAlgorithm */
Expand All @@ -43,6 +44,7 @@ class GDALVectorAlgorithm final : public GDALAlgorithm
RegisterSubAlgorithm<GDALVectorPipelineAlgorithm>();
RegisterSubAlgorithm<GDALVectorFilterAlgorithmStandalone>();
RegisterSubAlgorithm<GDALVectorReprojectAlgorithmStandalone>();
RegisterSubAlgorithm<GDALVectorSQLAlgorithmStandalone>();
}

private:
Expand Down
22 changes: 15 additions & 7 deletions apps/gdalalg_vector_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gdalalg_vector_clip.h"
#include "gdalalg_vector_filter.h"
#include "gdalalg_vector_reproject.h"
#include "gdalalg_vector_sql.h"
#include "gdalalg_vector_write.h"

#include "cpl_conv.h"
Expand Down Expand Up @@ -60,9 +61,12 @@ void GDALVectorPipelineStepAlgorithm::AddInputArgs(bool hiddenForCLI)
AddInputDatasetArg(&m_inputDataset, GDAL_OF_VECTOR,
/* positionalAndRequired = */ !hiddenForCLI)
.SetHiddenForCLI(hiddenForCLI);
AddArg("input-layer", 'l', _("Input layer name(s)"), &m_inputLayerNames)
.AddAlias("layer")
.SetHiddenForCLI(hiddenForCLI);
if (GetName() != "sql")
{
AddArg("input-layer", 'l', _("Input layer name(s)"), &m_inputLayerNames)
.AddAlias("layer")
.SetHiddenForCLI(hiddenForCLI);
}
}

/************************************************************************/
Expand Down Expand Up @@ -94,10 +98,13 @@ void GDALVectorPipelineStepAlgorithm::AddOutputArgs(
&m_appendLayer)
.SetDefault(false)
.SetHiddenForCLI(hiddenForCLI);
AddArg("output-layer", shortNameOutputLayerAllowed ? 'l' : 0,
_("Output layer name"), &m_outputLayerName)
.AddHiddenAlias("nln") // For ogr2ogr nostalgic people
.SetHiddenForCLI(hiddenForCLI);
if (GetName() != "sql")
{
AddArg("output-layer", shortNameOutputLayerAllowed ? 'l' : 0,
_("Output layer name"), &m_outputLayerName)
.AddHiddenAlias("nln") // For ogr2ogr nostalgic people
.SetHiddenForCLI(hiddenForCLI);
}
}

/************************************************************************/
Expand Down Expand Up @@ -178,6 +185,7 @@ GDALVectorPipelineAlgorithm::GDALVectorPipelineAlgorithm()
m_stepRegistry.Register<GDALVectorClipAlgorithm>();
m_stepRegistry.Register<GDALVectorReprojectAlgorithm>();
m_stepRegistry.Register<GDALVectorFilterAlgorithm>();
m_stepRegistry.Register<GDALVectorSQLAlgorithm>();
}

/************************************************************************/
Expand Down
Loading

0 comments on commit 5935820

Please sign in to comment.