Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-- committed Oct 30, 2024
1 parent 18e35cf commit bb35b1a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 83 deletions.
12 changes: 6 additions & 6 deletions include/pgduckdb/pgduckdb_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ __CPPFunctionGuard__(const char *func_name, FuncArgs... args) {

// Wrappers

#define DECLARE_PG_FUNCTION(func_name) PG_FUNCTION_INFO_V1(func_name); \
Datum func_name##_cpp(PG_FUNCTION_ARGS); \
Datum func_name(PG_FUNCTION_ARGS) \
{ \
return InvokeCPPFunc(func_name##_cpp, fcinfo); \
}
#define DECLARE_PG_FUNCTION(func_name) \
PG_FUNCTION_INFO_V1(func_name); \
Datum func_name##_cpp(PG_FUNCTION_ARGS); \
Datum func_name(PG_FUNCTION_ARGS) { \
return InvokeCPPFunc(func_name##_cpp, fcinfo); \
}

int SPI_exec_or_throw(const char *query, int tcount, int expected_ret_code);

Expand Down
10 changes: 5 additions & 5 deletions src/pgduckdb_ddl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ duckdb_create_table_trigger_cpp(PG_FUNCTION_ARGS) {
WHERE cmds.object_type = 'table'
AND pg_class.relam = (SELECT oid FROM pg_am WHERE amname = 'duckdb')
)",
0, SPI_OK_SELECT);
0, SPI_OK_SELECT);

/* if we selected a row it was a duckdb table */
auto is_duckdb_table = SPI_processed > 0;
Expand Down Expand Up @@ -236,7 +236,7 @@ duckdb_create_table_trigger_cpp(PG_FUNCTION_ARGS) {
INSERT INTO duckdb.tables (relid, duckdb_db, motherduck_catalog_version)
VALUES ($1, $2, $3)
)",
lengthof(arg_types), arg_types, values, nulls, false, 0);
lengthof(arg_types), arg_types, values, nulls, false, 0);

/* Revert back to original privileges */
SetUserIdAndSecContext(saved_userid, sec_context);
Expand Down Expand Up @@ -359,7 +359,7 @@ duckdb_drop_trigger_cpp(PG_FUNCTION_ARGS) {
WHERE object_type = 'schema'
AND object_identity LIKE 'ddb$%'
)",
0, SPI_OK_SELECT);
0, SPI_OK_SELECT);

if (SPI_processed > 0) {
throw std::runtime_error("Currently it's not possible to drop ddb$ schemas");
Expand Down Expand Up @@ -391,7 +391,7 @@ duckdb_drop_trigger_cpp(PG_FUNCTION_ARGS) {
WHERE relid = objid
RETURNING objs.schema_name, objs.object_name
)",
0, SPI_OK_DELETE_RETURNING);
0, SPI_OK_DELETE_RETURNING);

/* Revert back to original privileges */
SetUserIdAndSecContext(saved_userid, sec_context);
Expand Down Expand Up @@ -451,7 +451,7 @@ duckdb_drop_trigger_cpp(PG_FUNCTION_ARGS) {
WHERE object_type = 'table'
AND schema_name = 'pg_temp'
)",
0, SPI_OK_SELECT);
0, SPI_OK_SELECT);

