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

Remove most C++ from pgduckdb.cpp #498

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 16 additions & 3 deletions include/pgduckdb/pgduckdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ typedef enum {
MOTHERDUCK_AUTO,
} MotherDuckEnabled;

// pgduckdb.c
// pgduckdb.cpp
extern "C" void _PG_init(void);

// pgduckdb_hooks.c
void DuckdbInitHooks(void);
void DuckdbInitGUC();

// pgduckdb_hooks.cpp
void DuckdbInitHooks();

// pgduckdb_node.cpp
void DuckdbInitNode();

// pgduckdb_background_worker.cpp
void DuckdbInitBackgroundWorker();

namespace pgduckdb {
// pgduckdb_xact.cpp
void RegisterDuckdbXactCallback();
} // namespace pgduckdb
2 changes: 0 additions & 2 deletions include/pgduckdb/pgduckdb_background_worker.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

void DuckdbInitBackgroundWorker(void);

namespace pgduckdb {

void SyncMotherDuckCatalogsWithPg(bool drop_with_cascade);
Expand Down
1 change: 0 additions & 1 deletion include/pgduckdb/pgduckdb_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ extern "C" {
}

extern CustomScanMethods duckdb_scan_scan_methods;
extern "C" void DuckdbInitNode(void);
1 change: 0 additions & 1 deletion include/pgduckdb/pgduckdb_xact.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ void PreventInTransactionBlock(const char *statement_type);
} // namespace pg

void ClaimCurrentCommandId();
void RegisterDuckdbXactCallback();
void AutocommitSingleStatementQueries();
void MarkStatementNotTopLevel();
} // namespace pgduckdb
16 changes: 6 additions & 10 deletions src/pgduckdb.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#include "duckdb.hpp"
#include "pgduckdb/pgduckdb.h"

#include <type_traits>

extern "C" {
#include "postgres.h"
#include "miscadmin.h"
#include "utils/guc.h"
}

#include "pgduckdb/pgduckdb.h"
#include "pgduckdb/pgduckdb_node.hpp"
#include "pgduckdb/pgduckdb_background_worker.hpp"
#include "pgduckdb/pgduckdb_xact.hpp"

static void DuckdbInitGUC(void);

bool duckdb_force_execution = false;
int duckdb_max_threads_per_postgres_scan = 1;
int duckdb_motherduck_enabled = MotherDuckEnabled::MOTHERDUCK_AUTO;
Expand Down Expand Up @@ -99,6 +94,7 @@ DefineCustomVariable(const char *name, const char *short_desc, T *var, T min, T
} else {
static_assert("Unsupported type");
}

func(name, gettext_noop(short_desc), NULL, var, *var, min, max, context, flags, check_hook, assign_hook, show_hook);
}

Expand All @@ -122,8 +118,8 @@ static const struct config_enum_entry motherduck_enabled_options[] = {
};
/* clang-format on */

static void
DuckdbInitGUC(void) {
void
DuckdbInitGUC() {
DefineCustomVariable("duckdb.force_execution", "Force queries to use DuckDB execution", &duckdb_force_execution);

DefineCustomVariable("duckdb.enable_external_access", "Allow the DuckDB to access external state.",
Expand Down
2 changes: 1 addition & 1 deletion src/pgduckdb_background_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ force_motherduck_sync(PG_FUNCTION_ARGS) {
}

void
DuckdbInitBackgroundWorker(void) {
DuckdbInitBackgroundWorker() {
if (!pgduckdb::IsMotherDuckEnabledAnywhere()) {
return;
}
Expand Down
6 changes: 1 addition & 5 deletions src/pgduckdb_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ IsDuckdbPlan(PlannedStmt *stmt) {
}

CustomScan *custom_scan = castNode(CustomScan, plan);
if (custom_scan->methods != &duckdb_scan_scan_methods) {
return false;
}

return true;
return custom_scan->methods == &duckdb_scan_scan_methods;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/pgduckdb_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Duckdb_ExplainCustomScan(CustomScanState *node, List * /*ancestors*/, ExplainSta
InvokeCPPFunc(Duckdb_ExplainCustomScan_Cpp, node, es);
}

extern "C" void
void
DuckdbInitNode() {
/* setup scan methods */
memset(&duckdb_scan_scan_methods, 0, sizeof(duckdb_scan_scan_methods));
Expand Down