Skip to content

Commit 0a15573

Browse files
committed
Merge branch 'main' into mainschema
2 parents 27aeebc + 96df45d commit 0a15573

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+601
-257
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concurrency:
1414
jobs:
1515
duckdb-stable-build:
1616
name: Build extension binaries
17-
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@main
17+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_distribution.yml@v1.2.2
1818
with:
1919
duckdb_version: main
2020
ci_tools_version: main
@@ -24,7 +24,7 @@ jobs:
2424
duckdb-stable-deploy:
2525
name: Deploy extension binaries
2626
needs: duckdb-stable-build
27-
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@main
27+
uses: duckdb/extension-ci-tools/.github/workflows/_extension_deploy.yml@v1.2.2
2828
secrets: inherit
2929
with:
3030
duckdb_version: main

CMakeLists.txt

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 2.8.12)
1+
cmake_minimum_required(VERSION 2.8.12...3.29)
22
set(TARGET_NAME postgres_scanner)
33
project(${TARGET_NAME})
44

@@ -118,7 +118,8 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
118118

119119
# Download the PostgreSQL source code
120120
message(STATUS "Downloading PostgreSQL source code")
121-
file(DOWNLOAD
121+
file(
122+
DOWNLOAD
122123
"https://github.com/postgres/postgres/archive/refs/tags/REL_15_2.tar.gz"
123124
${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz
124125
SHOW_PROGRESS
@@ -132,13 +133,12 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
132133

133134
# Extract the PostgreSQL source code
134135
message(STATUS "Extracting PostgreSQL source code")
135-
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz
136-
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
136+
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_SOURCE_DIR}/pg.tar.gz DESTINATION
137+
${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
137138

138139
# Move out of root directory
139140
file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp/postgres-REL_15_2
140-
${CMAKE_CURRENT_SOURCE_DIR}/postgres
141-
)
141+
${CMAKE_CURRENT_SOURCE_DIR}/postgres)
142142

143143
# Remove the tmp directory
144144
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/postgres_tmp)
@@ -157,46 +157,32 @@ if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
157157

158158
# Check if configuration was successful
159159
if(NOT PG_MKVCBUILD_RESULT EQUAL 0)
160-
file(REMOVE_RECURSE postgres)
161-
message(FATAL_ERROR "Failed to configure PostgreSQL source code for windows")
160+
file(REMOVE_RECURSE postgres)
161+
message(
162+
FATAL_ERROR "Failed to configure PostgreSQL source code for windows")
162163
endif()
163164
else()
164165
# On other platforms, use the configure script to configure the source code
165166
set(ENV{CC} gcc)
166167
set(ENV{CXX} g++)
167168
execute_process(
168-
COMMAND ./configure
169-
--without-llvm
170-
--without-icu
171-
--without-tcl
172-
--without-perl
173-
--without-python
174-
--without-gssapi
175-
--without-pam
176-
--without-bsd-auth
177-
--without-ldap
178-
--without-bonjour
179-
--without-selinux
180-
--without-systemd
181-
--without-readline
182-
--without-libxml
183-
--without-libxslt
184-
--without-zlib
185-
--without-lz4
186-
--without-openssl
169+
COMMAND
170+
./configure --without-llvm --without-icu --without-tcl --without-perl
171+
--without-python --without-gssapi --without-pam --without-bsd-auth
172+
--without-ldap --without-bonjour --without-selinux --without-systemd
173+
--without-readline --without-libxml --without-libxslt --without-zlib
174+
--without-lz4 --without-openssl
187175
RESULT_VARIABLE PG_CONFIGURE_RESULT
188-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres
189-
)
176+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/postgres)
190177
# Check if configuration was successful
191178
if(NOT PG_CONFIGURE_RESULT EQUAL 0)
192179
file(REMOVE_RECURSE postgres)
193180
message(FATAL_ERROR "Failed to configure PostgreSQL source code")
194-
endif ()
181+
endif()
195182
endif()
196183
message(STATUS "Finished setting up PostgreSQL source code!")
197184
endif()
198185

199-
200186
set(PARAMETERS "-no-warnings")
201187
build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${ALL_OBJECT_FILES}
202188
${LIBPG_SOURCES_FULLPATH})

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 1880 files

src/include/postgres_binary_reader.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct PostgresBinaryReader {
2020
~PostgresBinaryReader() {
2121
Reset();
2222
}
23+
PostgresConnection &GetConn() {
24+
return con;
25+
}
2326

2427
bool Next() {
2528
Reset();
@@ -29,6 +32,10 @@ struct PostgresBinaryReader {
2932

3033
// len -1 signals end
3134
if (len == -1) {
35+
auto final_result = PQgetResult(con.GetConn());
36+
if (!final_result || PQresultStatus(final_result) != PGRES_COMMAND_OK) {
37+
throw IOException("Failed to fetch header for COPY: %s", string(PQresultErrorMessage(final_result)));
38+
}
3239
return false;
3340
}
3441

src/include/postgres_scanner.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ struct PostgresBindData : public FunctionData {
4545
void SetTablePages(idx_t approx_num_pages);
4646

4747
void SetCatalog(PostgresCatalog &catalog);
48+
void SetTable(PostgresTableEntry &table);
4849
optional_ptr<PostgresCatalog> GetCatalog() const {
4950
return pg_catalog;
5051
}
52+
optional_ptr<PostgresTableEntry> GetTable() const {
53+
return pg_table;
54+
}
5155

5256
unique_ptr<FunctionData> Copy() const override {
5357
throw NotImplementedException("");
@@ -58,6 +62,7 @@ struct PostgresBindData : public FunctionData {
5862

5963
private:
6064
optional_ptr<PostgresCatalog> pg_catalog;
65+
optional_ptr<PostgresTableEntry> pg_table;
6166
};
6267

6368
class PostgresAttachFunction : public TableFunction {

src/include/postgres_utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PostgresUtils {
6868
static bool SupportedPostgresOid(const LogicalType &input);
6969
static LogicalType RemoveAlias(const LogicalType &type);
7070
static PostgresType CreateEmptyPostgresType(const LogicalType &type);
71+
static string QuotePostgresIdentifier(const string &text);
7172

7273
static PostgresVersion ExtractPostgresVersion(const string &version);
7374
};

src/include/storage/postgres_catalog.hpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ class PostgresSchemaEntry;
2020

2121
class PostgresCatalog : public Catalog {
2222
public:
23-
explicit PostgresCatalog(AttachedDatabase &db_p, const string &path, AccessMode access_mode, string schema_to_load);
23+
explicit PostgresCatalog(AttachedDatabase &db_p, string connection_string, string attach_path,
24+
AccessMode access_mode, string schema_to_load);
2425
~PostgresCatalog();
2526

26-
string path;
27+
string connection_string;
28+
string attach_path;
2729
AccessMode access_mode;
2830

2931
public:
@@ -35,22 +37,24 @@ class PostgresCatalog : public Catalog {
3537
return default_schema.empty() ? "public" : default_schema;
3638
}
3739

40+
static string GetConnectionString(ClientContext &context, const string &attach_path, string secret_name);
41+
3842
optional_ptr<CatalogEntry> CreateSchema(CatalogTransaction transaction, CreateSchemaInfo &info) override;
3943

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

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

0 commit comments

Comments
 (0)