for (auto proc = 0; proc < SPI_processed; ++proc) {
HeapTuple tuple = SPI_tuptable->vals[proc];
Expand Down
3 changes: 2 additions & 1 deletion src/pgduckdb_duckdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ DuckDBManager::LoadExtensions(duckdb::ClientContext &context) {
duckdb::unique_ptr<duckdb::Connection>
DuckDBManager::CreateConnection() {
if (!pgduckdb::IsDuckdbExecutionAllowed()) {
throw std::runtime_error("DuckDB execution is not allowed because you have not been granted the duckdb.postgres_role");
throw std::runtime_error(
"DuckDB execution is not allowed because you have not been granted the duckdb.postgres_role");
}

auto &instance = Get();
Expand Down
6 changes: 3 additions & 3 deletions src/pgduckdb_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ DuckdbPlannerHook(Query *parse, const char *query_string, int cursor_options, Pa
}

static void
DuckdbUtilityHook_Cpp(PlannedStmt *pstmt, const char *query_string, bool read_only_tree,
ProcessUtilityContext context, ParamListInfo params, struct QueryEnvironment *query_env,
DestReceiver *dest, QueryCompletion *qc) {
DuckdbUtilityHook_Cpp(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;
if (pgduckdb::IsExtensionRegistered() && IsA(parsetree, CopyStmt)) {
uint64 processed;
Expand Down
121 changes: 60 additions & 61 deletions src/pgduckdb_table_am.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ extern "C" {

#include "pgduckdb/pgduckdb_duckdb.hpp"
#include "pgduckdb/pgduckdb_ddl.hpp"
#include "pgduckdb/pgduckdb_utils.hpp"

extern "C" {

Expand Down Expand Up @@ -399,70 +398,70 @@ duckdb_scan_sample_next_tuple(TableScanDesc scan, SampleScanState *scanstate, Tu
* ------------------------------------------------------------------------
*/

static const TableAmRoutine duckdb_methods = {
.type = T_TableAmRoutine,

.slot_callbacks = duckdb_slot_callbacks,

.scan_begin = duckdb_scan_begin,
.scan_end = duckdb_scan_end,
.scan_rescan = duckdb_scan_rescan,
.scan_getnextslot = duckdb_scan_getnextslot,

/* optional callbacks */
.scan_set_tidrange = NULL,
.scan_getnextslot_tidrange = NULL,

/* these are common helper functions */
.parallelscan_estimate = table_block_parallelscan_estimate,
.parallelscan_initialize = table_block_parallelscan_initialize,
.parallelscan_reinitialize = table_block_parallelscan_reinitialize,

.index_fetch_begin = duckdb_index_fetch_begin,
.index_fetch_reset = duckdb_index_fetch_reset,
.index_fetch_end = duckdb_index_fetch_end,
.index_fetch_tuple = duckdb_index_fetch_tuple,

.tuple_fetch_row_version = duckdb_fetch_row_version,
.tuple_tid_valid = duckdb_tuple_tid_valid,
.tuple_get_latest_tid = duckdb_get_latest_tid,
.tuple_satisfies_snapshot = duckdb_tuple_satisfies_snapshot,
.index_delete_tuples = duckdb_index_delete_tuples,

.tuple_insert = duckdb_tuple_insert,
.tuple_insert_speculative = duckdb_tuple_insert_speculative,
.tuple_complete_speculative = duckdb_tuple_complete_speculative,
.multi_insert = duckdb_multi_insert,
.tuple_delete = duckdb_tuple_delete,
.tuple_update = duckdb_tuple_update,
.tuple_lock = duckdb_tuple_lock,
.finish_bulk_insert = duckdb_finish_bulk_insert,
static const TableAmRoutine duckdb_methods = {.type = T_TableAmRoutine,

.slot_callbacks = duckdb_slot_callbacks,

.scan_begin = duckdb_scan_begin,
.scan_end = duckdb_scan_end,
.scan_rescan = duckdb_scan_rescan,
.scan_getnextslot = duckdb_scan_getnextslot,

/* optional callbacks */
.scan_set_tidrange = NULL,
.scan_getnextslot_tidrange = NULL,

/* these are common helper functions */
.parallelscan_estimate = table_block_parallelscan_estimate,
.parallelscan_initialize = table_block_parallelscan_initialize,
.parallelscan_reinitialize = table_block_parallelscan_reinitialize,

.index_fetch_begin = duckdb_index_fetch_begin,
.index_fetch_reset = duckdb_index_fetch_reset,
.index_fetch_end = duckdb_index_fetch_end,
.index_fetch_tuple = duckdb_index_fetch_tuple,

.tuple_fetch_row_version = duckdb_fetch_row_version,
.tuple_tid_valid = duckdb_tuple_tid_valid,
.tuple_get_latest_tid = duckdb_get_latest_tid,
.tuple_satisfies_snapshot = duckdb_tuple_satisfies_snapshot,
.index_delete_tuples = duckdb_index_delete_tuples,

.tuple_insert = duckdb_tuple_insert,
.tuple_insert_speculative = duckdb_tuple_insert_speculative,
.tuple_complete_speculative = duckdb_tuple_complete_speculative,
.multi_insert = duckdb_multi_insert,
.tuple_delete = duckdb_tuple_delete,
.tuple_update = duckdb_tuple_update,
.tuple_lock = duckdb_tuple_lock,
.finish_bulk_insert = duckdb_finish_bulk_insert,

#if PG_VERSION_NUM >= 160000
.relation_set_new_filelocator = duckdb_relation_set_new_filelocator,
.relation_set_new_filelocator = duckdb_relation_set_new_filelocator,
#else
.relation_set_new_filenode = duckdb_relation_set_new_filenode,
.relation_set_new_filenode = duckdb_relation_set_new_filenode,
#endif
.relation_nontransactional_truncate = duckdb_relation_nontransactional_truncate,
.relation_copy_data = duckdb_copy_data,
.relation_copy_for_cluster = duckdb_copy_for_cluster,
.relation_vacuum = duckdb_vacuum,
.scan_analyze_next_block = duckdb_scan_analyze_next_block,
.scan_analyze_next_tuple = duckdb_scan_analyze_next_tuple,
.index_build_range_scan = duckdb_index_build_range_scan,
.index_validate_scan = duckdb_index_validate_scan,

.relation_size = duckdb_relation_size,
.relation_needs_toast_table = duckdb_relation_needs_toast_table,
/* can be null because relation_needs_toast_table returns false */
.relation_fetch_toast_slice = NULL,

.relation_estimate_size = duckdb_estimate_rel_size,

.scan_bitmap_next_block = duckdb_scan_bitmap_next_block,
.scan_bitmap_next_tuple = duckdb_scan_bitmap_next_tuple,
.scan_sample_next_block = duckdb_scan_sample_next_block,
.scan_sample_next_tuple = duckdb_scan_sample_next_tuple};
.relation_nontransactional_truncate =
duckdb_relation_nontransactional_truncate,
.relation_copy_data = duckdb_copy_data,
.relation_copy_for_cluster = duckdb_copy_for_cluster,
.relation_vacuum = duckdb_vacuum,
.scan_analyze_next_block = duckdb_scan_analyze_next_block,
.scan_analyze_next_tuple = duckdb_scan_analyze_next_tuple,
.index_build_range_scan = duckdb_index_build_range_scan,
.index_validate_scan = duckdb_index_validate_scan,

.relation_size = duckdb_relation_size,
.relation_needs_toast_table = duckdb_relation_needs_toast_table,
/* can be null because relation_needs_toast_table returns false */
.relation_fetch_toast_slice = NULL,

.relation_estimate_size = duckdb_estimate_rel_size,

.scan_bitmap_next_block = duckdb_scan_bitmap_next_block,
.scan_bitmap_next_tuple = duckdb_scan_bitmap_next_tuple,
.scan_sample_next_block = duckdb_scan_sample_next_block,
.scan_sample_next_tuple = duckdb_scan_sample_next_tuple};

Datum
duckdb_am_handler(PG_FUNCTION_ARGS) {
Expand Down
8 changes: 5 additions & 3 deletions src/pgduckdb_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extern "C" {
namespace pgduckdb {

static bool
CheckDirectory(const std::string& directory) {
CheckDirectory(const std::string &directory) {
struct stat info;

if (lstat(directory.c_str(), &info) != 0) {
Expand Down Expand Up @@ -49,15 +49,17 @@ CreateOrGetDirectoryPath(std::string directory_name) {

if (!CheckDirectory(duckdb_data_directory)) {
if (MakePGDirectory(duckdb_data_directory.c_str()) == -1) {
throw std::runtime_error("Creating data directory '" + duckdb_data_directory + "' failed: `" + strerror(errno) + "`");
throw std::runtime_error("Creating data directory '" + duckdb_data_directory + "' failed: `" +
strerror(errno) + "`");
}
elog(DEBUG2, "Created %s directory", duckdb_data_directory.c_str());
};

return duckdb_data_directory;
}

int SPI_exec_or_throw(const char* query, int tcount, int expected_ret_code) {
int
SPI_exec_or_throw(const char *query, int tcount, int expected_ret_code) {
int ret = SPI_exec(query, tcount);
if (ret != expected_ret_code) {
throw std::runtime_error(std::string("SPI_exec failed: error code ") + SPI_result_code_string(ret));
Expand Down
2 changes: 1 addition & 1 deletion src/scan/heap_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ HeapReader::ReadPageTuples(duckdb::DataChunk &output) {
block = m_block_number;

m_buffer = PostgresFunctionGuard(ReadBufferExtended, m_rel, MAIN_FORKNUM, block, RBM_NORMAL,
m_buffer_access_strategy);
m_buffer_access_strategy);

PostgresFunctionGuard(LockBuffer, m_buffer, BUFFER_LOCK_SHARE);

Expand Down
2 changes: 1 addition & 1 deletion src/scan/postgres_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ FindMatchingRelation(const duckdb::string &schema, const duckdb::string &table)
return RangeVarGetRelid(table_range_var, AccessShareLock, true);
}

const char*
const char *
pgduckdb_pg_get_viewdef(Oid view) {
auto oid = ObjectIdGetDatum(view);
Datum viewdef = DirectFunctionCall1(pg_get_viewdef, oid);
Expand Down
2 changes: 0 additions & 2 deletions src/utility/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ CheckQueryPermissions(Query *query, const char *query_string) {

static duckdb::string
CreateCopyOptions(CopyStmt *copy_stmt, bool *options_valid) {


if (list_length(copy_stmt->options) == 0) {
return ";";
}
Expand Down

0 comments on commit bb35b1a

Please sign in to comment.