Skip to content

Bump to main - apply patches and fix tests #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
GEN: ninja
STATIC_LIBCPP: 1
run: |
make release
make reldebug

- name: Test extension
env:
Expand All @@ -84,4 +84,4 @@ jobs:
run: |
psql -c "SELECT 43"
source ./create-postgres-tables.sh
make test_release
make test_reldebug
8 changes: 4 additions & 4 deletions .github/workflows/MainDistributionPipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
name: Build extension binaries
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
with:
duckdb_version: v1.2.2
ci_tools_version: v1.2.2
duckdb_version: main
ci_tools_version: main
extension_name: postgres_scanner
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'

Expand All @@ -27,8 +27,8 @@ jobs:
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
secrets: inherit
with:
duckdb_version: v1.2.2
ci_tools_version: v1.2.2
duckdb_version: main
ci_tools_version: main
extension_name: postgres_scanner
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}
13 changes: 12 additions & 1 deletion create-postgres-tables.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
#!/bin/bash
set -e

DUCKDB_PATH=duckdb
if test -f build/release/duckdb; then
DUCKDB_PATH=build/release/duckdb
elif test -f build/reldebug/duckdb; then
DUCKDB_PATH=build/reldebug/duckdb
elif test -f build/debug/duckdb; then
DUCKDB_PATH=build/debug/duckdb
fi

echo "
CREATE SCHEMA tpch;
CREATE SCHEMA tpcds;
CALL dbgen(sf=0.01, schema='tpch');
CALL dsdgen(sf=0.01, schema='tpcds');
EXPORT DATABASE '/tmp/postgresscannertmp';
" | \
./build/release/duckdb
$DUCKDB_PATH

dropdb --if-exists postgresscanner
createdb postgresscanner
Expand Down
2 changes: 1 addition & 1 deletion duckdb
Submodule duckdb updated 1678 files
24 changes: 12 additions & 12 deletions src/include/storage/postgres_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ class PostgresCatalog : public Catalog {

void ScanSchemas(ClientContext &context, std::function<void(SchemaCatalogEntry &)> callback) override;

optional_ptr<SchemaCatalogEntry> GetSchema(CatalogTransaction transaction, const string &schema_name,
OnEntryNotFound if_not_found,
QueryErrorContext error_context = QueryErrorContext()) override;

unique_ptr<PhysicalOperator> PlanInsert(ClientContext &context, LogicalInsert &op,
unique_ptr<PhysicalOperator> plan) override;
unique_ptr<PhysicalOperator> PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
unique_ptr<PhysicalOperator> plan) override;
unique_ptr<PhysicalOperator> PlanDelete(ClientContext &context, LogicalDelete &op,
unique_ptr<PhysicalOperator> plan) override;
unique_ptr<PhysicalOperator> PlanUpdate(ClientContext &context, LogicalUpdate &op,
unique_ptr<PhysicalOperator> plan) override;
optional_ptr<SchemaCatalogEntry> LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup,
OnEntryNotFound if_not_found) override;

PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op,
PhysicalOperator &plan) override;
PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op,
optional_ptr<PhysicalOperator> plan) override;
PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op,
PhysicalOperator &plan) override;
PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op,
PhysicalOperator &plan) override;

unique_ptr<LogicalOperator> BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table,
unique_ptr<LogicalOperator> plan) override;

Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/postgres_schema_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PostgresSchemaEntry : public SchemaCatalogEntry {
void Scan(ClientContext &context, CatalogType type, const std::function<void(CatalogEntry &)> &callback) override;
void Scan(CatalogType type, const std::function<void(CatalogEntry &)> &callback) override;
void DropEntry(ClientContext &context, DropInfo &info) override;
optional_ptr<CatalogEntry> GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) override;
optional_ptr<CatalogEntry> LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) override;

static bool SchemaIsInternal(const string &name);

