Skip to content

Commit

Permalink
refactor: splitup table_functions.h
Browse files Browse the repository at this point in the history
  • Loading branch information
Riolku committed Oct 4, 2023
1 parent 851b567 commit 0f6f2be
Show file tree
Hide file tree
Showing 23 changed files with 355 additions and 260 deletions.
1 change: 1 addition & 0 deletions src/binder/bind/bind_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion src/catalog/catalog_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using namespace kuzu::binder;
using namespace kuzu::common;
using namespace kuzu::storage;
using namespace kuzu::transaction;

namespace kuzu {
namespace catalog {
Expand Down
2 changes: 1 addition & 1 deletion src/function/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(aggregate)
add_subdirectory(table_functions)

add_library(kuzu_function
OBJECT
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/function/built_in_table_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
#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;

namespace kuzu {
namespace function {
namespace kuzu::function {

void BuiltInTableFunctions::registerTableFunctions() {
tableFunctions.insert({TABLE_INFO_FUNC_NAME, TableInfoFunction::getDefinitions()});
Expand All @@ -25,5 +28,4 @@ TableFunctionDefinition* BuiltInTableFunctions::mathTableFunction(const std::str
return tableFunctions.at(upperName).get();
}

} // namespace function
} // namespace kuzu
} // namespace kuzu::function
130 changes: 0 additions & 130 deletions src/function/table_functions.cpp

This file was deleted.

10 changes: 10 additions & 0 deletions src/function/table_functions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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} $<TARGET_OBJECTS:kuzu_function_table_functions>
PARENT_SCOPE)
45 changes: 45 additions & 0 deletions src/function/table_functions/current_setting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#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::function {
struct CurrentSettingBindData : public TableFuncBindData {
std::string result;

CurrentSettingBindData(std::string result, std::vector<common::LogicalType> returnTypes,
std::vector<std::string> returnColumnNames, common::offset_t maxOffset)
: result{std::move(result)}, TableFuncBindData{std::move(returnTypes),
std::move(returnColumnNames), maxOffset} {}

std::unique_ptr<TableFuncBindData> copy() override {
return std::make_unique<CurrentSettingBindData>(
result, returnTypes, returnColumnNames, maxOffset);
}
};

void CurrentSettingFunction::tableFunc(std::pair<offset_t, offset_t> morsel,
function::TableFuncBindData* bindData, std::vector<ValueVector*> outputVectors) {
auto currentSettingBindData = reinterpret_cast<CurrentSettingBindData*>(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<TableFuncBindData> CurrentSettingFunction::bindFunc(main::ClientContext* context,
kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) {
auto optionName = input.inputs[0].getValue<std::string>();
std::vector<std::string> returnColumnNames;
std::vector<LogicalType> returnTypes;
returnColumnNames.emplace_back(optionName);
returnTypes.emplace_back(LogicalTypeID::STRING);
return std::make_unique<CurrentSettingBindData>(context->getCurrentSetting(optionName),
std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */);
}
} // namespace kuzu::function
29 changes: 29 additions & 0 deletions src/function/table_functions/db_version.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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::function {
void DBVersionFunction::tableFunc(std::pair<offset_t, offset_t> morsel,
function::TableFuncBindData* bindData, std::vector<ValueVector*> 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<TableFuncBindData> DBVersionFunction::bindFunc(main::ClientContext* context,
kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) {
std::vector<std::string> returnColumnNames;
std::vector<LogicalType> returnTypes;
returnColumnNames.emplace_back("version");
returnTypes.emplace_back(LogicalTypeID::STRING);
return std::make_unique<TableFuncBindData>(
std::move(returnTypes), std::move(returnColumnNames), 1 /* one row result */);
}

} // namespace kuzu::function
57 changes: 57 additions & 0 deletions src/function/table_functions/show_tables.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#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::function {

struct ShowTablesBindData : public TableFuncBindData {
std::vector<catalog::TableSchema*> tables;

ShowTablesBindData(std::vector<catalog::TableSchema*> tables,
std::vector<common::LogicalType> returnTypes, std::vector<std::string> returnColumnNames,
common::offset_t maxOffset)
: tables{std::move(tables)}, TableFuncBindData{std::move(returnTypes),
std::move(returnColumnNames), maxOffset} {}

inline std::unique_ptr<TableFuncBindData> copy() override {
return std::make_unique<ShowTablesBindData>(
tables, returnTypes, returnColumnNames, maxOffset);
}
};

void ShowTablesFunction::tableFunc(std::pair<offset_t, offset_t> morsel,
function::TableFuncBindData* bindData, std::vector<ValueVector*> outputVectors) {
auto tables = reinterpret_cast<function::ShowTablesBindData*>(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<TableFuncBindData> ShowTablesFunction::bindFunc(main::ClientContext* context,
kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) {
std::vector<std::string> returnColumnNames;
std::vector<LogicalType> 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<ShowTablesBindData>(catalog->getTableSchemas(), std::move(returnTypes),
std::move(returnColumnNames), catalog->getTableCount());
}

} // namespace kuzu::function
Loading

0 comments on commit 0f6f2be

Please sign in to comment.