Skip to content

Commit 96df45d

Browse files
authored
Merge pull request #320 from Mytherin/bumptomain
Bump to main - apply patches and fix tests
2 parents 92c0644 + 2343dd7 commit 96df45d

18 files changed

+139
-114
lines changed

.github/workflows/Linux.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
GEN: ninja
7676
STATIC_LIBCPP: 1
7777
run: |
78-
make release
78+
make reldebug
7979
8080
- name: Test extension
8181
env:
@@ -84,4 +84,4 @@ jobs:
8484
run: |
8585
psql -c "SELECT 43"
8686
source ./create-postgres-tables.sh
87-
make test_release
87+
make test_reldebug

.github/workflows/MainDistributionPipeline.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
name: Build extension binaries
1717
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
1818
with:
19-
duckdb_version: v1.2.2
20-
ci_tools_version: v1.2.2
19+
duckdb_version: main
20+
ci_tools_version: main
2121
extension_name: postgres_scanner
2222
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'
2323

@@ -27,8 +27,8 @@ jobs:
2727
uses: duckdb/extension-ci-tools/.github/workflows/[email protected]
2828
secrets: inherit
2929
with:
30-
duckdb_version: v1.2.2
31-
ci_tools_version: v1.2.2
30+
duckdb_version: main
31+
ci_tools_version: main
3232
extension_name: postgres_scanner
3333
exclude_archs: 'wasm_mvp;wasm_eh;wasm_threads;windows_amd64_mingw'
3434
deploy_latest: ${{ startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' }}

create-postgres-tables.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
#!/bin/bash
2+
set -e
3+
4+
DUCKDB_PATH=duckdb
5+
if test -f build/release/duckdb; then
6+
DUCKDB_PATH=build/release/duckdb
7+
elif test -f build/reldebug/duckdb; then
8+
DUCKDB_PATH=build/reldebug/duckdb
9+
elif test -f build/debug/duckdb; then
10+
DUCKDB_PATH=build/debug/duckdb
11+
fi
12+
213
echo "
314
CREATE SCHEMA tpch;
415
CREATE SCHEMA tpcds;
516
CALL dbgen(sf=0.01, schema='tpch');
617
CALL dsdgen(sf=0.01, schema='tpcds');
718
EXPORT DATABASE '/tmp/postgresscannertmp';
819
" | \
9-
./build/release/duckdb
20+
$DUCKDB_PATH
1021

1122
dropdb --if-exists postgresscanner
1223
createdb postgresscanner

duckdb

Submodule duckdb updated 1678 files

src/include/storage/postgres_catalog.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class PostgresCatalog : public Catalog {
4040

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

43-
optional_ptr<SchemaCatalogEntry> GetSchema(CatalogTransaction transaction, const string &schema_name,
44-
OnEntryNotFound if_not_found,
45-
QueryErrorContext error_context = QueryErrorContext()) override;
46-
47-
unique_ptr<PhysicalOperator> PlanInsert(ClientContext &context, LogicalInsert &op,
48-
unique_ptr<PhysicalOperator> plan) override;
49-
unique_ptr<PhysicalOperator> PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
50-
unique_ptr<PhysicalOperator> plan) override;
51-
unique_ptr<PhysicalOperator> PlanDelete(ClientContext &context, LogicalDelete &op,
52-
unique_ptr<PhysicalOperator> plan) override;
53-
unique_ptr<PhysicalOperator> PlanUpdate(ClientContext &context, LogicalUpdate &op,
54-
unique_ptr<PhysicalOperator> plan) override;
43+
optional_ptr<SchemaCatalogEntry> LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup,
44+
OnEntryNotFound if_not_found) override;
45+
46+
PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op,
47+
PhysicalOperator &plan) override;
48+
PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op,
49+
optional_ptr<PhysicalOperator> plan) override;
50+
PhysicalOperator &PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op,
51+
PhysicalOperator &plan) override;
52+
PhysicalOperator &PlanUpdate(ClientContext &context, PhysicalPlanGenerator &planner, LogicalUpdate &op,
53+
PhysicalOperator &plan) override;
54+
5555
unique_ptr<LogicalOperator> BindCreateIndex(Binder &binder, CreateStatement &stmt, TableCatalogEntry &table,
5656
unique_ptr<LogicalOperator> plan) override;
5757

