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

refactor table function constructor #4664

Merged
merged 2 commits into from
Dec 23, 2024
Merged
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
10 changes: 7 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,13 @@ 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
10 changes: 6 additions & 4 deletions extension/duckdb/src/function/clear_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ static std::unique_ptr<TableFuncBindData> clearCacheBindFunc(ClientContext* cont
1 /* maxOffset */);
}

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

} // namespace duckdb_extension
} // namespace kuzu
13 changes: 8 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,14 @@ 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
11 changes: 7 additions & 4 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,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING,
LogicalTypeID::LIST});
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
10 changes: 7 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,13 @@ 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
10 changes: 7 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,13 @@ 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
10 changes: 7 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,13 @@ 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
9 changes: 7 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,13 @@ 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
9 changes: 7 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,13 @@ 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
9 changes: 7 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,13 @@ 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
9 changes: 7 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,13 @@ 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
30 changes: 2 additions & 28 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,35 +94,11 @@ 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
Loading