Skip to content

Commit

Permalink
apply patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxxen committed Dec 3, 2024
1 parent 207b2ef commit f6815ce
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 62 deletions.
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 1985 files
11 changes: 4 additions & 7 deletions spatial/include/spatial/doc_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<duckdb::string, duckdb::string> &tags);
const duckdb::unordered_map<duckdb::string, duckdb::string> &tags, duckdb::vector<duckdb::string> parameter_names = {});

// Abuse adding tags as a comment
template <size_t N>
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<duckdb::string> parameter_names = {}) {
duckdb::unordered_map<duckdb::string, duckdb::string> 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<duckdb::string> names);
};

} // namespace spatial
} // namespace spatial
Original file line number Diff line number Diff line change
Expand Up @@ -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
} // namespace spatial
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ static void Execute(ClientContext &context, TableFunctionInput &data_p, DataChun
const auto chunk_size = MinValue<idx_t>(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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 9 additions & 6 deletions spatial/src/spatial/core/index/rtree/rtree_index_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BindInfo RTreeIndexScanBindInfo(const optional_ptr<FunctionData> bind_data_p) {
struct RTreeIndexScanGlobalState : public GlobalTableFunctionState {
ColumnFetchState fetch_state;
TableScanState local_storage_state;
vector<storage_t> column_ids;
vector<StorageIndex> column_ids;

// Index scan state
unique_ptr<IndexScanState> index_state;
Expand All @@ -54,7 +54,7 @@ static unique_ptr<GlobalTableFunctionState> 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
Expand Down Expand Up @@ -128,9 +128,13 @@ unique_ptr<NodeStatistics> RTreeIndexScanCardinality(ClientContext &context, con
//-------------------------------------------------------------------------
// ToString
//-------------------------------------------------------------------------
static string RTreeIndexScanToString(const FunctionData *bind_data_p) {
auto &bind_data = bind_data_p->Cast<RTreeIndexScanBindData>();
return bind_data.table.name + " (RTREE INDEX SCAN : " + bind_data.index.GetIndexName() + ")";
static InsertionOrderPreservingMap<string> RTreeIndexScanToString(TableFunctionToStringInput &input) {
D_ASSERT(input.bind_data);
InsertionOrderPreservingMap<string> result;
auto &bind_data = input.bind_data->Cast<RTreeIndexScanBindData>();
result["Table"] = bind_data.table.name;
result["Index"] = bind_data.index.GetIndexName();
return result;
}

//-------------------------------------------------------------------------
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions spatial/src/spatial/core/io/osm/st_read_osm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LocalState>();
return OperatorPartitionData(state.block->block_idx);
}

static unique_ptr<TableRef> ReadOsmPBFReplacementScan(ClientContext &context, ReplacementScanInput &input,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion spatial/src/spatial/gdal/functions/st_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions spatial/src/spatial/geos/functions/aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void GeosAggregateFunctions::Register(DatabaseInstance &db) {

AggregateFunctionSet st_intersection_agg("ST_Intersection_Agg");
st_intersection_agg.AddFunction(
AggregateFunction::UnaryAggregateDestructor<GEOSAggState, geometry_t, geometry_t, IntersectionAggFunction>(
AggregateFunction::UnaryAggregateDestructor<GEOSAggState, geometry_t, geometry_t, IntersectionAggFunction, AggregateDestructorType::LEGACY>(
core::GeoTypes::GEOMETRY(), core::GeoTypes::GEOMETRY()));

ExtensionUtil::RegisterFunction(db, st_intersection_agg);
Expand All @@ -206,7 +206,7 @@ void GeosAggregateFunctions::Register(DatabaseInstance &db) {

AggregateFunctionSet st_union_agg("ST_Union_Agg");
st_union_agg.AddFunction(
AggregateFunction::UnaryAggregateDestructor<GEOSAggState, geometry_t, geometry_t, UnionAggFunction>(
AggregateFunction::UnaryAggregateDestructor<GEOSAggState, geometry_t, geometry_t, UnionAggFunction, AggregateDestructorType::LEGACY>(
core::GeoTypes::GEOMETRY(), core::GeoTypes::GEOMETRY()));

ExtensionUtil::RegisterFunction(db, st_union_agg);
Expand Down
4 changes: 1 addition & 3 deletions spatial/src/spatial/geos/functions/scalar/st_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions spatial/src/spatial/proj/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
} // namespace spatial
35 changes: 9 additions & 26 deletions spatial/src/spatial_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<duckdb::string, duckdb::string> &tags) {
const duckdb::unordered_map<duckdb::string, duckdb::string> &tags,
duckdb::vector<duckdb::string> parameter_names) {

auto &system_catalog = Catalog::GetSystemCatalog(db);
auto data = CatalogTransaction::GetSystemTransaction(db);
Expand All @@ -73,40 +74,22 @@ void spatial::DocUtil::AddDocumentation(duckdb::DatabaseInstance &db, const char
}

auto &func_entry = catalog_entry->Cast<FunctionEntry>();
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<duckdb::string> 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<FunctionEntry>();
func_entry.parameter_names = std::move(names);
}

namespace duckdb {

static void LoadInternal(DatabaseInstance &instance) {
Expand Down

0 comments on commit f6815ce

Please sign in to comment.