src/include/storage/postgres_schema_entry.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PostgresSchemaEntry : public SchemaCatalogEntry {
4242
void Scan(ClientContext &context, CatalogType type, const std::function<void(CatalogEntry &)> &callback) override;
4343
void Scan(CatalogType type, const std::function<void(CatalogEntry &)> &callback) override;
4444
void DropEntry(ClientContext &context, DropInfo &info) override;
45-
optional_ptr<CatalogEntry> GetEntry(CatalogTransaction transaction, CatalogType type, const string &name) override;
45+
optional_ptr<CatalogEntry> LookupEntry(CatalogTransaction transaction, const EntryLookupInfo &lookup_info) override;
4646

4747
static bool SchemaIsInternal(const string &name);
4848

src/storage/postgres_catalog.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ void PostgresCatalog::ScanSchemas(ClientContext &context, std::function<void(Sch
138138
schemas.Scan(context, [&](CatalogEntry &schema) { callback(schema.Cast<PostgresSchemaEntry>()); });
139139
}
140140

141-
optional_ptr<SchemaCatalogEntry> PostgresCatalog::GetSchema(CatalogTransaction transaction, const string &schema_name,
142-
OnEntryNotFound if_not_found,
143-
QueryErrorContext error_context) {
141+
optional_ptr<SchemaCatalogEntry> PostgresCatalog::LookupSchema(CatalogTransaction transaction, const EntryLookupInfo &schema_lookup,
142+
OnEntryNotFound if_not_found) {
143+
auto schema_name = schema_lookup.GetEntryName();
144144
if (schema_name == DEFAULT_SCHEMA) {
145-
return GetSchema(transaction, default_schema, if_not_found, error_context);
145+
schema_name = default_schema;
146146
}
147147
auto &postgres_transaction = PostgresTransaction::Get(transaction.GetContext(), *this);
148148
if (schema_name == "pg_temp") {
149-
return GetSchema(transaction, postgres_transaction.GetTemporarySchema(), if_not_found, error_context);
149+
schema_name = postgres_transaction.GetTemporarySchema();
150150
}
151151
auto entry = schemas.GetEntry(transaction.GetContext(), schema_name);
152152
if (!entry && if_not_found != OnEntryNotFound::RETURN_NULL) {

src/storage/postgres_delete.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,16 @@ InsertionOrderPreservingMap<string> PostgresDelete::ParamsToString() const {
119119
//===--------------------------------------------------------------------===//
120120
// Plan
121121
//===--------------------------------------------------------------------===//
122-
unique_ptr<PhysicalOperator> PostgresCatalog::PlanDelete(ClientContext &context, LogicalDelete &op,
123-
unique_ptr<PhysicalOperator> plan) {
122+
PhysicalOperator &PostgresCatalog::PlanDelete(ClientContext &context, PhysicalPlanGenerator &planner, LogicalDelete &op, PhysicalOperator &plan) {
124123
if (op.return_chunk) {
125124
throw BinderException("RETURNING clause not yet supported for deletion of a Postgres table");
126125
}
127126
auto &bound_ref = op.expressions[0]->Cast<BoundReferenceExpression>();
128-
PostgresCatalog::MaterializePostgresScans(*plan);
127+
PostgresCatalog::MaterializePostgresScans(plan);
129128

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

135134
} // namespace duckdb

src/storage/postgres_index.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include "duckdb/planner/operator/logical_extension_operator.hpp"
55
#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
66
#include "duckdb/parser/parsed_data/drop_info.hpp"
7+
#include "duckdb/planner/operator/logical_create_index.hpp"
8+
#include "duckdb/parser/parsed_data/create_index_info.hpp"
9+
#include "duckdb/planner/expression_binder/index_binder.hpp"
10+
#include "duckdb/planner/operator/logical_get.hpp"
711

812
namespace duckdb {
913

@@ -56,8 +60,8 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
5660
unique_ptr<CreateIndexInfo> info;
5761
TableCatalogEntry &table;
5862

59-
unique_ptr<PhysicalOperator> CreatePlan(ClientContext &context, PhysicalPlanGenerator &generator) override {
60-
return make_uniq<PostgresCreateIndex>(std::move(info), table);
63+
PhysicalOperator &CreatePlan(ClientContext &context, PhysicalPlanGenerator &planner) override {
64+
return planner.Make<PostgresCreateIndex>(std::move(info), table);
6165
}
6266

6367
void Serialize(Serializer &serializer) const override {
@@ -72,8 +76,21 @@ class LogicalPostgresCreateIndex : public LogicalExtensionOperator {
7276
unique_ptr<LogicalOperator> PostgresCatalog::BindCreateIndex(Binder &binder, CreateStatement &stmt,
7377
TableCatalogEntry &table,
7478
unique_ptr<LogicalOperator> plan) {
75-
return make_uniq<LogicalPostgresCreateIndex>(unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move(stmt.info)),
76-
table);
79+
// FIXME: this is a work-around for the CreateIndexInfo we are getting here not being fully bound
80+
// this needs to be fixed upstream (eventually)
81+
auto create_index_info = unique_ptr_cast<CreateInfo, CreateIndexInfo>(std::move(stmt.info));
82+
IndexBinder index_binder(binder, binder.context);
83+
84+
// Bind the index expressions.
85+
vector<unique_ptr<Expression>> expressions;
86+
for (auto &expr : create_index_info->expressions) {
87+
expressions.push_back(index_binder.Bind(expr));
88+
}
89+
90+
auto &get = plan->Cast<LogicalGet>();
91+
index_binder.InitCreateIndexInfo(get, *create_index_info, table.schema.name);
92+
93+
return make_uniq<LogicalPostgresCreateIndex>(std::move(create_index_info), table);
7794
}
7895

7996
} // namespace duckdb

src/storage/postgres_insert.cpp

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -153,41 +153,41 @@ InsertionOrderPreservingMap<string> PostgresInsert::ParamsToString() const {
153153
//===--------------------------------------------------------------------===//
154154
// Plan
155155
//===--------------------------------------------------------------------===//
156-
unique_ptr<PhysicalOperator> AddCastToPostgresTypes(ClientContext &context, unique_ptr<PhysicalOperator> plan) {
156+
PhysicalOperator &AddCastToPostgresTypes(ClientContext &context, PhysicalPlanGenerator &planner, PhysicalOperator &plan) {
157157
// check if we need to cast anything
158158
bool require_cast = false;
159-
auto &child_types = plan->GetTypes();
159+
auto &child_types = plan.GetTypes();
160160
for (auto &type : child_types) {
161161
auto postgres_type = PostgresUtils::ToPostgresType(type);
162162
if (postgres_type != type) {
163163
require_cast = true;
164164
break;
165165
}
166166
}
167-
if (require_cast) {
168-
vector<LogicalType> postgres_types;
169-
vector<unique_ptr<Expression>> select_list;
170-
for (idx_t i = 0; i < child_types.size(); i++) {
171-
auto &type = child_types[i];
172-
unique_ptr<Expression> expr;
173-
expr = make_uniq<BoundReferenceExpression>(type, i);
174-
175-
auto postgres_type = PostgresUtils::ToPostgresType(type);
176-
if (postgres_type != type) {
177-
// add a cast
178-
expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type);
179-
}
180-
postgres_types.push_back(std::move(postgres_type));
181-
select_list.push_back(std::move(expr));
182-
}
183-
// we need to cast: add casts
184-
auto proj = make_uniq<PhysicalProjection>(std::move(postgres_types), std::move(select_list),
185-
plan->estimated_cardinality);
186-
proj->children.push_back(std::move(plan));
187-
plan = std::move(proj);
188-
}
189-
190-
return plan;
167+
if (!require_cast) {
168+
return plan;
169+
}
170+
171+
vector<LogicalType> postgres_types;
172+
vector<unique_ptr<Expression>> select_list;
173+
for (idx_t i = 0; i < child_types.size(); i++) {
174+
auto &type = child_types[i];
175+
unique_ptr<Expression> expr;
176+
expr = make_uniq<BoundReferenceExpression>(type, i);
177+
178+
auto postgres_type = PostgresUtils::ToPostgresType(type);
179+
if (postgres_type != type) {
180+
// add a cast
181+
expr = BoundCastExpression::AddCastToType(context, std::move(expr), postgres_type);
182+
}
183+
postgres_types.push_back(std::move(postgres_type));
184+
select_list.push_back(std::move(expr));
185+
}
186+
187+
// we need to cast: add casts
188+
auto &proj = planner.Make<PhysicalProjection>(std::move(postgres_types), std::move(select_list), plan.estimated_cardinality);
189+
proj.children.push_back(plan);
190+
return proj;
191191
}
192192

193193
bool PostgresCatalog::IsPostgresScan(const string &name) {
@@ -206,36 +206,34 @@ void PostgresCatalog::MaterializePostgresScans(PhysicalOperator &op) {
206206
}
207207
}
208208
for (auto &child : op.children) {
209-
MaterializePostgresScans(*child);
209+
MaterializePostgresScans(child);
210210
}
211211
}
212212

213-
unique_ptr<PhysicalOperator> PostgresCatalog::PlanInsert(ClientContext &context, LogicalInsert &op,
214-
unique_ptr<PhysicalOperator> plan) {
213+
PhysicalOperator &PostgresCatalog::PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op, optional_ptr<PhysicalOperator> plan) {
215214
if (op.return_chunk) {
216215
throw BinderException("RETURNING clause not yet supported for insertion into Postgres table");
217216
}
218217
if (op.action_type != OnConflictAction::THROW) {
219218
throw BinderException("ON CONFLICT clause not yet supported for insertion into Postgres table");
220219
}
221-
MaterializePostgresScans(*plan);
222220

223-
plan = AddCastToPostgresTypes(context, std::move(plan));
221+
D_ASSERT(plan);
222+
MaterializePostgresScans(*plan);
223+
auto &inner_plan = AddCastToPostgresTypes(context, planner, *plan);
224224

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

230-
unique_ptr<PhysicalOperator> PostgresCatalog::PlanCreateTableAs(ClientContext &context, LogicalCreateTable &op,
231-
unique_ptr<PhysicalOperator> plan) {
232-
plan = AddCastToPostgresTypes(context, std::move(plan));
233-
234-
MaterializePostgresScans(*plan);
230+
PhysicalOperator &PostgresCatalog::PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner, LogicalCreateTable &op, PhysicalOperator &plan) {
231+
auto &inner_plan = AddCastToPostgresTypes(context, planner, plan);
232+
MaterializePostgresScans(inner_plan);
235233

236-
auto insert = make_uniq<PostgresInsert>(op, op.schema, std::move(op.info));
237-
insert->children.push_back(std::move(plan));
238-
return std::move(insert);
234+
auto &insert = planner.Make<PostgresInsert>(op, op.schema, std::move(op.info));
235+
insert.children.push_back(inner_plan);
236+
return insert;
239237
}
240238

241239
} // namespace duckdb

0 commit comments

Comments
 (0)