diff --git a/duckdb b/duckdb index 19864453..fc4b8d47 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit 19864453f7d0ed095256d848b46e7b8630989bac +Subproject commit fc4b8d4794d0dfe62764ae5d03270d34264c005f diff --git a/spatial/include/spatial/doc_util.hpp b/spatial/include/spatial/doc_util.hpp index 6262c18a..5745f67c 100644 --- a/spatial/include/spatial/doc_util.hpp +++ b/spatial/include/spatial/doc_util.hpp @@ -12,21 +12,18 @@ struct DocTag { struct DocUtil { static void AddDocumentation(duckdb::DatabaseInstance &db, const char *function_name, const char *description, const char *example, - const duckdb::unordered_map &tags); + const duckdb::unordered_map &tags, duckdb::vector parameter_names = {}); // Abuse adding tags as a comment template static void AddDocumentation(duckdb::DatabaseInstance &db, const char *function_name, const char *description, - const char *example, const DocTag (&tags)[N]) { + const char *example, const DocTag (&tags)[N], duckdb::vector parameter_names = {}) { duckdb::unordered_map tag_map; for (size_t i = 0; i < N; i++) { tag_map[tags[i].key] = tags[i].value; } - AddDocumentation(db, function_name, description, example, tag_map); + AddDocumentation(db, function_name, description, example, tag_map, parameter_names); } - - static void AddFunctionParameterNames(duckdb::DatabaseInstance &db, const char *function_name, - duckdb::vector names); }; -} // namespace spatial \ No newline at end of file +} // namespace spatial diff --git a/spatial/src/spatial/core/functions/scalar/st_collectionextract.cpp b/spatial/src/spatial/core/functions/scalar/st_collectionextract.cpp index 78c3f7d9..82ad4598 100644 --- a/spatial/src/spatial/core/functions/scalar/st_collectionextract.cpp +++ b/spatial/src/spatial/core/functions/scalar/st_collectionextract.cpp @@ -196,10 +196,9 @@ void CoreScalarFunctions::RegisterStCollectionExtract(DatabaseInstance &db) { GeometryFunctionLocalState::Init)); ExtensionUtil::RegisterFunction(db, set); - DocUtil::AddDocumentation(db, "ST_CollectionExtract", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS); - DocUtil::AddFunctionParameterNames(db, "ST_CollectionExtract", {"geom", "type"}); + DocUtil::AddDocumentation(db, "ST_CollectionExtract", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS, {"geom", "type"}); } } // namespace core -} // namespace spatial \ No newline at end of file +} // namespace spatial diff --git a/spatial/src/spatial/core/functions/table/st_generatepoints.cpp b/spatial/src/spatial/core/functions/table/st_generatepoints.cpp index 007d386d..8754619a 100644 --- a/spatial/src/spatial/core/functions/table/st_generatepoints.cpp +++ b/spatial/src/spatial/core/functions/table/st_generatepoints.cpp @@ -79,8 +79,8 @@ static void Execute(ClientContext &context, TableFunctionInput &data_p, DataChun const auto chunk_size = MinValue(STANDARD_VECTOR_SIZE, bind_data.count - state.current_idx); for (idx_t i = 0; i < chunk_size; i++) { - x_data[i] = state.rng.NextRandom(bind_data.bbox.min.x, bind_data.bbox.max.x); - y_data[i] = state.rng.NextRandom(bind_data.bbox.min.y, bind_data.bbox.max.y); + x_data[i] = state.rng.NextRandom32(bind_data.bbox.min.x, bind_data.bbox.max.x); + y_data[i] = state.rng.NextRandom32(bind_data.bbox.min.y, bind_data.bbox.max.y); state.current_idx++; } diff --git a/spatial/src/spatial/core/index/rtree/rtree_index_plan_scan.cpp b/spatial/src/spatial/core/index/rtree/rtree_index_plan_scan.cpp index 65f5c189..23ddb2d6 100644 --- a/spatial/src/spatial/core/index/rtree/rtree_index_plan_scan.cpp +++ b/spatial/src/spatial/core/index/rtree/rtree_index_plan_scan.cpp @@ -46,7 +46,7 @@ class RTreeIndexScanOptimizer : public OptimizerExtension { column_t referenced_column = column_ids[bound_colref.binding.column_index]; // search for the referenced column in the set of column_ids for (idx_t i = 0; i < get_column_ids.size(); i++) { - if (get_column_ids[i] == referenced_column) { + if (get_column_ids[i].GetPrimaryIndex() == referenced_column) { bound_colref.binding.column_index = i; return; } @@ -213,7 +213,7 @@ class RTreeIndexScanOptimizer : public OptimizerExtension { auto &type = get.returned_types[column_id]; bool found = false; for (idx_t i = 0; i < column_ids.size(); i++) { - if (column_ids[i] == column_id) { + if (column_ids[i].GetPrimaryIndex() == column_id) { column_id = i; found = true; break; diff --git a/spatial/src/spatial/core/index/rtree/rtree_index_scan.cpp b/spatial/src/spatial/core/index/rtree/rtree_index_scan.cpp index 01f2966a..101ac45d 100644 --- a/spatial/src/spatial/core/index/rtree/rtree_index_scan.cpp +++ b/spatial/src/spatial/core/index/rtree/rtree_index_scan.cpp @@ -31,7 +31,7 @@ BindInfo RTreeIndexScanBindInfo(const optional_ptr bind_data_p) { struct RTreeIndexScanGlobalState : public GlobalTableFunctionState { ColumnFetchState fetch_state; TableScanState local_storage_state; - vector column_ids; + vector column_ids; // Index scan state unique_ptr index_state; @@ -54,7 +54,7 @@ static unique_ptr RTreeIndexScanInitGlobal(ClientConte if (id != DConstants::INVALID_INDEX) { col_id = bind_data.table.GetColumn(LogicalIndex(id)).StorageOid(); } - result->column_ids.push_back(col_id); + result->column_ids.emplace_back(col_id); } // Initialize the storage scan state @@ -128,9 +128,13 @@ unique_ptr RTreeIndexScanCardinality(ClientContext &context, con //------------------------------------------------------------------------- // ToString //------------------------------------------------------------------------- -static string RTreeIndexScanToString(const FunctionData *bind_data_p) { - auto &bind_data = bind_data_p->Cast(); - return bind_data.table.name + " (RTREE INDEX SCAN : " + bind_data.index.GetIndexName() + ")"; +static InsertionOrderPreservingMap RTreeIndexScanToString(TableFunctionToStringInput &input) { + D_ASSERT(input.bind_data); + InsertionOrderPreservingMap result; + auto &bind_data = input.bind_data->Cast(); + result["Table"] = bind_data.table.name; + result["Index"] = bind_data.index.GetIndexName(); + return result; } //------------------------------------------------------------------------- @@ -205,7 +209,6 @@ TableFunction RTreeIndexScanFunction::GetFunction() { func.pushdown_complex_filter = nullptr; func.to_string = RTreeIndexScanToString; func.table_scan_progress = nullptr; - func.get_batch_index = nullptr; func.projection_pushdown = true; func.filter_pushdown = false; func.get_bind_info = RTreeIndexScanBindInfo; diff --git a/spatial/src/spatial/core/io/osm/st_read_osm.cpp b/spatial/src/spatial/core/io/osm/st_read_osm.cpp index 465cb872..5aa49ddb 100644 --- a/spatial/src/spatial/core/io/osm/st_read_osm.cpp +++ b/spatial/src/spatial/core/io/osm/st_read_osm.cpp @@ -836,10 +836,12 @@ static double Progress(ClientContext &context, const FunctionData *bind_data, return state.GetProgress(); } -static idx_t GetBatchIndex(ClientContext &context, const FunctionData *bind_data_p, - LocalTableFunctionState *local_state, GlobalTableFunctionState *global_state) { - auto &state = (LocalState &)*local_state; - return state.block->block_idx; +static OperatorPartitionData GetPartitionData(ClientContext &context, TableFunctionGetPartitionInput &input) { + if (input.partition_info.RequiresPartitionColumns()) { + throw InternalException("ST_ReadOSM::GetPartitionData: partition columns not supported"); + } + auto &state = input.local_state->Cast(); + return OperatorPartitionData(state.block->block_idx); } static unique_ptr ReadOsmPBFReplacementScan(ClientContext &context, ReplacementScanInput &input, @@ -898,7 +900,7 @@ static constexpr const char *DOC_EXAMPLE = R"( void CoreTableFunctions::RegisterOsmTableFunction(DatabaseInstance &db) { TableFunction read("ST_ReadOSM", {LogicalType::VARCHAR}, Execute, Bind, InitGlobal, InitLocal); - read.get_batch_index = GetBatchIndex; + read.get_partition_data = GetPartitionData; read.table_scan_progress = Progress; ExtensionUtil::RegisterFunction(db, read); diff --git a/spatial/src/spatial/gdal/functions/st_read.cpp b/spatial/src/spatial/gdal/functions/st_read.cpp index 9bd92e80..600fad8c 100644 --- a/spatial/src/spatial/gdal/functions/st_read.cpp +++ b/spatial/src/spatial/gdal/functions/st_read.cpp @@ -675,7 +675,7 @@ void GdalTableFunction::Register(DatabaseInstance &db) { GdalTableFunction::InitGlobal, GdalTableFunction::InitLocal); scan.cardinality = GdalTableFunction::Cardinality; - scan.get_batch_index = ArrowTableFunction::ArrowGetBatchIndex; + scan.get_partition_data = ArrowTableFunction::ArrowGetPartitionData; scan.projection_pushdown = true; scan.filter_pushdown = true; diff --git a/spatial/src/spatial/geos/functions/aggregate.cpp b/spatial/src/spatial/geos/functions/aggregate.cpp index aacc6682..c4787863 100644 --- a/spatial/src/spatial/geos/functions/aggregate.cpp +++ b/spatial/src/spatial/geos/functions/aggregate.cpp @@ -197,7 +197,7 @@ void GeosAggregateFunctions::Register(DatabaseInstance &db) { AggregateFunctionSet st_intersection_agg("ST_Intersection_Agg"); st_intersection_agg.AddFunction( - AggregateFunction::UnaryAggregateDestructor( + AggregateFunction::UnaryAggregateDestructor( core::GeoTypes::GEOMETRY(), core::GeoTypes::GEOMETRY())); ExtensionUtil::RegisterFunction(db, st_intersection_agg); @@ -206,7 +206,7 @@ void GeosAggregateFunctions::Register(DatabaseInstance &db) { AggregateFunctionSet st_union_agg("ST_Union_Agg"); st_union_agg.AddFunction( - AggregateFunction::UnaryAggregateDestructor( + AggregateFunction::UnaryAggregateDestructor( core::GeoTypes::GEOMETRY(), core::GeoTypes::GEOMETRY())); ExtensionUtil::RegisterFunction(db, st_union_agg); diff --git a/spatial/src/spatial/geos/functions/scalar/st_buffer.cpp b/spatial/src/spatial/geos/functions/scalar/st_buffer.cpp index 9d5730db..78b034e4 100644 --- a/spatial/src/spatial/geos/functions/scalar/st_buffer.cpp +++ b/spatial/src/spatial/geos/functions/scalar/st_buffer.cpp @@ -130,9 +130,7 @@ void GEOSScalarFunctions::RegisterStBuffer(DatabaseInstance &db) { GEOSFunctionLocalState::Init)); ExtensionUtil::RegisterFunction(db, set); - DocUtil::AddDocumentation(db, "ST_Buffer", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS); - DocUtil::AddFunctionParameterNames(db, "ST_Buffer", - {"geom", "distance", "num_triangles", "join_style", "cap_style", "mitre_limit"}); + DocUtil::AddDocumentation(db, "ST_Buffer", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS, {"geom", "distance", "num_triangles", "join_style", "cap_style", "mitre_limit"}); } } // namespace geos diff --git a/spatial/src/spatial/proj/functions.cpp b/spatial/src/spatial/proj/functions.cpp index 7baf0e4a..554c77a3 100644 --- a/spatial/src/spatial/proj/functions.cpp +++ b/spatial/src/spatial/proj/functions.cpp @@ -510,12 +510,10 @@ void ProjFunctions::Register(DatabaseInstance &db) { GeometryTransformFunction, TransformBind, nullptr, nullptr, ProjFunctionLocalState::Init)); ExtensionUtil::RegisterFunction(db, set); - DocUtil::AddDocumentation(db, "ST_Transform", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS); - DocUtil::AddFunctionParameterNames(db, "ST_Transform", {"geom", "source_crs", "target_crs", "always_xy"}); - + DocUtil::AddDocumentation(db, "ST_Transform", DOC_DESCRIPTION, DOC_EXAMPLE, DOC_TAGS, {"geom", "source_crs", "target_crs", "always_xy"}); GenerateSpatialRefSysTable::Register(db); } } // namespace proj -} // namespace spatial \ No newline at end of file +} // namespace spatial diff --git a/spatial/src/spatial_extension.cpp b/spatial/src/spatial_extension.cpp index d07319f1..488cd1ff 100644 --- a/spatial/src/spatial_extension.cpp +++ b/spatial/src/spatial_extension.cpp @@ -53,7 +53,8 @@ static string RemoveIndentAndTrailingWhitespace(const char *text) { void spatial::DocUtil::AddDocumentation(duckdb::DatabaseInstance &db, const char *function_name, const char *description, const char *example, - const duckdb::unordered_map &tags) { + const duckdb::unordered_map &tags, + duckdb::vector parameter_names) { auto &system_catalog = Catalog::GetSystemCatalog(db); auto data = CatalogTransaction::GetSystemTransaction(db); @@ -73,40 +74,22 @@ void spatial::DocUtil::AddDocumentation(duckdb::DatabaseInstance &db, const char } auto &func_entry = catalog_entry->Cast(); + FunctionDescription func_description; if (description != nullptr) { - func_entry.description = RemoveIndentAndTrailingWhitespace(description); + func_description.description = RemoveIndentAndTrailingWhitespace(description); } if (example != nullptr) { - func_entry.example = RemoveIndentAndTrailingWhitespace(example); + func_description.examples.push_back(RemoveIndentAndTrailingWhitespace(example)); } + if (!parameter_names.empty()) { + func_description.parameter_names = std::move(parameter_names); + } + func_entry.descriptions.push_back(std::move(func_description)); if (!tags.empty()) { func_entry.tags = tags; } } -void spatial::DocUtil::AddFunctionParameterNames(duckdb::DatabaseInstance &db, const char *function_name, - duckdb::vector names) { - auto &system_catalog = Catalog::GetSystemCatalog(db); - auto data = CatalogTransaction::GetSystemTransaction(db); - auto &schema = system_catalog.GetSchema(data, DEFAULT_SCHEMA); - auto catalog_entry = schema.GetEntry(data, CatalogType::SCALAR_FUNCTION_ENTRY, function_name); - if (!catalog_entry) { - // Try get a aggregate function - catalog_entry = schema.GetEntry(data, CatalogType::AGGREGATE_FUNCTION_ENTRY, function_name); - if (!catalog_entry) { - // Try get a table function - catalog_entry = schema.GetEntry(data, CatalogType::TABLE_FUNCTION_ENTRY, function_name); - if (!catalog_entry) { - throw duckdb::InvalidInputException("Function with name \"%s\" not found in DocUtil::AddDocumentation", - function_name); - } - } - } - - auto &func_entry = catalog_entry->Cast(); - func_entry.parameter_names = std::move(names); -} - namespace duckdb { static void LoadInternal(DatabaseInstance &instance) {