37 switch (ext_arg_column_type) {
59 switch (ext_arg_array_type) {
82 const std::vector<ExtArgumentType>& sig_types,
106 auto stype = sig_types[sig_pos];
107 int max_pos = sig_types.size() - 1;
111 penalty_score += 1000;
118 penalty_score += 1000;
121 penalty_score += 2000;
124 penalty_score += 4000;
127 penalty_score += 8000;
130 penalty_score += 1008000;
139 penalty_score += 1000;
142 penalty_score += 2000;
145 penalty_score += 4000;
148 penalty_score += 1004000;
157 penalty_score += 1000;
160 penalty_score += 2000;
163 penalty_score += 1002000;
172 penalty_score += 1000;
175 penalty_score += 1001000;
184 penalty_score += 1000;
187 penalty_score += 2000;
195 penalty_score += 1000;
206 penalty_score += 1000;
210 penalty_score += 1000;
220 penalty_score += 1000;
228 penalty_score += 1000;
231 penalty_score += 1000;
243 penalty_score += 1000;
246 penalty_score += 1000;
259 penalty_score += 1000;
262 penalty_score += 1000;
269 penalty_score += 1000;
273 penalty_score += 1000;
283 penalty_score += 1000;
293 penalty_score += 1000;
296 penalty_score += 1000;
307 penalty_score += 1000;
313 penalty_score += 1000;
334 throw std::runtime_error(std::string(__FILE__) +
"#" +
std::to_string(__LINE__) +
349 if (!(std::isalpha(str[0]) || str[0] ==
'_')) {
353 for (
size_t i = 1; i < str.size(); i++) {
354 if (!(std::isalnum(str[i]) || str[i] ==
'_')) {
364 template <
typename T>
367 const std::vector<T>& ext_funcs,
368 const std::string processor) {
402 "Cannot bind function with invalid UDF/UDTF function name: " + name);
405 int minimal_score = std::numeric_limits<int>::max();
409 std::vector<SQLTypeInfo> type_infos;
410 for (
auto atype : func_args) {
411 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
412 if (dynamic_cast<const Analyzer::ColumnVar*>(atype.get())) {
415 type_infos.push_back(ti);
419 type_infos.push_back(atype->get_type_info());
422 for (
auto ext_func : ext_funcs) {
424 auto ext_func_args = ext_func.getInputArgs();
428 if (func_args.size() <= ext_func_args.size()) {
431 int penalty_score = 0;
433 for (
auto ti : type_infos) {
445 if (penalty_score < minimal_score) {
447 minimal_score = penalty_score;
458 if (!ext_funcs.size()) {
459 message =
"Function " + name +
"(" + sarg_types +
") not supported.";
462 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
463 message =
"Could not bind " + name +
"(" + sarg_types +
") to any " + processor +
464 " UDTF implementation.";
465 }
else if constexpr (std::is_same_v<T, ExtensionFunction>) {
466 message =
"Could not bind " + name +
"(" + sarg_types +
") to any " + processor +
467 " UDF implementation.";
469 LOG(
FATAL) <<
"bind_function: unknown extension function type "
472 message +=
"\n Existing extension function implementations:";
473 for (
const auto& ext_func : ext_funcs) {
474 message +=
"\n " + ext_func.toStringSQL();
479 return ext_funcs[optimal];
485 const std::vector<table_functions::TableFunction>& table_funcs,
487 std::string processor = (is_gpu ?
"GPU" :
"CPU");
488 return bind_function<table_functions::TableFunction>(
489 name, input_args, table_funcs, processor);
497 std::string processor =
"GPU";
499 if (!ext_funcs.size()) {
505 return bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor);
509 processor =
"GPU|CPU";
511 return bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor);
522 std::vector<ExtensionFunction> ext_funcs =
524 std::string processor = (is_gpu ?
"GPU" :
"CPU");
525 return bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor);
533 for (
size_t i = 0; i < function_oper->
getArity(); ++i) {
534 func_args.push_back(function_oper->
getOwnArg(i));
544 std::vector<table_functions::TableFunction> table_funcs =
550 switch (ext_arg_type) {
566 switch (ext_arg_type) {
582 switch (ext_arg_type) {
595 switch (ext_arg_type) {
611 switch (ext_arg_type) {
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name, const bool is_gpu)
ExtArgumentType get_array_arg_elem_type(const ExtArgumentType ext_arg_array_type)
bool is_ext_arg_type_geo(const ExtArgumentType ext_arg_type)
HOST DEVICE SQLTypes get_type() const
int get_logical_size() const
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
ExtArgumentType get_column_arg_elem_type(const ExtArgumentType ext_arg_column_type)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
const table_functions::TableFunction bind_table_function(std::string name, Analyzer::ExpressionPtrVector input_args, const std::vector< table_functions::TableFunction > &table_funcs, const bool is_gpu)
HOST DEVICE EncodingType get_compression() const
bool is_ext_arg_type_scalar(const ExtArgumentType ext_arg_type)
std::string get_type_name() const
T bind_function(std::string name, Analyzer::ExpressionPtrVector func_args, const std::vector< T > &ext_funcs, const std::string processor)
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
static std::vector< TableFunction > get_table_funcs(const std::string &name, const bool is_gpu)
std::vector< ExpressionPtr > ExpressionPtrVector
static int match_arguments(const SQLTypeInfo &arg_type, int sig_pos, const std::vector< ExtArgumentType > &sig_types, int &penalty_score)
bool is_valid_identifier(std::string str)
std::string getName() const
SQLTypeInfo get_elem_type() const
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)
bool is_ext_arg_type_column(const ExtArgumentType ext_arg_type)
bool is_ext_arg_type_pointer(const ExtArgumentType ext_arg_type)