Skip to content

Commit

Permalink
Refactor scalar function constructor (#4666)
Browse files Browse the repository at this point in the history
* Refactor scalar function constructor

---------

Co-authored-by: CI Bot <[email protected]>
  • Loading branch information
andyfengHKU and andyfengHKU authored Dec 27, 2024
1 parent 3e87d45 commit c14b6d4
Show file tree
Hide file tree
Showing 58 changed files with 335 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
function_set JsonArrayFunction::getFunctionSet() {
function_set result;
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc);
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
function->bindFunc = bindFunc;
function->isVarLength = true;
result.push_back(std::move(function));
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set JsonMergePatchFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING},
LogicalTypeID::STRING, execFunc, bindFunc));
LogicalTypeID::STRING, execFunc);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
function_set JsonObjectFunction::getFunctionSet() {
function_set result;
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc);
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
function->bindFunc = bindFunc;
function->isVarLength = true;
result.push_back(std::move(function));
return result;
Expand Down
6 changes: 4 additions & 2 deletions extension/json/src/functions/creation_functions/to_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ToJsonFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc));
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
19 changes: 13 additions & 6 deletions extension/json/src/functions/extract_functions/json_extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@ static std::unique_ptr<FunctionBindData> bindJsonExtractMultiPath(ScalarBindFunc

function_set JsonExtractFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::unique_ptr<ScalarFunction> func;
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING},
LogicalTypeID::STRING, jsonExtractSinglePath, bindJsonExtractSinglePath));
result.push_back(std::make_unique<ScalarFunction>(name,
LogicalTypeID::STRING, jsonExtractSinglePath);
func->bindFunc = bindJsonExtractSinglePath;
result.push_back(std::move(func));
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::INT64},
LogicalTypeID::STRING, jsonExtractSinglePath, bindJsonExtractSinglePath));
result.push_back(std::make_unique<ScalarFunction>(name,
LogicalTypeID::STRING, jsonExtractSinglePath);
func->bindFunc = bindJsonExtractSinglePath;
result.push_back(std::move(func));
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::LIST}, LogicalTypeID::LIST,
jsonExtractMultiPath, bindJsonExtractMultiPath));
jsonExtractMultiPath);
func->bindFunc = bindJsonExtractMultiPath;
result.push_back(std::move(func));
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions extension/json/src/functions/scalar_functions/json_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set JsonKeysFunction::getFunctionSet() {
function_set result;
result.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING},
LogicalTypeID::LIST, execFunc, bindFunc));
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::LIST, execFunc);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions extension/json/src/functions/scalar_functions/json_minify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set MinifyJsonFunction::getFunctionSet() {
function_set result;
result.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING},
LogicalTypeID::STRING, execFunc, bindFunc));
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING, execFunc);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
14 changes: 9 additions & 5 deletions src/function/array/array_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ std::unique_ptr<FunctionBindData> ArrayCrossProductBindFunc(ScalarBindFuncInput

function_set ArrayCrossProductFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{
LogicalTypeID::ARRAY,
LogicalTypeID::ARRAY,
},
LogicalTypeID::ARRAY, nullptr, nullptr, ArrayCrossProductBindFunc));
LogicalTypeID::ARRAY);
func->bindFunc = ArrayCrossProductBindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down Expand Up @@ -166,13 +168,15 @@ std::unique_ptr<FunctionBindData> arrayTemplateBindFunc(std::string functionName
template<typename OPERATION>
function_set templateGetFunctionSet(const std::string& functionName) {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(functionName,
auto function = std::make_unique<ScalarFunction>(functionName,
std::vector<LogicalTypeID>{
LogicalTypeID::ARRAY,
LogicalTypeID::ARRAY,
},
LogicalTypeID::ANY, nullptr, nullptr,
std::bind(arrayTemplateBindFunc<OPERATION>, functionName, std::placeholders::_1)));
LogicalTypeID::ANY);
function->bindFunc =
std::bind(arrayTemplateBindFunc<OPERATION>, functionName, std::placeholders::_1);
result.push_back(std::move(function));
return result;
}

Expand Down
3 changes: 2 additions & 1 deletion src/function/array/array_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function_set ArrayValueFunction::getFunctionSet() {
function_set result;
auto function =
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::ANY},
LogicalTypeID::ARRAY, ListCreationFunction::execFunc, nullptr, bindFunc);
LogicalTypeID::ARRAY, ListCreationFunction::execFunc);
function->bindFunc = bindFunc;
function->isVarLength = true;
result.push_back(std::move(function));
return result;
Expand Down
14 changes: 8 additions & 6 deletions src/function/list/list_agg_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ struct ListSum {

function_set ListSumFunction::getFunctionSet() {
function_set result;
result.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::LIST},
LogicalTypeID::INT64, bindFuncListAggr<ListSum>));
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::INT64);
function->bindFunc = bindFuncListAggr<ListSum>;
result.push_back(std::move(function));
return result;
}

