Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit c14b6d4

Browse files
authored
Refactor scalar function constructor (#4666)
* Refactor scalar function constructor --------- Co-authored-by: CI Bot <[email protected]>
1 parent 3e87d45 commit c14b6d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+335
-239
lines changed

extension/json/src/functions/creation_functions/json_array.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
4242
function_set JsonArrayFunction::getFunctionSet() {
4343
function_set result;
4444
auto function = std::make_unique<ScalarFunction>(name,
45-
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc);
45+
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
46+
function->bindFunc = bindFunc;
4647
function->isVarLength = true;
4748
result.push_back(std::move(function));
4849
return result;

extension/json/src/functions/creation_functions/json_merge_patch.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
3939

4040
function_set JsonMergePatchFunction::getFunctionSet() {
4141
function_set result;
42-
result.push_back(std::make_unique<ScalarFunction>(name,
42+
auto func = std::make_unique<ScalarFunction>(name,
4343
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING},
44-
LogicalTypeID::STRING, execFunc, bindFunc));
44+
LogicalTypeID::STRING, execFunc);
45+
func->bindFunc = bindFunc;
46+
result.push_back(std::move(func));
4547
return result;
4648
}
4749

extension/json/src/functions/creation_functions/json_object.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
5454
function_set JsonObjectFunction::getFunctionSet() {
5555
function_set result;
5656
auto function = std::make_unique<ScalarFunction>(name,
57-
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc);
57+
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
58+
function->bindFunc = bindFunc;
5859
function->isVarLength = true;
5960
result.push_back(std::move(function));
6061
return result;

extension/json/src/functions/creation_functions/to_json.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
3636

3737
function_set ToJsonFunction::getFunctionSet() {
3838
function_set result;
39-
result.push_back(std::make_unique<ScalarFunction>(name,
40-
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc, bindFunc));
39+
auto func = std::make_unique<ScalarFunction>(name,
40+
std::vector<LogicalTypeID>{LogicalTypeID::ANY}, LogicalTypeID::STRING, execFunc);
41+
func->bindFunc = bindFunc;
42+
result.push_back(std::move(func));
4143
return result;
4244
}
4345

extension/json/src/functions/extract_functions/json_extract.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,22 @@ static std::unique_ptr<FunctionBindData> bindJsonExtractMultiPath(ScalarBindFunc
8989

9090
function_set JsonExtractFunction::getFunctionSet() {
9191
function_set result;
92-
result.push_back(std::make_unique<ScalarFunction>(name,
92+
std::unique_ptr<ScalarFunction> func;
93+
func = std::make_unique<ScalarFunction>(name,
9394
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::STRING},
94-
LogicalTypeID::STRING, jsonExtractSinglePath, bindJsonExtractSinglePath));
95-
result.push_back(std::make_unique<ScalarFunction>(name,
95+
LogicalTypeID::STRING, jsonExtractSinglePath);
96+
func->bindFunc = bindJsonExtractSinglePath;
97+
result.push_back(std::move(func));
98+
func = std::make_unique<ScalarFunction>(name,
9699
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::INT64},
97-
LogicalTypeID::STRING, jsonExtractSinglePath, bindJsonExtractSinglePath));
98-
result.push_back(std::make_unique<ScalarFunction>(name,
100+
LogicalTypeID::STRING, jsonExtractSinglePath);
101+
func->bindFunc = bindJsonExtractSinglePath;
102+
result.push_back(std::move(func));
103+
func = std::make_unique<ScalarFunction>(name,
99104
std::vector<LogicalTypeID>{LogicalTypeID::STRING, LogicalTypeID::LIST}, LogicalTypeID::LIST,
100-
jsonExtractMultiPath, bindJsonExtractMultiPath));
105+
jsonExtractMultiPath);
106+
func->bindFunc = bindJsonExtractMultiPath;
107+
result.push_back(std::move(func));
101108
return result;
102109
}
103110

extension/json/src/functions/scalar_functions/json_keys.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
5050

5151
function_set JsonKeysFunction::getFunctionSet() {
5252
function_set result;
53-
result.push_back(
54-
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING},
55-
LogicalTypeID::LIST, execFunc, bindFunc));
53+
auto func = std::make_unique<ScalarFunction>(name,
54+
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::LIST, execFunc);
55+
func->bindFunc = bindFunc;
56+
result.push_back(std::move(func));
5657
return result;
5758
}
5859

