Skip to content

Commit

Permalink
Cleanup branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaruza committed Apr 9, 2024
1 parent 2979deb commit 6814034
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 1,200 deletions.
6 changes: 4 additions & 2 deletions include/quack/quack.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

// quack.c
void _PG_init(void);
void _PG_fini(void);

// quack_internal.cpp
const char * quack_duckdb_version();
// quack_hooks.c
extern void quack_init_hooks(void);
61 changes: 0 additions & 61 deletions include/quack/quack.hpp

This file was deleted.

47 changes: 25 additions & 22 deletions include/quack/quack_scan.hpp → include/quack/quack_heap_scan.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include "duckdb.hpp"
#include "postgres.h"
#include "miscadmin.h"

extern "C" {
#include "postgres.h"
#include "miscadmin.h"
#include "executor/executor.h"
} // extern "C"
#include "access/relscan.h"
}

// Postgres Relation

Expand All @@ -27,11 +28,11 @@ class PostgresRelation {
Relation rel = nullptr;
};

namespace duckdb {
namespace quack {

// Local State

struct PostgresScanLocalState : public LocalTableFunctionState {
struct PostgresScanLocalState : public duckdb::LocalTableFunctionState {
public:
PostgresScanLocalState(PostgresRelation &relation, Snapshot snapshot);
~PostgresScanLocalState() override;
Expand All @@ -44,15 +45,14 @@ struct PostgresScanLocalState : public LocalTableFunctionState {

// Global State

struct PostgresScanGlobalState : public GlobalTableFunctionState {
struct PostgresScanGlobalState : public duckdb::GlobalTableFunctionState {
explicit PostgresScanGlobalState();

std::mutex lock;
};

// Bind Data

struct PostgresScanFunctionData : public TableFunctionData {
struct PostgresScanFunctionData : public duckdb::TableFunctionData {
public:
PostgresScanFunctionData(PostgresRelation &&relation, Snapshot snapshot);
~PostgresScanFunctionData() override;
Expand All @@ -64,32 +64,34 @@ struct PostgresScanFunctionData : public TableFunctionData {

// ------- Table Function -------

struct PostgresScanFunction : public TableFunction {
struct PostgresScanFunction : public duckdb::TableFunction {
public:
PostgresScanFunction();

public:
static unique_ptr<FunctionData> PostgresBind(ClientContext &context, TableFunctionBindInput &input,
vector<LogicalType> &return_types, vector<string> &names);
static unique_ptr<GlobalTableFunctionState> PostgresInitGlobal(ClientContext &context,
TableFunctionInitInput &input);
static unique_ptr<LocalTableFunctionState>
PostgresInitLocal(ExecutionContext &context, TableFunctionInitInput &input, GlobalTableFunctionState *gstate);
static duckdb::unique_ptr<duckdb::FunctionData> PostgresBind(duckdb::ClientContext &context,
duckdb::TableFunctionBindInput &input,
duckdb::vector<duckdb::LogicalType> &return_types,
duckdb::vector<duckdb::string> &names);
static duckdb::unique_ptr<duckdb::GlobalTableFunctionState>
PostgresInitGlobal(duckdb::ClientContext &context, duckdb::TableFunctionInitInput &input);
static duckdb::unique_ptr<duckdb::LocalTableFunctionState>
PostgresInitLocal(duckdb::ExecutionContext &context, duckdb::TableFunctionInitInput &input,
duckdb::GlobalTableFunctionState *gstate);
// static idx_t PostgresMaxThreads(ClientContext &context, const FunctionData *bind_data_p);
// static bool PostgresParallelStateNext(ClientContext &context, const FunctionData *bind_data_p,
// LocalTableFunctionState *lstate, GlobalTableFunctionState *gstate); static double PostgresProgress(ClientContext
// &context, const FunctionData *bind_data_p, const GlobalTableFunctionState *gstate);
static void PostgresFunc(ClientContext &context, TableFunctionInput &data_p, DataChunk &output);
static void PostgresFunc(duckdb::ClientContext &context, duckdb::TableFunctionInput &data_p,
duckdb::DataChunk &output);
// static unique_ptr<NodeStatistics> PostgresCardinality(ClientContext &context, const FunctionData *bind_data);
// static idx_t PostgresGetBatchIndex(ClientContext &context, const FunctionData *bind_data_p,
// LocalTableFunctionState *local_state, GlobalTableFunctionState *global_state); static void
// PostgresSerialize(Serializer &serializer, const optional_ptr<FunctionData> bind_data, const TableFunction
// &function);
};

// ------- Replacement Scan -------

struct PostgresReplacementScanData : public ReplacementScanData {
struct PostgresReplacementScanData : public duckdb::ReplacementScanData {
public:
PostgresReplacementScanData(QueryDesc *desc);
~PostgresReplacementScanData() override;
Expand All @@ -98,7 +100,8 @@ struct PostgresReplacementScanData : public ReplacementScanData {
QueryDesc *desc;
};

unique_ptr<TableRef> PostgresReplacementScan(ClientContext &context, const string &table_name,
ReplacementScanData *data);
duckdb::unique_ptr<duckdb::TableRef> PostgresReplacementScan(duckdb::ClientContext &context,
const duckdb::string &table_name,
duckdb::ReplacementScanData *data);

} // namespace duckdb
} // namespace quack
7 changes: 7 additions & 0 deletions include/quack/quack_select.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#include "postgres.h"

#include "executor/executor.h"

bool quack_execute_select(QueryDesc *query_desc, ScanDirection direction, uint64_t count);
14 changes: 14 additions & 0 deletions include/quack/quack_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "duckdb.hpp"

extern "C" {
#include "postgres.h"
#include "executor/tuptable.h"
}

namespace quack {
duckdb::LogicalType ConvertPostgresToDuckColumnType(Oid type);
void ConvertPostgresToDuckValue(Datum value, duckdb::Vector &result, idx_t offset);
void ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col);
} // namespace quack
9 changes: 0 additions & 9 deletions sql/quack--0.0.1.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
CREATE SCHEMA quack;

CREATE OR REPLACE FUNCTION quack.quack_am_handler(internal)
RETURNS table_am_handler
LANGUAGE C
AS 'MODULE_PATHNAME', 'quack_am_handler';

CREATE ACCESS METHOD quack
TYPE TABLE
HANDLER quack.quack_am_handler;
12 changes: 5 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
ADD_LIBRARY(extension OBJECT quack_internal.cpp
quack_hooks.cpp
quack_scan.cpp
quack_tableam.cpp
quack_utility.cpp
quack_write_manager.cpp
quack.cpp)
ADD_LIBRARY(extension OBJECT quack.c
quack_hooks.c
quack_select.cpp
quack_heap_scan.cpp
quack_types.cpp)

set(PROJECT_OBJECTS ${PROJECT_OBJECTS} "$<TARGET_OBJECTS:extension>" PARENT_SCOPE)
21 changes: 21 additions & 0 deletions src/quack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "postgres.h"

#include "utils/guc.h"

#include "quack/quack.h"

PG_MODULE_MAGIC;

static void quack_init_guc(void);

void
_PG_init(void) {
quack_init_guc();
quack_init_hooks();
}

/* clang-format off */
static void
quack_init_guc(void) {

}
75 changes: 0 additions & 75 deletions src/quack.cpp

This file was deleted.

Loading

0 comments on commit 6814034

Please sign in to comment.