forked from alibaba/AliSQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_set.cpp
More file actions
92 lines (77 loc) · 3.12 KB
/
function_set.cpp
File metadata and controls
92 lines (77 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "duckdb/function/function_set.hpp"
#include "duckdb/function/function_binder.hpp"
namespace duckdb {
ScalarFunctionSet::ScalarFunctionSet() : FunctionSet("") {
}
ScalarFunctionSet::ScalarFunctionSet(string name) : FunctionSet(std::move(name)) {
}
ScalarFunctionSet::ScalarFunctionSet(ScalarFunction fun) : FunctionSet(std::move(fun.name)) {
functions.push_back(std::move(fun));
}
ScalarFunction ScalarFunctionSet::GetFunctionByArguments(ClientContext &context, const vector<LogicalType> &arguments) {
ErrorData error;
FunctionBinder binder(context);
auto index = binder.BindFunction(name, *this, arguments, error);
if (!index.IsValid()) {
throw InternalException("Failed to find function %s(%s)\n%s", name, StringUtil::ToString(arguments, ","),
error.Message());
}
return GetFunctionByOffset(index.GetIndex());
}
AggregateFunctionSet::AggregateFunctionSet() : FunctionSet("") {
}
AggregateFunctionSet::AggregateFunctionSet(string name) : FunctionSet(std::move(name)) {
}
AggregateFunctionSet::AggregateFunctionSet(AggregateFunction fun) : FunctionSet(std::move(fun.name)) {
functions.push_back(std::move(fun));
}
AggregateFunction AggregateFunctionSet::GetFunctionByArguments(ClientContext &context,
const vector<LogicalType> &arguments) {
ErrorData error;
FunctionBinder binder(context);
auto index = binder.BindFunction(name, *this, arguments, error);
if (!index.IsValid()) {
// check if the arguments are a prefix of any of the arguments
// this is used for functions such as quantile or string_agg that delete part of their arguments during bind
// FIXME: we should come up with a better solution here
for (auto &func : functions) {
if (arguments.size() >= func.arguments.size()) {
continue;
}
bool is_prefix = true;
for (idx_t k = 0; k < arguments.size(); k++) {
if (arguments[k].id() != func.arguments[k].id()) {
is_prefix = false;
break;
}
}
if (is_prefix) {
return func;
}
}
throw InternalException("Failed to find function %s(%s)\n%s", name, StringUtil::ToString(arguments, ","),
error.Message());
}
return GetFunctionByOffset(index.GetIndex());
}
TableFunctionSet::TableFunctionSet(string name) : FunctionSet(std::move(name)) {
}
TableFunctionSet::TableFunctionSet(TableFunction fun) : FunctionSet(std::move(fun.name)) {
functions.push_back(std::move(fun));
}
TableFunction TableFunctionSet::GetFunctionByArguments(ClientContext &context, const vector<LogicalType> &arguments) {
ErrorData error;
FunctionBinder binder(context);
auto index = binder.BindFunction(name, *this, arguments, error);
if (!index.IsValid()) {
throw InternalException("Failed to find function %s(%s)\n%s", name, StringUtil::ToString(arguments, ","),
error.Message());
}
return GetFunctionByOffset(index.GetIndex());
}
PragmaFunctionSet::PragmaFunctionSet(string name) : FunctionSet(std::move(name)) {
}
PragmaFunctionSet::PragmaFunctionSet(PragmaFunction fun) : FunctionSet(std::move(fun.name)) {
functions.push_back(std::move(fun));
}
} // namespace duckdb