Expand Down
10 changes: 5 additions & 5 deletions src/storage/postgres_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ void PostgresCatalog::ScanSchemas(ClientContext &context, std::function<void(Sch
schemas.Scan(context, [&](CatalogEntry &schema) { callback(schema.Cast<PostgresSchemaEntry>()); });
}

optional_ptr<SchemaCatalogEntry> PostgresCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name,
OnEntryNotFound if_not_found,
QueryErrorContext error_context) {
optional_ptr<SchemaCatalogEntry> PostgresCatalog::LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup,
OnEntryNotFound if_not_found) {
auto schema_name = schema_lookup.GetEntryName();
if (schema_name == DEFAULT_SCHEMA) {
return GetSchema(transaction, default_schema, if_not_found, error_context);
schema_name = default_schema;
}
auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this);
if (schema_name == "pg_temp") {
return GetSchema(transaction, postgres_transaction.GetTemporarySchema(), if_not_found, error_context);
schema_name = postgres_transaction.GetTemporarySchema();
}
auto entry = schemas.GetEntry(transaction.GetContext(), schema_name);
if (!entry && if_not_found != OnEntryNotFound::RETURN_NULL) {
Expand Down
11 changes: 5 additions & 6 deletions src/storage/postgres_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,16 @@ InsertionOrderPreservingMap<string> PostgresDelete::ParamsToString() const {
//===--------------------------------------------------------------------===//
// Plan
//===--------------------------------------------------------------------===//
unique_ptr<PhysicalOperator> PostgresCatalog::PlanDelete(ClientContext &context, LogicalDelete &op,
unique_ptr<PhysicalOperator> plan) {
PhysicalOperator &PostgresCatalog::PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, PhysicalOperator &plan) {
if (op.return_chunk) {
throw BinderException("RETURNING clause not yet supported for deletion of a Postgres table");
}
auto &bound_ref = op.expressions[0]->Cast<BoundReferenceExpression>();
PostgresCatalog::MaterializePostgresScans(*plan);
PostgresCatalog::MaterializePostgresScans(plan);

auto insert = make_uniq<PostgresDelete>(op, op.table, bound_ref.index);
insert->children.push_back(std::move(plan));
return std::move(insert);
auto &delete_op = planner.Make<PostgresDelete>(op, op.table, bound_ref.index);
delete_op.children.push_back(plan);
return delete_op;
}

} // namespace duckdb
25 changes: 21 additions & 4 deletions src/storage/postgres_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "duckdb/planner/operator/logical_extension_operator.hpp"
#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
#include "duckdb/parser/parsed_data/drop_info.hpp"
#include "duckdb/planner/operator/logical_create_index.hpp"
#include "duckdb/parser/parsed_data/create_index_info.hpp"
#include "duckdb/planner/expression_binder/index_binder.hpp"
#include "duckdb/planner/operator/logical_get.hpp"

namespace duckdb {

Expand Down Expand Up @@ -56,8 +60,8 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
unique_ptr<CreateIndexInfo> info;
TableCatalogEntry &table;

unique_ptr<PhysicalOperator> CreatePlan(ClientContext &context, PhysicalPlanGenerator &generator) override {
return make_uniq<PostgresCreateIndex>(std::move(info), table);
PhysicalOperator &CreatePlan(ClientContext &context, PhysicalPlanGenerator &planner) override {
return planner.Make<PostgresCreateIndex>(std::move(info), table);
}

void Serialize(Serializer &serializer) const override {
Expand All @@ -72,8 +76,21 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
unique_ptr<LogicalOperator> PostgresCatalog::BindCreateIndex(Binder &binder, CreateStatement &stmt,
TableCatalogEntry &table,
unique_ptr<LogicalOperator> plan) {
return make_uniq<LogicalPostgresCreateIndex>(unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move(stmt.info)),
table);
// FIXME: this is a work-around for the CreateIndexInfo we are getting here not being fully bound
// this needs to be fixed upstream (eventually)
auto create_index_info = unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move(stmt.info));
IndexBinder index_binder(binder, binder.context);

// Bind the index expressions.
vector<unique_ptr<Expression>> expressions;
for (auto &expr : create_index_info->expressions) {
expressions.push_back(index_binder.Bind(expr));
}

auto &get = plan->Cast<LogicalGet>();
index_binder.InitCreateIndexInfo(get, *create_index_info, table.schema.name);

return make_uniq<LogicalPostgresCreateIndex>(std::move(create_index_info), table);
}

} // namespace duckdb
82 changes: 40 additions & 42 deletions src/storage/postgres_insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,41 +153,41 @@ InsertionOrderPreservingMap<string> PostgresInsert::ParamsToString() const {
//===--------------------------------------------------------------------===//
// Plan
//===--------------------------------------------------------------------===//
unique_ptr<PhysicalOperator> AddCastToPostgresTypes(ClientContext &context, unique_ptr<PhysicalOperator> plan) {
PhysicalOperator &AddCastToPostgresTypes(ClientContext &context, PhysicalPlanGenerator &planner, PhysicalOperator &plan) {
// check if we need to cast anything
bool require_cast = false;
auto &child_types = plan->GetTypes();
auto &child_types = plan.GetTypes();
for (auto &type : child_types) {
auto postgres_type = PostgresUtils::ToPostgresType(type);
if (postgres_type != type) {
require_cast = true;
break;
}
}
if (require_cast) {
vector<LogicalType> postgres_types;
vector<unique_ptr<Expression>> select_list;
for (idx_t i = 0; i < child_types.size(); i++) {
auto &type = child_types[i];
unique_ptr<Expression> expr;
expr = make_uniq<BoundReferenceExpression>(type, i);

auto postgres_type = PostgresUtils::ToPostgresType(type);
if (postgres_type != type) {
// add a cast
expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type);
}
postgres_types.push_back(std::move(postgres_type));
select_list.push_back(std::move(expr));
}
// we need to cast: add casts
auto proj = make_uniq<PhysicalProjection>(std::move(postgres_types), std::move(select_list),
plan->estimated_cardinality);
proj->children.push_back(std::move(plan));
plan = std::move(proj);
}

return plan;
if (!require_cast) {
return plan;
}

vector<LogicalType> postgres_types;
vector<unique_ptr<Expression>> select_list;
for (idx_t i = 0; i < child_types.size(); i++) {
auto &type = child_types[i];
unique_ptr<Expression> expr;
expr = make_uniq<BoundReferenceExpression>(type, i);

auto postgres_type = PostgresUtils::ToPostgresType(type);
if (postgres_type != type) {
// add a cast
expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type);
}
postgres_types.push_back(std::move(postgres_type));
select_list.push_back(std::move(expr));
}

// we need to cast: add casts
auto &proj = planner.Make<PhysicalProjection>(std::move(postgres_types), std::move(select_list), plan.estimated_cardinality);
proj.children.push_back(plan);
return proj;
}

bool PostgresCatalog::IsPostgresScan(const string &name) {
Expand All @@ -206,36 +206,34 @@ void PostgresCatalog::MaterializePostgresScans(PhysicalOperator &op) {
}
}
for (auto &child : op.children) {
MaterializePostgresScans(*child);
MaterializePostgresScans(child);
}
}