Expand All @@ -65,9 +66,10 @@ struct ListProduct {

function_set ListProductFunction::getFunctionSet() {
function_set result;
result.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::LIST},
LogicalTypeID::INT64, bindFuncListAggr<ListProduct>));
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::INT64);
function->bindFunc = bindFuncListAggr<ListProduct>;
result.push_back(std::move(function));
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/function/list/list_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function_set ListAllFunction::getFunctionSet() {
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::BOOL,
std::bind(execQuantifierFunc, allHandler, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
bindQuantifierFunc);
std::placeholders::_3));
function->bindFunc = bindQuantifierFunc;
function->isListLambda = true;
result.push_back(std::move(function));
return result;
Expand Down
4 changes: 2 additions & 2 deletions src/function/list/list_any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function_set ListAnyFunction::getFunctionSet() {
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::BOOL,
std::bind(execQuantifierFunc, anyHandler, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
bindQuantifierFunc);
std::placeholders::_3));
function->bindFunc = bindQuantifierFunc;
function->isListLambda = true;
result.push_back(std::move(function));
return result;
Expand Down
7 changes: 4 additions & 3 deletions src/function/list/list_any_value_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListAnyValueFunction::getFunctionSet() {
function_set result;
result.push_back(
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::LIST},
LogicalTypeID::ANY, nullptr, nullptr, bindFunc));
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::ANY);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions src/function/list/list_append_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListAppendFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::LIST,
nullptr /* execFunc */, nullptr /* selectFunc */, bindFunc));
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::LIST);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}

Expand Down
6 changes: 4 additions & 2 deletions src/function/list/list_concat_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ function_set ListConcatFunction::getFunctionSet() {
function_set result;
auto execFunc = ScalarFunction::BinaryExecListStructFunction<list_entry_t, list_entry_t,
list_entry_t, ListConcat>;
result.push_back(std::make_unique<ScalarFunction>(name,
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::LIST}, LogicalTypeID::LIST,
execFunc, nullptr, bindFunc));
execFunc);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions src/function/list/list_contains_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListContainsFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::BOOL,
nullptr, nullptr, bindFunc));
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::BOOL);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}

Expand Down
6 changes: 3 additions & 3 deletions src/function/list/list_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListCreationFunction::getFunctionSet() {
function_set result;
auto function =
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::ANY},
LogicalTypeID::LIST, execFunc, nullptr, bindFunc);
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::LIST, execFunc);
function->bindFunc = bindFunc;
function->isVarLength = true;
result.push_back(std::move(function));
return result;
Expand Down
7 changes: 4 additions & 3 deletions src/function/list/list_distinct_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListDistinctFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::LIST,
ScalarFunction::UnaryExecNestedTypeFunction<list_entry_t, list_entry_t, ListDistinct>,
nullptr, bindFunc));
ScalarFunction::UnaryExecNestedTypeFunction<list_entry_t, list_entry_t, ListDistinct>);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}

Expand Down
20 changes: 12 additions & 8 deletions src/function/list/list_extract_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ static std::unique_ptr<FunctionBindData> ListExtractBindFunc(ScalarBindFuncInput

function_set ListExtractFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::INT64}, LogicalTypeID::ANY,
nullptr, nullptr, ListExtractBindFunc));
result.push_back(std::make_unique<ScalarFunction>(name,
std::unique_ptr<ScalarFunction> func;
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::INT64}, LogicalTypeID::ANY);
func->bindFunc = ListExtractBindFunc;
result.push_back(std::move(func));
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::INT64},
LogicalTypeID::STRING,
ScalarFunction::BinaryExecFunction<ku_string_t, int64_t, ku_string_t, ListExtract>));
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ARRAY, LogicalTypeID::INT64}, LogicalTypeID::ANY,
nullptr, nullptr, ListExtractBindFunc));
ScalarFunction::BinaryExecFunction<ku_string_t, int64_t, ku_string_t, ListExtract>);
result.push_back(std::move(func));
func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::ARRAY, LogicalTypeID::INT64}, LogicalTypeID::ANY);
func->bindFunc = ListExtractBindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
3 changes: 2 additions & 1 deletion src/function/list/list_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function_set ListFilterFunction::getFunctionSet() {
function_set result;
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::LIST,
execFunc, bindFunc);
execFunc);
function->bindFunc = bindFunc;
function->isListLambda = true;
result.push_back(std::move(function));
return result;
Expand Down
3 changes: 2 additions & 1 deletion src/function/list/list_has_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function_set ListHasAllFunction::getFunctionSet() {
uint8_t, ListHasAll>;
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::LIST}, LogicalTypeID::BOOL,
execFunc, bindFunc);
execFunc);
function->bindFunc = bindFunc;
result.push_back(std::move(function));
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/function/list/list_none.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function_set ListNoneFunction::getFunctionSet() {
auto function = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::BOOL,
std::bind(execQuantifierFunc, noneHandler, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
bindQuantifierFunc);
std::placeholders::_3));
function->bindFunc = bindQuantifierFunc;
function->isListLambda = true;
result.push_back(std::move(function));
return result;
Expand Down
9 changes: 5 additions & 4 deletions src/function/list/list_position_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace kuzu::common;
namespace kuzu {
namespace function {

static std::unique_ptr<FunctionBindData> ListPositionBindFunc(ScalarBindFuncInput input) {
static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
auto scalarFunction = input.definition->ptrCast<ScalarFunction>();
TypeUtils::visit(input.arguments[1]->getDataType().getPhysicalType(),
[&scalarFunction]<typename T>(T) {
Expand All @@ -21,9 +21,10 @@ static std::unique_ptr<FunctionBindData> ListPositionBindFunc(ScalarBindFuncInpu

function_set ListPositionFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::INT64,
ListPositionBindFunc));
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::INT64);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
7 changes: 4 additions & 3 deletions src/function/list/list_prepend_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {

function_set ListPrependFunction::getFunctionSet() {
function_set result;
result.push_back(std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::LIST,
bindFunc));
auto func = std::make_unique<ScalarFunction>(name,
std::vector<LogicalTypeID>{LogicalTypeID::LIST, LogicalTypeID::ANY}, LogicalTypeID::LIST);
func->bindFunc = bindFunc;
result.push_back(std::move(func));
return result;
}

Expand Down
Loading

0 comments on commit c14b6d4

Please sign in to comment.