Skip to content

Commit

Permalink
Merge pull request #1769 from kuzudb/issue-1732
Browse files Browse the repository at this point in the history
solve issue-1732
  • Loading branch information
acquamarin committed Jul 6, 2023
2 parents 0b5b617 + 6d480d5 commit 7bbea12
Show file tree
Hide file tree
Showing 163 changed files with 3,357 additions and 3,556 deletions.
2 changes: 1 addition & 1 deletion src/binder/bind/bind_reading_clause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::unique_ptr<BoundReadingClause> Binder::bindUnwindClause(const ReadingClause
std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause& readingClause) {
auto& callStatement = reinterpret_cast<const parser::InQueryCall&>(readingClause);
auto tableFunctionDefinition =
catalog.getBuiltInTableOperation()->mathTableOperation(callStatement.getFuncName());
catalog.getBuiltInTableFunction()->mathTableFunction(callStatement.getFuncName());
auto boundExpr = expressionBinder.bindLiteralExpression(*callStatement.getParameter());
auto inputValue = reinterpret_cast<LiteralExpression*>(boundExpr.get())->getValue();
auto bindData = tableFunctionDefinition->bindFunc(clientContext,
Expand Down
7 changes: 3 additions & 4 deletions src/binder/bind_expression/bind_boolean_expression.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "binder/expression/function_expression.h"
#include "binder/expression_binder.h"
#include "function/boolean/vector_boolean_operations.h"
#include "function/boolean/vector_boolean_functions.h"

using namespace kuzu::common;
using namespace kuzu::parser;
Expand All @@ -25,10 +25,9 @@ std::shared_ptr<Expression> ExpressionBinder::bindBooleanExpression(
}
auto functionName = expressionTypeToString(expressionType);
function::scalar_exec_func execFunc;
function::VectorBooleanOperations::bindExecFunction(
expressionType, childrenAfterCast, execFunc);
function::VectorBooleanFunction::bindExecFunction(expressionType, childrenAfterCast, execFunc);
function::scalar_select_func selectFunc;
function::VectorBooleanOperations::bindSelectFunction(
function::VectorBooleanFunction::bindSelectFunction(
expressionType, childrenAfterCast, selectFunc);
auto bindData = std::make_unique<function::FunctionBindData>(LogicalType(LogicalTypeID::BOOL));
auto uniqueExpressionName =
Expand Down
4 changes: 2 additions & 2 deletions src/binder/bind_expression/bind_comparison_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(

std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(
common::ExpressionType expressionType, const expression_vector& children) {
auto builtInFunctions = binder->catalog.getBuiltInVectorOperation();
auto builtInFunctions = binder->catalog.getBuiltInVectorFunctions();
auto functionName = expressionTypeToString(expressionType);
std::vector<common::LogicalType> childrenTypes;
for (auto& child : children) {
childrenTypes.push_back(child->dataType);
}
auto function = builtInFunctions->matchVectorOperation(functionName, childrenTypes);
auto function = builtInFunctions->matchVectorFunction(functionName, childrenTypes);
expression_vector childrenAfterCast;
for (auto i = 0u; i < children.size(); ++i) {
childrenAfterCast.push_back(
Expand Down
8 changes: 4 additions & 4 deletions src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "binder/expression/literal_expression.h"
#include "binder/expression_binder.h"
#include "common/string_utils.h"
#include "function/schema/vector_label_operations.h"
#include "function/schema/vector_label_functions.h"
#include "parser/expression/parsed_function_expression.h"

using namespace kuzu::common;
Expand Down Expand Up @@ -43,12 +43,12 @@ std::shared_ptr<Expression> ExpressionBinder::bindScalarFunctionExpression(

std::shared_ptr<Expression> ExpressionBinder::bindScalarFunctionExpression(
const expression_vector& children, const std::string& functionName) {
auto builtInFunctions = binder->catalog.getBuiltInVectorOperation();
auto builtInFunctions = binder->catalog.getBuiltInVectorFunctions();
std::vector<LogicalType> childrenTypes;
for (auto& child : children) {
childrenTypes.push_back(child->dataType);
}
auto function = builtInFunctions->matchVectorOperation(functionName, childrenTypes);
auto function = builtInFunctions->matchVectorFunction(functionName, childrenTypes);
if (builtInFunctions->canApplyStaticEvaluation(functionName, children)) {
return staticEvaluate(functionName, children);
}
Expand Down Expand Up @@ -230,7 +230,7 @@ std::shared_ptr<Expression> ExpressionBinder::bindLabelFunction(const Expression
default:
throw NotImplementedException("ExpressionBinder::bindLabelFunction");
}
auto execFunc = function::LabelVectorOperation::execFunction;
auto execFunc = function::LabelVectorFunction::execFunction;
auto bindData =
std::make_unique<function::FunctionBindData>(LogicalType(LogicalTypeID::STRING));
auto uniqueExpressionName = ScalarFunctionExpression::getUniqueName(LABEL_FUNC_NAME, children);
Expand Down
6 changes: 3 additions & 3 deletions src/binder/bind_expression/bind_null_operator_expression.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "binder/expression/function_expression.h"
#include "binder/expression_binder.h"
#include "function/null/vector_null_operations.h"
#include "function/null/vector_null_functions.h"

using namespace kuzu::parser;

Expand All @@ -16,9 +16,9 @@ std::shared_ptr<Expression> ExpressionBinder::bindNullOperatorExpression(
auto expressionType = parsedExpression.getExpressionType();
auto functionName = expressionTypeToString(expressionType);
function::scalar_exec_func execFunc;
function::VectorNullOperations::bindExecFunction(expressionType, children, execFunc);
function::VectorNullFunction::bindExecFunction(expressionType, children, execFunc);
function::scalar_select_func selectFunc;
function::VectorNullOperations::bindSelectFunction(expressionType, children, selectFunc);
function::VectorNullFunction::bindSelectFunction(expressionType, children, selectFunc);
auto bindData = std::make_unique<function::FunctionBindData>(
common::LogicalType(common::LogicalTypeID::BOOL));
auto uniqueExpressionName = ScalarFunctionExpression::getUniqueName(functionName, children);
Expand Down
8 changes: 4 additions & 4 deletions src/binder/expression_binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "binder/expression/function_expression.h"
#include "binder/expression/literal_expression.h"
#include "binder/expression/parameter_expression.h"
#include "function/cast/vector_cast_operations.h"
#include "function/cast/vector_cast_functions.h"

using namespace kuzu::common;
using namespace kuzu::function;
Expand Down Expand Up @@ -83,12 +83,12 @@ std::shared_ptr<Expression> ExpressionBinder::implicitCastIfNecessary(

std::shared_ptr<Expression> ExpressionBinder::implicitCast(
const std::shared_ptr<Expression>& expression, const common::LogicalType& targetType) {
if (VectorCastOperations::hasImplicitCast(expression->dataType, targetType)) {
auto functionName = VectorCastOperations::bindImplicitCastFuncName(targetType);
if (VectorCastFunction::hasImplicitCast(expression->dataType, targetType)) {
auto functionName = VectorCastFunction::bindImplicitCastFuncName(targetType);
auto children = expression_vector{expression};
auto bindData = std::make_unique<FunctionBindData>(targetType);
function::scalar_exec_func execFunc;
VectorCastOperations::bindImplicitCastFunc(
VectorCastFunction::bindImplicitCastFunc(
expression->dataType.getLogicalTypeID(), targetType.getLogicalTypeID(), execFunc);
auto uniqueName = ScalarFunctionExpression::getUniqueName(functionName, children);
return std::make_shared<ScalarFunctionExpression>(functionName, FUNCTION,
Expand Down
10 changes: 5 additions & 5 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,16 @@ void CatalogContent::writeMagicBytes(FileInfo* fileInfo, offset_t& offset) const

Catalog::Catalog() : wal{nullptr} {
catalogContentForReadOnlyTrx = std::make_unique<CatalogContent>();
builtInVectorOperations = std::make_unique<function::BuiltInVectorOperations>();
builtInVectorFunctions = std::make_unique<function::BuiltInVectorFunctions>();
builtInAggregateFunctions = std::make_unique<function::BuiltInAggregateFunctions>();
builtInTableOperations = std::make_unique<function::BuiltInTableOperations>();
builtInTableFunctions = std::make_unique<function::BuiltInTableFunctions>();
}

Catalog::Catalog(WAL* wal) : wal{wal} {
catalogContentForReadOnlyTrx = std::make_unique<CatalogContent>(wal->getDirectory());
builtInVectorOperations = std::make_unique<function::BuiltInVectorOperations>();
builtInVectorFunctions = std::make_unique<function::BuiltInVectorFunctions>();
builtInAggregateFunctions = std::make_unique<function::BuiltInAggregateFunctions>();
builtInTableOperations = std::make_unique<function::BuiltInTableOperations>();
builtInTableFunctions = std::make_unique<function::BuiltInTableFunctions>();
}

void Catalog::prepareCommitOrRollback(TransactionAction action) {
Expand All @@ -390,7 +390,7 @@ void Catalog::checkpointInMemory() {
}

ExpressionType Catalog::getFunctionType(const std::string& name) const {
if (builtInVectorOperations->containsFunction(name)) {
if (builtInVectorFunctions->containsFunction(name)) {
return FUNCTION;
} else if (builtInAggregateFunctions->containsFunction(name)) {
return AGGREGATE_FUNCTION;
Expand Down
6 changes: 3 additions & 3 deletions src/expression_evaluator/node_rel_evaluator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "expression_evaluator/node_rel_evaluator.h"

#include "function/struct/vector_struct_operations.h"
#include "function/struct/vector_struct_functions.h"

using namespace kuzu::common;
using namespace kuzu::function;
Expand All @@ -12,7 +12,7 @@ void NodeRelExpressionEvaluator::evaluate() {
for (auto& child : children) {
child->evaluate();
}
StructPackVectorOperations::execFunc(parameters, *resultVector);
StructPackVectorFunctions::execFunc(parameters, *resultVector);
}

void NodeRelExpressionEvaluator::resolveResultVector(
Expand All @@ -25,7 +25,7 @@ void NodeRelExpressionEvaluator::resolveResultVector(
inputEvaluators.push_back(child.get());
}
resolveResultStateFromChildren(inputEvaluators);
StructPackVectorOperations::compileFunc(nullptr, parameters, resultVector);
StructPackVectorFunctions::compileFunc(nullptr, parameters, resultVector);
}

} // namespace evaluator
Expand Down
39 changes: 19 additions & 20 deletions src/function/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
add_subdirectory(comparison)

add_library(kuzu_function
OBJECT
aggregate_function.cpp
base_lower_upper_operation.cpp
built_in_aggregate_functions.cpp
built_in_vector_operations.cpp
built_in_table_operations.cpp
find_operation.cpp
table_operations.cpp
vector_arithmetic_operations.cpp
vector_boolean_operations.cpp
vector_cast_operations.cpp
vector_date_operations.cpp
vector_hash_operations.cpp
vector_list_operation.cpp
vector_null_operations.cpp
vector_node_rel_operations.cpp
vector_string_operations.cpp
vector_timestamp_operations.cpp
vector_struct_operations.cpp
vector_map_operation.cpp
vector_union_operations.cpp
vector_blob_operations.cpp)
built_in_vector_functions.cpp
built_in_table_functions.cpp
comparison_functions.cpp
find_function.cpp
table_functions.cpp
vector_arithmetic_functions.cpp
vector_boolean_functions.cpp
vector_cast_functions.cpp
vector_date_functions.cpp
vector_hash_functions.cpp
vector_list_functions.cpp
vector_null_functions.cpp
vector_node_rel_functions.cpp
vector_string_functions.cpp
vector_timestamp_functions.cpp
vector_struct_functions.cpp
vector_map_functions.cpp
vector_union_functions.cpp
vector_blob_functions.cpp)

set(ALL_OBJECT_FILES
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:kuzu_function>
Expand Down
4 changes: 2 additions & 2 deletions src/function/aggregate_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getSumFunction(

std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getMinFunction(
const LogicalType& inputType, bool isDistinct) {
return getMinMaxFunction<operation::LessThan>(inputType, isDistinct);
return getMinMaxFunction<LessThan>(inputType, isDistinct);
}

std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getMaxFunction(
const LogicalType& inputType, bool isDistinct) {
return getMinMaxFunction<operation::GreaterThan>(inputType, isDistinct);
return getMinMaxFunction<GreaterThan>(inputType, isDistinct);
}

std::unique_ptr<AggregateFunction> AggregateFunctionUtil::getCollectFunction(
Expand Down
8 changes: 3 additions & 5 deletions src/function/base_lower_upper_operation.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "function/string/operations/base_lower_upper_operation.h"
#include "function/string/functions/base_lower_upper_function.h"

using namespace kuzu::utf8proc;

namespace kuzu {
namespace function {
namespace operation {

uint32_t BaseLowerUpperOperation::getResultLen(char* inputStr, uint32_t inputLen, bool isUpper) {
uint32_t BaseLowerUpperFunction::getResultLen(char* inputStr, uint32_t inputLen, bool isUpper) {
uint32_t outputLength = 0;
for (uint32_t i = 0; i < inputLen;) {
// For UTF-8 characters, changing case can increase / decrease total byte length.
Expand All @@ -28,7 +27,7 @@ uint32_t BaseLowerUpperOperation::getResultLen(char* inputStr, uint32_t inputLen
return outputLength;
}

void BaseLowerUpperOperation::convertCase(char* result, uint32_t len, char* input, bool toUpper) {
void BaseLowerUpperFunction::convertCase(char* result, uint32_t len, char* input, bool toUpper) {
for (auto i = 0u; i < len;) {
if (input[i] & 0x80) {
int size = 0, newSize = 0;
Expand All @@ -47,6 +46,5 @@ void BaseLowerUpperOperation::convertCase(char* result, uint32_t len, char* inpu
}
}

} // namespace operation
} // namespace function
} // namespace kuzu
27 changes: 27 additions & 0 deletions src/function/built_in_table_functions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "function/built_in_table_functions.h"

#include "common/expression_type.h"
#include "common/string_utils.h"

namespace kuzu {
namespace function {

void BuiltInTableFunctions::registerTableFunctions() {
tableFunctions.insert({common::TABLE_INFO_FUNC_NAME, TableInfoFunction::getDefinitions()});
tableFunctions.insert({common::DB_VERSION_FUNC_NAME, DBVersionFunction::getDefinitions()});
tableFunctions.insert(
{common::CURRENT_SETTING_FUNC_NAME, CurrentSettingFunction::getDefinitions()});
}

TableFunctionDefinition* BuiltInTableFunctions::mathTableFunction(const std::string& name) {
auto upperName = name;
common::StringUtils::toUpper(upperName);
if (!tableFunctions.contains(upperName)) {
throw common::BinderException{
"Cannot match a built-in function for given function " + name + "."};
}
return tableFunctions.at(upperName).get();
}

} // namespace function
} // namespace kuzu
27 changes: 0 additions & 27 deletions src/function/built_in_table_operations.cpp

This file was deleted.

Loading

0 comments on commit 7bbea12

Please sign in to comment.