extension/json/src/functions/scalar_functions/json_minify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ static std::unique_ptr<FunctionBindData> bindFunc(ScalarBindFuncInput input) {
3838

3939
function_set MinifyJsonFunction::getFunctionSet() {
4040
function_set result;
41-
result.push_back(
42-
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::STRING},
43-
LogicalTypeID::STRING, execFunc, bindFunc));
41+
auto func = std::make_unique<ScalarFunction>(name,
42+
std::vector<LogicalTypeID>{LogicalTypeID::STRING}, LogicalTypeID::STRING, execFunc);
43+
func->bindFunc = bindFunc;
44+
result.push_back(std::move(func));
4445
return result;
4546
}
4647

src/function/array/array_functions.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ std::unique_ptr<FunctionBindData> ArrayCrossProductBindFunc(ScalarBindFuncInput
7373

7474
function_set ArrayCrossProductFunction::getFunctionSet() {
7575
function_set result;
76-
result.push_back(std::make_unique<ScalarFunction>(name,
76+
auto func = std::make_unique<ScalarFunction>(name,
7777
std::vector<LogicalTypeID>{
7878
LogicalTypeID::ARRAY,
7979
LogicalTypeID::ARRAY,
8080
},
81-
LogicalTypeID::ARRAY, nullptr, nullptr, ArrayCrossProductBindFunc));
81+
LogicalTypeID::ARRAY);
82+
func->bindFunc = ArrayCrossProductBindFunc;
83+
result.push_back(std::move(func));
8284
return result;
8385
}
8486

@@ -166,13 +168,15 @@ std::unique_ptr<FunctionBindData> arrayTemplateBindFunc(std::string functionName
166168
template<typename OPERATION>
167169
function_set templateGetFunctionSet(const std::string& functionName) {
168170
function_set result;
169-
result.push_back(std::make_unique<ScalarFunction>(functionName,
171+
auto function = std::make_unique<ScalarFunction>(functionName,
170172
std::vector<LogicalTypeID>{
171173
LogicalTypeID::ARRAY,
172174
LogicalTypeID::ARRAY,
173175
},
174-
LogicalTypeID::ANY, nullptr, nullptr,
175-
std::bind(arrayTemplateBindFunc<OPERATION>, functionName, std::placeholders::_1)));
176+
LogicalTypeID::ANY);
177+
function->bindFunc =
178+
std::bind(arrayTemplateBindFunc<OPERATION>, functionName, std::placeholders::_1);
179+
result.push_back(std::move(function));
176180
return result;
177181
}
178182

src/function/array/array_value.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ function_set ArrayValueFunction::getFunctionSet() {
2727
function_set result;
2828
auto function =
2929
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::ANY},
30-
LogicalTypeID::ARRAY, ListCreationFunction::execFunc, nullptr, bindFunc);
30+
LogicalTypeID::ARRAY, ListCreationFunction::execFunc);
31+
function->bindFunc = bindFunc;
3132
function->isVarLength = true;
3233
result.push_back(std::move(function));
3334
return result;

src/function/list/list_agg_function.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ struct ListSum {
4242

4343
function_set ListSumFunction::getFunctionSet() {
4444
function_set result;
45-
result.push_back(
46-
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::LIST},
47-
LogicalTypeID::INT64, bindFuncListAggr<ListSum>));
45+
auto function = std::make_unique<ScalarFunction>(name,
46+
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::INT64);
47+
function->bindFunc = bindFuncListAggr<ListSum>;
48+
result.push_back(std::move(function));
4849
return result;
4950
}
5051

@@ -65,9 +66,10 @@ struct ListProduct {
6566

6667
function_set ListProductFunction::getFunctionSet() {
6768
function_set result;
68-
result.push_back(
69-
std::make_unique<ScalarFunction>(name, std::vector<LogicalTypeID>{LogicalTypeID::LIST},
70-
LogicalTypeID::INT64, bindFuncListAggr<ListProduct>));
69+
auto function = std::make_unique<ScalarFunction>(name,
70+
std::vector<LogicalTypeID>{LogicalTypeID::LIST}, LogicalTypeID::INT64);
71+
function->bindFunc = bindFuncListAggr<ListProduct>;
72+
result.push_back(std::move(function));
7173
return result;
7274
}
7375

0 commit comments

Comments
 (0)