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: splitup table_functions.h #2142

Merged
merged 1 commit into from
Oct 4, 2023
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
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
4 changes: 4 additions & 0 deletions src/function/built_in_table_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
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)
47 changes: 47 additions & 0 deletions src/function/table_functions/current_setting.cpp
Original file line number Diff line number Diff line change
@@ -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<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 function
} // namespace kuzu
31 changes: 31 additions & 0 deletions src/function/table_functions/db_version.cpp
Original file line number Diff line number Diff line change
@@ -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<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 function
} // namespace kuzu
59 changes: 59 additions & 0 deletions src/function/table_functions/show_tables.cpp
Original file line number Diff line number Diff line change
@@ -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<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 function
} // namespace kuzu
Loading
Loading