unique_ptr<PhysicalOperator> PostgresCatalog::PlanInsert(ClientContext &context, LogicalInsert &op,
unique_ptr<PhysicalOperator> plan) {
PhysicalOperator &PostgresCatalog::PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, optional_ptr<PhysicalOperator> plan) {
if (op.return_chunk) {
throw BinderException("RETURNING clause not yet supported for insertion into Postgres table");
}
if (op.action_type != OnConflictAction::THROW) {
throw BinderException("ON CONFLICT clause not yet supported for insertion into Postgres table");
}
MaterializePostgresScans(*plan);

plan = AddCastToPostgresTypes(context, std::move(plan));
D_ASSERT(plan);
MaterializePostgresScans(*plan);
auto &inner_plan = AddCastToPostgresTypes(context, planner, *plan);

auto insert = make_uniq<PostgresInsert>(op, op.table, op.column_index_map);
insert->children.push_back(std::move(plan));
return std::move(insert);
auto &insert = planner.Make<PostgresInsert>(op, op.table, op.column_index_map);
insert.children.push_back(inner_plan);
return insert;
}

unique_ptr<PhysicalOperator> PostgresCatalog::PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
unique_ptr<PhysicalOperator> plan) {
plan = AddCastToPostgresTypes(context, std::move(plan));

MaterializePostgresScans(*plan);
PhysicalOperator &PostgresCatalog::PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op, PhysicalOperator &plan) {
auto &inner_plan = AddCastToPostgresTypes(context, planner, plan);
MaterializePostgresScans(inner_plan);

auto insert = make_uniq<PostgresInsert>(op, op.schema, std::move(op.info));
insert->children.push_back(std::move(plan));
return std::move(insert);
auto &insert = planner.Make<PostgresInsert>(op, op.schema, std::move(op.info));
insert.children.push_back(inner_plan);
return insert;
}

} // namespace duckdb
8 changes: 4 additions & 4 deletions src/storage/postgres_schema_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ void PostgresSchemaEntry::DropEntry(ClientContext &context, DropInfo &info) {
GetCatalogSet(info.type).DropEntry(context, info);
}

