Skip to content
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

Use duckdb functions without having to specify the full type signature #531

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
3f2c5af
Initial trial for new read_csv syntax
JelteF Dec 9, 2024
bf6596f
Generate query that works for iceberg scans
JelteF Dec 11, 2024
6568155
Correct column aliases and use star
JelteF Dec 12, 2024
01d5ad5
Attempt to fix create table as, but very hacky
JelteF Dec 13, 2024
69b044e
Add comment about bug so I don't forget
JelteF Dec 13, 2024
556d476
Add support for duckdb.query
JelteF Dec 18, 2024
537753b
Add missing max aggregate
JelteF Dec 20, 2024
43e084a
Add error hint
JelteF Jan 14, 2025
926d1b5
Ignore warning about declarations after statements
JelteF Jan 14, 2025
e312a3b
Fix warning
JelteF Jan 14, 2025
e46b49f
Don't rename subscript expressions in subqueries
JelteF Jan 14, 2025
aa3d72b
Fix materialized views
JelteF Jan 14, 2025
6055d59
Only do CTAS type detection using duckdb for unresolved types
JelteF Jan 14, 2025
284795b
Use C duckdb_only_function handler for approx_count_distinct
JelteF Jan 14, 2025
3ce96f7
Support array/json indexing
JelteF Jan 14, 2025
7678dbc
Fix CTAS
JelteF Jan 15, 2025
83acc35
Move extension registration to top of subscript transform fuction
JelteF Jan 15, 2025
a4cf3a1
Remove pprint
JelteF Jan 15, 2025
adc717c
More comments and tests
JelteF Jan 15, 2025
5955471
Even more comments and tests
JelteF Jan 15, 2025
c238af7
Add missing file
JelteF Jan 15, 2025
09b7f56
Revert "Generate query that works for iceberg scans"
JelteF Jan 17, 2025
1c9ddda
Fix iceberg_scan in a better way
JelteF Jan 17, 2025
259e0f9
Update iceberg_scan fix
JelteF Jan 17, 2025
13c7a0e
Also wrap "query" in a subquery
JelteF Jan 17, 2025
8700df4
Update comment to reflect reality
JelteF Jan 18, 2025
b14a98e
Simplify and comment
JelteF Jan 21, 2025
fb48133
Simplify star reconstruction logic and move it almost fully to pgduck…
JelteF Jan 21, 2025
f4f5d17
Move some more logic to pgduckdb_ruleutils.cpp
JelteF Jan 21, 2025
2410c10
Move subscript to columnref conversion to pgduckdb_ruleutils.cpp
JelteF Jan 21, 2025
855ce18
Move duckdb.row refname generation to pgduckdb_ruleutils.cpp
JelteF Jan 21, 2025
2c3fae5
Improve subscript support
JelteF Jan 21, 2025
1b9f7d5
Port to PG16 ruleutils
JelteF Jan 21, 2025
bdcc965
Port to PG14 ruleutils
JelteF Jan 21, 2025
ac2bdf9
Add back removed comment
JelteF Jan 21, 2025
f24fc19
Port to PG15 ruleutils
JelteF Jan 21, 2025
89e2849
Add missing include for PG below 17
JelteF Jan 21, 2025
c41ea06
Add some PG14 version specific code
JelteF Jan 21, 2025
1b2d1cf
Add subquery aliases to make PG15 & PG14 happy
JelteF Jan 21, 2025
c890f35
Address review
JelteF Jan 23, 2025
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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ COMPILER_FLAGS=-Wno-sign-compare -Wshadow -Wswitch -Wunused-parameter -Wunreacha

override PG_CPPFLAGS += -Iinclude -isystem third_party/duckdb/src/include -isystem third_party/duckdb/third_party/re2 ${COMPILER_FLAGS}
override PG_CXXFLAGS += -std=c++17 ${DUCKDB_BUILD_CXX_FLAGS} ${COMPILER_FLAGS} -Wno-register
# Ignore declaration-after-statement warnings in our code. Postgres enforces
# this because their ancient style guide requires it, but we don't care. It
# would only apply to C files anyway, and we don't have many of those. The only
# ones that we do have are vendored in from Postgres (ruleutils), and allowing
# declarations to be anywhere is even a good thing for those as we can keep our
# changes to the vendored code in one place.
override PG_CFLAGS += -Wno-declaration-after-statement

SHLIB_LINK += -Wl,-rpath,$(PG_LIB)/ -lpq -Lthird_party/duckdb/build/$(DUCKDB_BUILD_TYPE)/src -L$(PG_LIB) -lduckdb -lstdc++ -llz4

Expand Down
3 changes: 3 additions & 0 deletions include/pgduckdb/pgduckdb_metadata_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ bool IsExtensionRegistered();
bool IsDuckdbOnlyFunction(Oid function_oid);
uint64 CacheVersion();
Oid ExtensionOid();
Oid SchemaOid();
Oid DuckdbRowOid();
Oid DuckdbUnresolvedTypeOid();
Oid DuckdbTableAmOid();
bool IsMotherDuckEnabled();
bool IsMotherDuckEnabledAnywhere();
Expand Down
22 changes: 22 additions & 0 deletions include/pgduckdb/pgduckdb_ruleutils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#include "postgres.h"
#include "pgduckdb/vendor/pg_list.hpp"

typedef struct StarReconstructionContext {
List *target_list;
int varno_star;
int varattno_star;
bool added_current_star;
} StarReconstructionContext;

char *pgduckdb_relation_name(Oid relid);
char *pgduckdb_function_name(Oid function_oid);
Expand All @@ -7,3 +15,17 @@ char *pgduckdb_get_tabledef(Oid relation_id);
bool pgduckdb_is_not_default_expr(Node *node, void *context);
List *pgduckdb_db_and_schema(const char *postgres_schema_name, bool is_duckdb_table);
const char *pgduckdb_db_and_schema_string(const char *postgres_schema_name, bool is_duckdb_table);
bool pgduckdb_is_duckdb_row(Oid type_oid);
bool pgduckdb_is_unresolved_type(Oid type_oid);
bool pgduckdb_var_is_duckdb_row(Var *var);
bool pgduckdb_func_returns_duckdb_row(RangeTblFunction *rtfunc);
bool pgduckdb_target_list_contains_unresolved_type_or_row(List *target_list);
Var *pgduckdb_duckdb_row_subscript_var(Expr *expr);
bool pgduckdb_reconstruct_star_step(StarReconstructionContext *ctx, ListCell *tle_cell);
bool pgduckdb_function_needs_subquery(Oid function_oid);
int pgduckdb_show_type(Const *constval, int original_showtype);
bool pgduckdb_subscript_has_custom_alias(Plan *plan, List *rtable, Var *subscript_var, char *colname);
SubscriptingRef *pgduckdb_strip_first_subscript(SubscriptingRef *sbsref, StringInfo buf);
char *pgduckdb_write_row_refname(StringInfo buf, char *refname, bool is_top_level);

extern bool processed_targetlist;
Loading