From cc1a65c79df58ea984fccc29521f333f59720805 Mon Sep 17 00:00:00 2001 From: Keenan Gugeler Date: Tue, 3 Oct 2023 11:25:11 -0400 Subject: [PATCH] refactor: splitup table_functions.h --- src/binder/bind/bind_graph_pattern.cpp | 1 + src/binder/bind/bind_reading_clause.cpp | 1 + src/catalog/catalog_content.cpp | 1 - src/function/CMakeLists.txt | 2 +- src/function/built_in_table_functions.cpp | 4 + src/function/table_functions.cpp | 130 ----------------- src/function/table_functions/CMakeLists.txt | 10 ++ .../table_functions/current_setting.cpp | 47 +++++++ src/function/table_functions/db_version.cpp | 31 ++++ src/function/table_functions/show_tables.cpp | 59 ++++++++ src/function/table_functions/table_info.cpp | 77 ++++++++++ .../reading_clause/bound_in_query_call.h | 1 + src/include/catalog/catalog.h | 3 + src/include/function/table_functions.h | 132 ++---------------- .../function/table_functions/bind_data.h | 24 ++++ .../function/table_functions/bind_input.h | 14 ++ .../table_functions/current_setting.h | 21 +++ .../function/table_functions/db_version.h | 21 +++ .../function/table_functions/show_tables.h | 21 +++ .../function/table_functions/table_info.h | 21 +++ .../planner/operator/logical_in_query_call.h | 1 + .../processor/operator/call/in_query_call.h | 1 + 22 files changed, 371 insertions(+), 252 deletions(-) delete mode 100644 src/function/table_functions.cpp create mode 100644 src/function/table_functions/CMakeLists.txt create mode 100644 src/function/table_functions/current_setting.cpp create mode 100644 src/function/table_functions/db_version.cpp create mode 100644 src/function/table_functions/show_tables.cpp create mode 100644 src/function/table_functions/table_info.cpp create mode 100644 src/include/function/table_functions/bind_data.h create mode 100644 src/include/function/table_functions/bind_input.h create mode 100644 src/include/function/table_functions/current_setting.h create mode 100644 src/include/function/table_functions/db_version.h create mode 100644 src/include/function/table_functions/show_tables.h create mode 100644 src/include/function/table_functions/table_info.h diff --git a/src/binder/bind/bind_graph_pattern.cpp b/src/binder/bind/bind_graph_pattern.cpp index e7cdfc33fd..ce51131051 100644 --- a/src/binder/bind/bind_graph_pattern.cpp +++ b/src/binder/bind/bind_graph_pattern.cpp @@ -11,6 +11,7 @@ #include "catalog/rel_table_schema.h" #include "common/exception/binder.h" #include "common/string_utils.h" +#include "main/client_context.h" using namespace kuzu::common; using namespace kuzu::parser; diff --git a/src/binder/bind/bind_reading_clause.cpp b/src/binder/bind/bind_reading_clause.cpp index b796471939..d7fd6cdeab 100644 --- a/src/binder/bind/bind_reading_clause.cpp +++ b/src/binder/bind/bind_reading_clause.cpp @@ -5,6 +5,7 @@ #include "binder/query/reading_clause/bound_match_clause.h" #include "binder/query/reading_clause/bound_unwind_clause.h" #include "common/exception/binder.h" +#include "function/table_functions/bind_input.h" #include "parser/query/reading_clause/in_query_call_clause.h" #include "parser/query/reading_clause/load_from.h" #include "parser/query/reading_clause/unwind_clause.h" diff --git a/src/catalog/catalog_content.cpp b/src/catalog/catalog_content.cpp index 1d96f63c86..5ac9407c45 100644 --- a/src/catalog/catalog_content.cpp +++ b/src/catalog/catalog_content.cpp @@ -13,7 +13,6 @@ using namespace kuzu::binder; using namespace kuzu::common; using namespace kuzu::storage; -using namespace kuzu::transaction; namespace kuzu { namespace catalog { diff --git a/src/function/CMakeLists.txt b/src/function/CMakeLists.txt index 53f573c5f4..7816d15bfd 100644 --- a/src/function/CMakeLists.txt +++ b/src/function/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(aggregate) +add_subdirectory(table_functions) add_library(kuzu_function OBJECT @@ -10,7 +11,6 @@ add_library(kuzu_function comparison_functions.cpp find_function.cpp scalar_macro_function.cpp - table_functions.cpp vector_arithmetic_functions.cpp vector_boolean_functions.cpp vector_cast_functions.cpp diff --git a/src/function/built_in_table_functions.cpp b/src/function/built_in_table_functions.cpp index 20fdf15111..e5433f1c9c 100644 --- a/src/function/built_in_table_functions.cpp +++ b/src/function/built_in_table_functions.cpp @@ -3,6 +3,10 @@ #include "common/exception/binder.h" #include "common/expression_type.h" #include "common/string_utils.h" +#include "function/table_functions/current_setting.h" +#include "function/table_functions/db_version.h" +#include "function/table_functions/show_tables.h" +#include "function/table_functions/table_info.h" using namespace kuzu::common; diff --git a/src/function/table_functions.cpp b/src/function/table_functions.cpp deleted file mode 100644 index 76bb0f617b..0000000000 --- a/src/function/table_functions.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "function/table_functions.h" - -#include "catalog/catalog.h" -#include "catalog/node_table_schema.h" - -using namespace kuzu::catalog; -using namespace kuzu::common; - -namespace kuzu { -namespace function { - -void TableInfoFunction::tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors) { - auto tableSchema = reinterpret_cast(bindData)->tableSchema; - auto numPropertiesToOutput = morsel.second - morsel.first; - auto outVectorPos = 0; - for (auto i = 0u; i < numPropertiesToOutput; i++) { - auto property = tableSchema->properties[morsel.first + i].get(); - if (tableSchema->getTableType() == TableType::REL && - property->getName() == InternalKeyword::ID) { - continue; - } - outputVectors[0]->setValue(outVectorPos, (int64_t)property->getPropertyID()); - outputVectors[1]->setValue(outVectorPos, property->getName()); - outputVectors[2]->setValue( - outVectorPos, LogicalTypeUtils::dataTypeToString(*property->getDataType())); - if (tableSchema->tableType == TableType::NODE) { - auto primaryKeyID = - reinterpret_cast(tableSchema)->getPrimaryKeyPropertyID(); - outputVectors[3]->setValue(outVectorPos, primaryKeyID == property->getPropertyID()); - } - outVectorPos++; - } - for (auto& outputVector : outputVectors) { - outputVector->state->selVector->selectedSize = outVectorPos; - } -} - -std::unique_ptr TableInfoFunction::bindFunc(main::ClientContext* context, - kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { - std::vector returnColumnNames; - std::vector returnTypes; - auto tableName = input.inputs[0].getValue(); - auto tableID = catalog->getTableID(tableName); - auto schema = catalog->getTableSchema(tableID); - returnColumnNames.emplace_back("property id"); - returnTypes.emplace_back(LogicalTypeID::INT64); - returnColumnNames.emplace_back("name"); - returnTypes.emplace_back(LogicalTypeID::STRING); - returnColumnNames.emplace_back("type"); - returnTypes.emplace_back(LogicalTypeID::STRING); - if (schema->tableType == TableType::NODE) { - returnColumnNames.emplace_back("primary key"); - returnTypes.emplace_back(LogicalTypeID::BOOL); - } - return std::make_unique( - schema, std::move(returnTypes), std::move(returnColumnNames), schema->getNumProperties()); -} - -void DBVersionFunction::tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors) { - auto outputVector = outputVectors[0]; - auto pos = outputVector->state->selVector->selectedPositions[0]; - outputVectors[0]->setValue(pos, std::string(KUZU_VERSION)); - outputVectors[0]->setNull(pos, false); - outputVector->state->selVector->selectedSize = 1; -} - -std::unique_ptr DBVersionFunction::bindFunc(main::ClientContext* context, - kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { - std::vector returnColumnNames; - std::vector returnTypes; - returnColumnNames.emplace_back("version"); - returnTypes.emplace_back(LogicalTypeID::STRING); - return std::make_unique( - std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */); -} - -void CurrentSettingFunction::tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors) { - auto currentSettingBindData = reinterpret_cast(bindData); - auto outputVector = outputVectors[0]; - auto pos = outputVector->state->selVector->selectedPositions[0]; - outputVectors[0]->setValue(pos, currentSettingBindData->result); - outputVectors[0]->setNull(pos, false); - outputVector->state->selVector->selectedSize = 1; -} - -std::unique_ptr CurrentSettingFunction::bindFunc(main::ClientContext* context, - kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { - auto optionName = input.inputs[0].getValue(); - std::vector returnColumnNames; - std::vector returnTypes; - returnColumnNames.emplace_back(optionName); - returnTypes.emplace_back(LogicalTypeID::STRING); - return std::make_unique(context->getCurrentSetting(optionName), - std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */); -} - -void ShowTablesFunction::tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors) { - auto tables = reinterpret_cast(bindData)->tables; - auto numTablesToOutput = morsel.second - morsel.first; - for (auto i = 0u; i < numTablesToOutput; i++) { - auto tableSchema = tables[morsel.first + i]; - outputVectors[0]->setValue(i, tableSchema->tableName); - std::string typeString = TableTypeUtils::toString(tableSchema->tableType); - outputVectors[1]->setValue(i, typeString); - outputVectors[2]->setValue(i, tableSchema->comment); - } - outputVectors[0]->state->selVector->selectedSize = numTablesToOutput; -} - -std::unique_ptr ShowTablesFunction::bindFunc(main::ClientContext* context, - kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { - std::vector returnColumnNames; - std::vector returnTypes; - returnColumnNames.emplace_back("name"); - returnTypes.emplace_back(LogicalTypeID::STRING); - returnColumnNames.emplace_back("type"); - returnTypes.emplace_back(LogicalTypeID::STRING); - returnColumnNames.emplace_back("comment"); - returnTypes.emplace_back(LogicalTypeID::STRING); - - return std::make_unique(catalog->getTableSchemas(), std::move(returnTypes), - std::move(returnColumnNames), catalog->getTableCount()); -} - -} // namespace function -} // namespace kuzu diff --git a/src/function/table_functions/CMakeLists.txt b/src/function/table_functions/CMakeLists.txt new file mode 100644 index 0000000000..b8cf5dc14c --- /dev/null +++ b/src/function/table_functions/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(kuzu_function_table_functions + OBJECT + current_setting.cpp + db_version.cpp + show_tables.cpp + table_info.cpp) + +set(ALL_OBJECT_FILES + ${ALL_OBJECT_FILES} $ + PARENT_SCOPE) diff --git a/src/function/table_functions/current_setting.cpp b/src/function/table_functions/current_setting.cpp new file mode 100644 index 0000000000..ae600fdda0 --- /dev/null +++ b/src/function/table_functions/current_setting.cpp @@ -0,0 +1,47 @@ +#include "function/table_functions/current_setting.h" + +#include "common/vector/value_vector.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" +#include "main/client_context.h" + +using namespace kuzu::common; + +namespace kuzu { +namespace function { +struct CurrentSettingBindData : public TableFuncBindData { + std::string result; + + CurrentSettingBindData(std::string result, std::vector returnTypes, + std::vector returnColumnNames, common::offset_t maxOffset) + : result{std::move(result)}, TableFuncBindData{std::move(returnTypes), + std::move(returnColumnNames), maxOffset} {} + + std::unique_ptr copy() override { + return std::make_unique( + result, returnTypes, returnColumnNames, maxOffset); + } +}; + +void CurrentSettingFunction::tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors) { + auto currentSettingBindData = reinterpret_cast(bindData); + auto outputVector = outputVectors[0]; + auto pos = outputVector->state->selVector->selectedPositions[0]; + outputVectors[0]->setValue(pos, currentSettingBindData->result); + outputVectors[0]->setNull(pos, false); + outputVector->state->selVector->selectedSize = 1; +} + +std::unique_ptr CurrentSettingFunction::bindFunc(main::ClientContext* context, + kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { + auto optionName = input.inputs[0].getValue(); + std::vector returnColumnNames; + std::vector returnTypes; + returnColumnNames.emplace_back(optionName); + returnTypes.emplace_back(LogicalTypeID::STRING); + return std::make_unique(context->getCurrentSetting(optionName), + std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */); +} +} // namespace function +} // namespace kuzu diff --git a/src/function/table_functions/db_version.cpp b/src/function/table_functions/db_version.cpp new file mode 100644 index 0000000000..8ba6815976 --- /dev/null +++ b/src/function/table_functions/db_version.cpp @@ -0,0 +1,31 @@ +#include "function/table_functions/db_version.h" + +#include "common/vector/value_vector.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +using namespace kuzu::common; + +namespace kuzu { +namespace function { +void DBVersionFunction::tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors) { + auto outputVector = outputVectors[0]; + auto pos = outputVector->state->selVector->selectedPositions[0]; + outputVectors[0]->setValue(pos, std::string(KUZU_VERSION)); + outputVectors[0]->setNull(pos, false); + outputVector->state->selVector->selectedSize = 1; +} + +std::unique_ptr DBVersionFunction::bindFunc(main::ClientContext* context, + kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { + std::vector returnColumnNames; + std::vector returnTypes; + returnColumnNames.emplace_back("version"); + returnTypes.emplace_back(LogicalTypeID::STRING); + return std::make_unique( + std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */); +} + +} // namespace function +} // namespace kuzu diff --git a/src/function/table_functions/show_tables.cpp b/src/function/table_functions/show_tables.cpp new file mode 100644 index 0000000000..cd1558bf07 --- /dev/null +++ b/src/function/table_functions/show_tables.cpp @@ -0,0 +1,59 @@ +#include "function/table_functions/show_tables.h" + +#include "catalog/catalog_content.h" +#include "catalog/table_schema.h" +#include "common/vector/value_vector.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +using namespace kuzu::common; + +namespace kuzu { +namespace function { + +struct ShowTablesBindData : public TableFuncBindData { + std::vector tables; + + ShowTablesBindData(std::vector tables, + std::vector returnTypes, std::vector returnColumnNames, + common::offset_t maxOffset) + : tables{std::move(tables)}, TableFuncBindData{std::move(returnTypes), + std::move(returnColumnNames), maxOffset} {} + + inline std::unique_ptr copy() override { + return std::make_unique( + tables, returnTypes, returnColumnNames, maxOffset); + } +}; + +void ShowTablesFunction::tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors) { + auto tables = reinterpret_cast(bindData)->tables; + auto numTablesToOutput = morsel.second - morsel.first; + for (auto i = 0u; i < numTablesToOutput; i++) { + auto tableSchema = tables[morsel.first + i]; + outputVectors[0]->setValue(i, tableSchema->tableName); + std::string typeString = TableTypeUtils::toString(tableSchema->tableType); + outputVectors[1]->setValue(i, typeString); + outputVectors[2]->setValue(i, tableSchema->comment); + } + outputVectors[0]->state->selVector->selectedSize = numTablesToOutput; +} + +std::unique_ptr ShowTablesFunction::bindFunc(main::ClientContext* context, + kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { + std::vector returnColumnNames; + std::vector returnTypes; + returnColumnNames.emplace_back("name"); + returnTypes.emplace_back(LogicalTypeID::STRING); + returnColumnNames.emplace_back("type"); + returnTypes.emplace_back(LogicalTypeID::STRING); + returnColumnNames.emplace_back("comment"); + returnTypes.emplace_back(LogicalTypeID::STRING); + + return std::make_unique(catalog->getTableSchemas(), std::move(returnTypes), + std::move(returnColumnNames), catalog->getTableCount()); +} + +} // namespace function +} // namespace kuzu diff --git a/src/function/table_functions/table_info.cpp b/src/function/table_functions/table_info.cpp new file mode 100644 index 0000000000..2fc94a1af8 --- /dev/null +++ b/src/function/table_functions/table_info.cpp @@ -0,0 +1,77 @@ +#include "function/table_functions/table_info.h" + +#include "catalog/catalog_content.h" +#include "catalog/node_table_schema.h" +#include "catalog/table_schema.h" +#include "common/vector/value_vector.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +using namespace kuzu::common; + +namespace kuzu { +namespace function { +struct TableInfoBindData : public TableFuncBindData { + catalog::TableSchema* tableSchema; + + TableInfoBindData(catalog::TableSchema* tableSchema, + std::vector returnTypes, std::vector returnColumnNames, + common::offset_t maxOffset) + : tableSchema{tableSchema}, TableFuncBindData{std::move(returnTypes), + std::move(returnColumnNames), maxOffset} {} + + std::unique_ptr copy() override { + return std::make_unique( + tableSchema, returnTypes, returnColumnNames, maxOffset); + } +}; + +void TableInfoFunction::tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors) { + auto tableSchema = reinterpret_cast(bindData)->tableSchema; + auto numPropertiesToOutput = morsel.second - morsel.first; + auto outVectorPos = 0; + for (auto i = 0u; i < numPropertiesToOutput; i++) { + auto property = tableSchema->properties[morsel.first + i].get(); + if (tableSchema->getTableType() == TableType::REL && + property->getName() == InternalKeyword::ID) { + continue; + } + outputVectors[0]->setValue(outVectorPos, (int64_t)property->getPropertyID()); + outputVectors[1]->setValue(outVectorPos, property->getName()); + outputVectors[2]->setValue( + outVectorPos, LogicalTypeUtils::dataTypeToString(*property->getDataType())); + if (tableSchema->tableType == TableType::NODE) { + auto primaryKeyID = + reinterpret_cast(tableSchema)->getPrimaryKeyPropertyID(); + outputVectors[3]->setValue(outVectorPos, primaryKeyID == property->getPropertyID()); + } + outVectorPos++; + } + for (auto& outputVector : outputVectors) { + outputVector->state->selVector->selectedSize = outVectorPos; + } +} + +std::unique_ptr TableInfoFunction::bindFunc(main::ClientContext* context, + kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { + std::vector returnColumnNames; + std::vector returnTypes; + auto tableName = input.inputs[0].getValue(); + auto tableID = catalog->getTableID(tableName); + auto schema = catalog->getTableSchema(tableID); + returnColumnNames.emplace_back("property id"); + returnTypes.emplace_back(LogicalTypeID::INT64); + returnColumnNames.emplace_back("name"); + returnTypes.emplace_back(LogicalTypeID::STRING); + returnColumnNames.emplace_back("type"); + returnTypes.emplace_back(LogicalTypeID::STRING); + if (schema->tableType == TableType::NODE) { + returnColumnNames.emplace_back("primary key"); + returnTypes.emplace_back(LogicalTypeID::BOOL); + } + return std::make_unique( + schema, std::move(returnTypes), std::move(returnColumnNames), schema->getNumProperties()); +} +} // namespace function +} // namespace kuzu diff --git a/src/include/binder/query/reading_clause/bound_in_query_call.h b/src/include/binder/query/reading_clause/bound_in_query_call.h index daa2ee25ae..886a4662fd 100644 --- a/src/include/binder/query/reading_clause/bound_in_query_call.h +++ b/src/include/binder/query/reading_clause/bound_in_query_call.h @@ -3,6 +3,7 @@ #include "binder/expression/expression.h" #include "binder/query/reading_clause/bound_reading_clause.h" #include "function/table_functions.h" +#include "function/table_functions/bind_data.h" namespace kuzu { namespace binder { diff --git a/src/include/catalog/catalog.h b/src/include/catalog/catalog.h index 527d50e36e..dbcbccc6b3 100644 --- a/src/include/catalog/catalog.h +++ b/src/include/catalog/catalog.h @@ -5,6 +5,9 @@ #include "catalog_content.h" namespace kuzu { +namespace storage { +class WAL; +} namespace transaction { enum class TransactionAction : uint8_t; } diff --git a/src/include/function/table_functions.h b/src/include/function/table_functions.h index 36db01b6ef..c8a3433eb7 100644 --- a/src/include/function/table_functions.h +++ b/src/include/function/table_functions.h @@ -1,15 +1,21 @@ #pragma once -#include "common/types/value/value.h" -#include "common/vector/value_vector.h" -#include "function/function_definition.h" -#include "main/client_context.h" +#include +#include +#include -namespace kuzu { +#include "common/types/internal_id_t.h" +namespace kuzu { namespace catalog { class CatalogContent; } // namespace catalog +namespace common { +class ValueVector; +} +namespace main { +class ClientContext; +} namespace function { @@ -17,32 +23,10 @@ struct TableFuncBindData; struct TableFuncBindInput; using table_func_t = std::function, - function::TableFuncBindData*, std::vector)>; + TableFuncBindData*, std::vector)>; using table_bind_func_t = std::function( main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog)>; -struct TableFuncBindData { - std::vector returnTypes; - std::vector returnColumnNames; - common::offset_t maxOffset; - - TableFuncBindData(std::vector returnTypes, - std::vector returnColumnNames, common::offset_t maxOffset) - : returnTypes{std::move(returnTypes)}, - returnColumnNames{std::move(returnColumnNames)}, maxOffset{maxOffset} {} - - virtual ~TableFuncBindData() = default; - - virtual std::unique_ptr copy() { - return std::make_unique(returnTypes, returnColumnNames, maxOffset); - } -}; - -struct TableFuncBindInput { - explicit TableFuncBindInput(std::vector inputs) : inputs{std::move(inputs)} {} - std::vector inputs; -}; - struct TableFunctionDefinition { std::string name; table_func_t tableFunc; @@ -52,97 +36,5 @@ struct TableFunctionDefinition { : name{std::move(name)}, tableFunc{std::move(tableFunc)}, bindFunc{std::move(bindFunc)} {} }; -struct TableInfoBindData : public TableFuncBindData { - catalog::TableSchema* tableSchema; - - TableInfoBindData(catalog::TableSchema* tableSchema, - std::vector returnTypes, std::vector returnColumnNames, - common::offset_t maxOffset) - : tableSchema{tableSchema}, TableFuncBindData{std::move(returnTypes), - std::move(returnColumnNames), maxOffset} {} - - std::unique_ptr copy() override { - return std::make_unique( - tableSchema, returnTypes, returnColumnNames, maxOffset); - } -}; - -struct TableInfoFunction { - inline static std::unique_ptr getDefinitions() { - return std::make_unique("table_info", tableFunc, bindFunc); - } - - static void tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors); - - static std::unique_ptr bindFunc( - main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); -}; - -struct DBVersionFunction { - inline static std::unique_ptr getDefinitions() { - return std::make_unique("db_version", tableFunc, bindFunc); - } - - static void tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors); - - static std::unique_ptr bindFunc( - main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); -}; - -struct CurrentSettingBindData : public TableFuncBindData { - std::string result; - - CurrentSettingBindData(std::string result, std::vector returnTypes, - std::vector returnColumnNames, common::offset_t maxOffset) - : result{std::move(result)}, TableFuncBindData{std::move(returnTypes), - std::move(returnColumnNames), maxOffset} {} - - std::unique_ptr copy() override { - return std::make_unique( - result, returnTypes, returnColumnNames, maxOffset); - } -}; - -struct CurrentSettingFunction { - inline static std::unique_ptr getDefinitions() { - return std::make_unique("current_setting", tableFunc, bindFunc); - } - - static void tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors); - - static std::unique_ptr bindFunc( - main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); -}; - -struct ShowTablesBindData : public TableFuncBindData { - std::vector tables; - - ShowTablesBindData(std::vector tables, - std::vector returnTypes, std::vector returnColumnNames, - common::offset_t maxOffset) - : tables{std::move(tables)}, TableFuncBindData{std::move(returnTypes), - std::move(returnColumnNames), maxOffset} {} - - inline std::unique_ptr copy() override { - return std::make_unique( - tables, returnTypes, returnColumnNames, maxOffset); - } -}; - -struct ShowTablesFunction { - inline static std::unique_ptr getDefinitions() { - return std::make_unique("show_tables", tableFunc, bindFunc); - } - - static void tableFunc(std::pair morsel, - function::TableFuncBindData* bindData, std::vector outputVectors); - - static std::unique_ptr bindFunc( - main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); -}; - } // namespace function } // namespace kuzu diff --git a/src/include/function/table_functions/bind_data.h b/src/include/function/table_functions/bind_data.h new file mode 100644 index 0000000000..9328142f5d --- /dev/null +++ b/src/include/function/table_functions/bind_data.h @@ -0,0 +1,24 @@ +#pragma once + +#include "common/types/value/value.h" + +namespace kuzu { +namespace function { +struct TableFuncBindData { + std::vector returnTypes; + std::vector returnColumnNames; + common::offset_t maxOffset; + + TableFuncBindData(std::vector returnTypes, + std::vector returnColumnNames, common::offset_t maxOffset) + : returnTypes{std::move(returnTypes)}, + returnColumnNames{std::move(returnColumnNames)}, maxOffset{maxOffset} {} + + virtual ~TableFuncBindData() = default; + + virtual std::unique_ptr copy() { + return std::make_unique(returnTypes, returnColumnNames, maxOffset); + } +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/function/table_functions/bind_input.h b/src/include/function/table_functions/bind_input.h new file mode 100644 index 0000000000..93aa0065fa --- /dev/null +++ b/src/include/function/table_functions/bind_input.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +#include "common/types/value/value.h" + +namespace kuzu { +namespace function { +struct TableFuncBindInput { + explicit TableFuncBindInput(std::vector inputs) : inputs{std::move(inputs)} {} + std::vector inputs; +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/function/table_functions/current_setting.h b/src/include/function/table_functions/current_setting.h new file mode 100644 index 0000000000..d8f16f8b6e --- /dev/null +++ b/src/include/function/table_functions/current_setting.h @@ -0,0 +1,21 @@ +#pragma once + +#include "function/table_functions.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +namespace kuzu { +namespace function { +struct CurrentSettingFunction { + inline static std::unique_ptr getDefinitions() { + return std::make_unique("current_setting", tableFunc, bindFunc); + } + + static void tableFunc(std::pair morsel, + TableFuncBindData* bindData, std::vector outputVectors); + + static std::unique_ptr bindFunc( + main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/function/table_functions/db_version.h b/src/include/function/table_functions/db_version.h new file mode 100644 index 0000000000..971b0699d2 --- /dev/null +++ b/src/include/function/table_functions/db_version.h @@ -0,0 +1,21 @@ +#pragma once + +#include "function/table_functions.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +namespace kuzu { +namespace function { +struct DBVersionFunction { + inline static std::unique_ptr getDefinitions() { + return std::make_unique("db_version", tableFunc, bindFunc); + } + + static void tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors); + + static std::unique_ptr bindFunc( + main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/function/table_functions/show_tables.h b/src/include/function/table_functions/show_tables.h new file mode 100644 index 0000000000..bfa641d606 --- /dev/null +++ b/src/include/function/table_functions/show_tables.h @@ -0,0 +1,21 @@ +#pragma once + +#include "function/table_functions.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +namespace kuzu { +namespace function { +struct ShowTablesFunction { + inline static std::unique_ptr getDefinitions() { + return std::make_unique("show_tables", tableFunc, bindFunc); + } + + static void tableFunc(std::pair morsel, + function::TableFuncBindData* bindData, std::vector outputVectors); + + static std::unique_ptr bindFunc( + main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/function/table_functions/table_info.h b/src/include/function/table_functions/table_info.h new file mode 100644 index 0000000000..9fd6605505 --- /dev/null +++ b/src/include/function/table_functions/table_info.h @@ -0,0 +1,21 @@ +#pragma once + +#include "function/table_functions.h" +#include "function/table_functions/bind_data.h" +#include "function/table_functions/bind_input.h" + +namespace kuzu { +namespace function { +struct TableInfoFunction { + inline static std::unique_ptr getDefinitions() { + return std::make_unique("table_info", tableFunc, bindFunc); + } + + static void tableFunc(std::pair morsel, + TableFuncBindData* bindData, std::vector outputVectors); + + static std::unique_ptr bindFunc( + main::ClientContext* context, TableFuncBindInput input, catalog::CatalogContent* catalog); +}; +} // namespace function +} // namespace kuzu diff --git a/src/include/planner/operator/logical_in_query_call.h b/src/include/planner/operator/logical_in_query_call.h index 46451d05cb..3796de3fa4 100644 --- a/src/include/planner/operator/logical_in_query_call.h +++ b/src/include/planner/operator/logical_in_query_call.h @@ -1,6 +1,7 @@ #pragma once #include "function/table_functions.h" +#include "function/table_functions/bind_data.h" #include "planner/operator/logical_operator.h" namespace kuzu { diff --git a/src/include/processor/operator/call/in_query_call.h b/src/include/processor/operator/call/in_query_call.h index be1dc65b8e..5deafed38d 100644 --- a/src/include/processor/operator/call/in_query_call.h +++ b/src/include/processor/operator/call/in_query_call.h @@ -2,6 +2,7 @@ #include "catalog/catalog.h" #include "function/table_functions.h" +#include "function/table_functions/bind_data.h" #include "processor/operator/physical_operator.h" namespace kuzu {