optional_ptr<CatalogEntry> PostgresSchemaEntry::GetEntry(CatalogTransaction transaction, CatalogType type,
const string &name) {
if (!CatalogTypeIsSupported(type)) {
optional_ptr<CatalogEntry> PostgresSchemaEntry::LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) {
auto catalog_type = lookup_info.GetCatalogType();
if (!CatalogTypeIsSupported(catalog_type)) {
return nullptr;
}
return GetCatalogSet(type).GetEntry(transaction.GetContext(), name);
return GetCatalogSet(catalog_type).GetEntry(transaction.GetContext(), lookup_info.GetEntryName());
}

PostgresCatalogSet &PostgresSchemaEntry::GetCatalogSet(CatalogType type) {
Expand Down
12 changes: 6 additions & 6 deletions src/storage/postgres_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ InsertionOrderPreservingMap<string> PostgresUpdate::ParamsToString() const {
//===--------------------------------------------------------------------===//
// Plan
//===--------------------------------------------------------------------===//
unique_ptr<PhysicalOperator> PostgresCatalog::PlanUpdate(ClientContext &context, LogicalUpdate &op,
unique_ptr<PhysicalOperator> plan) {
PhysicalOperator &PostgresCatalog::PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op, PhysicalOperator &plan) {
if (op.return_chunk) {
throw BinderException("RETURNING clause not yet supported for updates of a Postgres table");
}
Expand All @@ -190,10 +189,11 @@ unique_ptr<PhysicalOperator> PostgresCatalog::PlanUpdate(ClientContext &context,
throw BinderException("SET DEFAULT is not yet supported for updates of a Postgres table");
}
}
PostgresCatalog::MaterializePostgresScans(*plan);
auto insert = make_uniq<PostgresUpdate>(op, op.table, std::move(op.columns));
insert->children.push_back(std::move(plan));
return std::move(insert);

PostgresCatalog::MaterializePostgresScans(plan);
auto &update = planner.Make<PostgresUpdate>(op, op.table, std::move(op.columns));
update.children.push_back(plan);
return update;
}

} // namespace duckdb
4 changes: 2 additions & 2 deletions test/sql/scanner/arrays.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ SELECT UNNEST(float_col), ROUND(UNNEST(double_col), 1) FROM pg_numarraytypes
query IIIIIIII
select * from pg_bytearraytypes;
----
[a, Z, NULL] [a, Z, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [x00, xff, NULL] [{"a":42}, NULL] [a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11, NULL]
[a, Z, NULL] [a, Z, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [aaaa, ZZZZ, NULL] [x00, xff, NULL] ['{"a":42}', NULL] [a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11, NULL]
NULL NULL NULL NULL NULL NULL NULL NULL

query IIIII
select * from pg_datearraytypes;
----
[2019-11-26, 2021-03-01, NULL] [14:42:43, 12:45:01, NULL] [14:42:43+05:45, 12:45:01+05:45, NULL] [2019-11-26 12:45:01, 2021-03-01 12:45:01, NULL] [2019-11-26 07:00:01+00, 2021-03-01 07:00:01+00, NULL]
[2019-11-26, 2021-03-01, NULL] ['14:42:43', '12:45:01', NULL] ['14:42:43+05:45', '12:45:01+05:45', NULL] ['2019-11-26 12:45:01', '2021-03-01 12:45:01', NULL] ['2019-11-26 07:00:01+00', '2021-03-01 07:00:01+00', NULL]
NULL NULL NULL NULL NULL

statement ok
Expand Down
2 changes: 1 addition & 1 deletion test/sql/scanner/daterange_array.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ loop i 0 2
query II
SELECT * from daterange_array;
----
1108 [["2010-01-01 14:30:00","2010-01-01 15:30:00")]
1108 ['["2010-01-01 14:30:00","2010-01-01 15:30:00")']

statement ok
USE memory
Expand Down
Loading
Loading