Skip to content

Commit

Permalink
refactor table function constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Dec 23, 2024
1 parent c93bbd9 commit 8b3b9b5
Show file tree
Hide file tree
Showing 32 changed files with 198 additions and 111 deletions.
9 changes: 6 additions & 3 deletions extension/delta/src/function/delta_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ std::unique_ptr<TableFuncLocalState> initEmptyLocalState(TableFunctionInitInput&

function_set DeltaScanFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(
std::make_unique<TableFunction>(name, tableFunc, bindFunc, initDeltaScanSharedState,
initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initDeltaScanSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
9 changes: 6 additions & 3 deletions extension/duckdb/src/function/clear_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ static std::unique_ptr<TableFuncBindData> clearCacheBindFunc(ClientContext* cont
}

ClearCacheFunction::ClearCacheFunction()
: TableFunction{name, clearCacheTableFunc, clearCacheBindFunc,
function::SimpleTableFunction::initSharedState,
function::SimpleTableFunction::initEmptyLocalState, std::vector<LogicalTypeID>{}} {}
: TableFunction{name, std::vector<LogicalTypeID>{}} {
tableFunc = clearCacheTableFunc;
bindFunc = clearCacheBindFunc;
initSharedStateFunc = SimpleTableFunction::initSharedState;
initLocalStateFunc = SimpleTableFunction::initEmptyLocalState;
}

} // namespace duckdb_extension
} // namespace kuzu
12 changes: 7 additions & 5 deletions extension/duckdb/src/function/duckdb_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ std::unique_ptr<function::TableFuncBindData> DuckDBScanFunction::bindFunc(
}

TableFunction getScanFunction(DuckDBScanBindData bindData) {
return TableFunction(DuckDBScanFunction::DUCKDB_SCAN_FUNC_NAME, DuckDBScanFunction::tableFunc,
std::bind(DuckDBScanFunction::bindFunc, std::move(bindData), std::placeholders::_1,
std::placeholders::_2),
DuckDBScanFunction::initSharedState, DuckDBScanFunction::initLocalState,
std::vector<LogicalTypeID>{});
auto function = TableFunction(DuckDBScanFunction::DUCKDB_SCAN_FUNC_NAME, std::vector<LogicalTypeID>{});
function.tableFunc = DuckDBScanFunction::tableFunc;
function.bindFunc = std::bind(DuckDBScanFunction::bindFunc, std::move(bindData), std::placeholders::_1,
std::placeholders::_2);
function.initSharedStateFunc = DuckDBScanFunction::initSharedState;
function.initLocalStateFunc = DuckDBScanFunction::initLocalState;
return function;
}

} // namespace duckdb_extension
Expand Down
7 changes: 5 additions & 2 deletions extension/fts/src/function/create_fts_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,13 @@ static common::offset_t tableFunc(TableFuncInput& input, TableFuncOutput& /*outp

function_set CreateFTSFunction::getFunctionSet() {
function_set functionSet;
auto func = std::make_unique<TableFunction>(name, tableFunc, bindFunc, initSharedState,
initEmptyLocalState,
auto func = std::make_unique<TableFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING,
LogicalTypeID::LIST});
func->tableFunc = tableFunc;
func->bindFunc = bindFunc;
func->initSharedStateFunc = initSharedState;
func->initLocalStateFunc = initEmptyLocalState;
func->rewriteFunc = createFTSIndexQuery;
func->canParallelFunc = []() { return false; };
functionSet.push_back(std::move(func));
Expand Down
7 changes: 5 additions & 2 deletions extension/fts/src/function/drop_fts_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ static common::offset_t tableFunc(TableFuncInput& input, TableFuncOutput& /*outp

function_set DropFTSFunction::getFunctionSet() {
function_set functionSet;
auto func = std::make_unique<TableFunction>(name, tableFunc, bindFunc, initSharedState,
initEmptyLocalState,
auto func = std::make_unique<TableFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING});
func->tableFunc = tableFunc;
func->bindFunc = bindFunc;
func->initSharedStateFunc = initSharedState;
func->initLocalStateFunc = initEmptyLocalState;
func->rewriteFunc = dropFTSIndexQuery;
func->canParallelFunc = []() { return false; };
functionSet.push_back(std::move(func));
Expand Down
9 changes: 6 additions & 3 deletions extension/iceberg/src/function/iceberg_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ std::unique_ptr<TableFuncBindData> metadataBindFunc(main::ClientContext* context

function_set IcebergMetadataFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, delta_extension::tableFunc,
metadataBindFunc, delta_extension::initDeltaScanSharedState,
delta_extension::initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = delta_extension::tableFunc;
function->bindFunc = metadataBindFunc;
function->initSharedStateFunc = delta_extension::initDeltaScanSharedState;
function->initLocalStateFunc = delta_extension::initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
9 changes: 6 additions & 3 deletions extension/iceberg/src/function/iceberg_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ std::unique_ptr<TableFuncBindData> scanBindFunc(main::ClientContext* context,

function_set IcebergScanFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, delta_extension::tableFunc,
scanBindFunc, delta_extension::initDeltaScanSharedState,
delta_extension::initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = delta_extension::tableFunc;
function->bindFunc = scanBindFunc;
function->initSharedStateFunc = delta_extension::initDeltaScanSharedState;
function->initLocalStateFunc = delta_extension::initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
9 changes: 6 additions & 3 deletions extension/iceberg/src/function/iceberg_snapshots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ static std::unique_ptr<TableFuncBindData> snapshotBindFunc(main::ClientContext*

function_set IcebergSnapshotsFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, delta_extension::tableFunc,
snapshotBindFunc, delta_extension::initDeltaScanSharedState,
delta_extension::initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = delta_extension::tableFunc;
function->bindFunc = snapshotBindFunc;
function->initSharedStateFunc = delta_extension::initDeltaScanSharedState;
function->initLocalStateFunc = delta_extension::initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
9 changes: 7 additions & 2 deletions extension/json/src/functions/table_functions/json_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,13 @@ static void finalizeFunc(processor::ExecutionContext* ctx, TableFuncSharedState*

std::unique_ptr<TableFunction> JsonScan::getFunction() {
auto func =
std::make_unique<TableFunction>(name, tableFunc, bindFunc, initSharedState, initLocalState,
progressFunc, std::vector<LogicalTypeID>{LogicalTypeID::STRING}, finalizeFunc);
std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
func->tableFunc = tableFunc;
func->bindFunc = bindFunc;
func->initSharedStateFunc = initSharedState;
func->initLocalStateFunc = initLocalState;
func->progressFunc = progressFunc;
func->finalizeFunc = finalizeFunc;
return func;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/bm_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set BMInfoFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<common::LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<common::LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
7 changes: 5 additions & 2 deletions src/function/table/call/clear_warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* /*contex

function_set ClearWarningsFunction::getFunctionSet() {
function_set functionSet;
auto func = std::make_unique<TableFunction>(name, tableFunc, bindFunc, initSharedState,
initEmptyLocalState, std::vector<LogicalTypeID>{});
auto func = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
func->tableFunc = tableFunc;
func->bindFunc = bindFunc;
func->initSharedStateFunc = initSharedState;
func->initLocalStateFunc = initEmptyLocalState;
func->canParallelFunc = []() { return false; };
functionSet.push_back(std::move(func));
return functionSet;
Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/current_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(ClientContext* context,

function_set CurrentSettingFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/db_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(ClientContext*, TableFuncBind

function_set DBVersionFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_attached_databases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set ShowAttachedDatabasesFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(ClientContext* context,

function_set ShowConnectionFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set ShowFunctionsFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_sequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set ShowSequencesFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set ShowTablesFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/show_warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set ShowWarningsFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/stats_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(ClientContext* context,

function_set StatsInfoFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initLocalState, std::vector{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/storage_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(ClientContext* context,

function_set StorageInfoFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
8 changes: 6 additions & 2 deletions src/function/table/call/table_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ static std::unique_ptr<TableFuncBindData> bindFunc(main::ClientContext* context,

function_set TableInfoFunction::getFunctionSet() {
function_set functionSet;
functionSet.push_back(std::make_unique<TableFunction>(name, tableFunc, bindFunc,
initSharedState, initEmptyLocalState, std::vector<LogicalTypeID>{LogicalTypeID::STRING}));
auto function = std::make_unique<TableFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING});
function->tableFunc = tableFunc;
function->bindFunc = bindFunc;
function->initSharedStateFunc = initSharedState;
function->initLocalStateFunc = initEmptyLocalState;
functionSet.push_back(std::move(function));
return functionSet;
}

Expand Down
32 changes: 3 additions & 29 deletions src/include/function/table_functions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include <optional>

#include "common/data_chunk/data_chunk.h"
#include "function.h"

Expand Down Expand Up @@ -96,36 +94,12 @@ struct KUZU_API TableFunction : public Function {
table_func_can_parallel_t canParallelFunc = [] { return true; };
table_func_progress_t progressFunc = [](TableFuncSharedState*) { return 0.0; };
table_func_finalize_t finalizeFunc = [](auto, auto) {};
table_func_rewrite_t rewriteFunc;
table_func_rewrite_t rewriteFunc = nullptr;

TableFunction()
: Function{}, tableFunc{nullptr}, bindFunc{nullptr}, initSharedStateFunc{nullptr},
initLocalStateFunc{nullptr} {};
TableFunction() : Function{} {};
TableFunction(std::string name, std::vector<common::LogicalTypeID> inputTypes)
: Function{name, inputTypes} {}
TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
std::vector<common::LogicalTypeID> inputTypes,
std::optional<table_func_finalize_t> finalizeFunc = {})
: Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
initLocalStateFunc{initLocalFunc} {
if (finalizeFunc.has_value()) {
this->finalizeFunc = finalizeFunc.value();
}
}
TableFunction(std::string name, table_func_t tableFunc, table_func_bind_t bindFunc,
table_func_init_shared_t initSharedFunc, table_func_init_local_t initLocalFunc,
table_func_progress_t progressFunc, std::vector<common::LogicalTypeID> inputTypes,
std::optional<table_func_finalize_t> finalizeFunc = {})
: Function{std::move(name), std::move(inputTypes)}, tableFunc{tableFunc},
bindFunc{bindFunc}, initSharedStateFunc{initSharedFunc},
initLocalStateFunc{initLocalFunc}, progressFunc(progressFunc) {
if (finalizeFunc.has_value()) {
this->finalizeFunc = finalizeFunc.value();
}
}


std::string signatureToString() const override {
return common::LogicalTypeUtils::toString(parameterTypeIDs);
}
Expand Down
1 change: 1 addition & 0 deletions src/include/main/client_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <atomic>
#include <memory>
#include <mutex>
#include <optional>

#include "common/timer.h"
#include "common/types/value/value.h"
Expand Down
Loading

0 comments on commit 8b3b9b5

Please sign in to comment.