Skip to content

Commit

Permalink
Don't parse with lexer query string
Browse files Browse the repository at this point in the history
Manually parse OPTIONS part of COPY query. Check settings and allow only
combinations that should work with DuckDB execution.
  • Loading branch information
mkaruza committed Oct 11, 2024
1 parent a08020f commit 90b297c
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 43 deletions.
3 changes: 2 additions & 1 deletion include/pgduckdb/utility/copy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ extern "C" {
#include "nodes/plannodes.h"
}

bool DuckdbCopy(PlannedStmt *pstmt, const char *query_string, struct QueryEnvironment *query_env, uint64 *processed);
bool DuckdbCopy(PlannedStmt *pstmt, const char *query_string, struct QueryEnvironment *query_env, uint64 *processed,
bool *is_copy_to_cloud);
7 changes: 6 additions & 1 deletion src/pgduckdb_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,19 @@ static void
DuckdbUtilityHook(PlannedStmt *pstmt, const char *query_string, bool read_only_tree, ProcessUtilityContext context,
ParamListInfo params, struct QueryEnvironment *query_env, DestReceiver *dest, QueryCompletion *qc) {
Node *parsetree = pstmt->utilityStmt;
bool is_copy_to_cloud = false;
if (duckdb_execution && pgduckdb::IsExtensionRegistered() && IsA(parsetree, CopyStmt)) {
uint64 processed;
if (DuckdbCopy(pstmt, query_string, query_env, &processed)) {
if (DuckdbCopy(pstmt, query_string, query_env, &processed, &is_copy_to_cloud)) {
if (qc) {
SetQueryCompletion(qc, CMDTAG_COPY, processed);
}
return;
}
/* We have COPY .. TO remote so PG can't handle it, raise ERROR */
if (is_copy_to_cloud) {
elog(ERROR, "DuckDB COPY execution failed.");
}
}

if (pgduckdb::IsExtensionRegistered()) {
Expand Down
Loading

0 comments on commit 90b297c

Please sign in to comment.