37 switch (ext_arg_column_type) {
60 switch (ext_arg_column_list_type) {
82 switch (ext_arg_array_type) {
105 const std::vector<ExtArgumentType>& sig_types,
106 int& penalty_score) {
129 int max_pos = sig_types.size() - 1;
130 if (sig_pos > max_pos) {
133 auto stype = sig_types[sig_pos];
137 penalty_score += 1000;
144 penalty_score += 1000;
147 penalty_score += 2000;
150 penalty_score += 4000;
153 penalty_score += 8000;
156 penalty_score += 1008000;
165 penalty_score += 1000;
168 penalty_score += 2000;
171 penalty_score += 4000;
174 penalty_score += 1004000;
183 penalty_score += 1000;
186 penalty_score += 2000;
189 penalty_score += 1002000;
198 penalty_score += 1000;
201 penalty_score += 1001000;
210 penalty_score += 1000;
213 penalty_score += 2000;
221 penalty_score += 1000;
232 penalty_score += 1000;
236 penalty_score += 1000;
246 penalty_score += 1000;
254 penalty_score += 1000;
257 penalty_score += 1000;
269 penalty_score += 1000;
272 penalty_score += 1000;
285 penalty_score += 1000;
288 penalty_score += 1000;
295 penalty_score += 1000;
299 penalty_score += 1000;
309 penalty_score += 1000;
319 penalty_score += 1000;
322 penalty_score += 1000;
332 const auto stype_ti =
336 penalty_score += 10000;
339 penalty_score += 10000;
350 penalty_score += 1000;
356 penalty_score += 1000;
377 throw std::runtime_error(std::string(__FILE__) +
"#" +
std::to_string(__LINE__) +
392 if (!(std::isalpha(str[0]) || str[0] ==
'_')) {
396 for (
size_t i = 1;
i < str.size();
i++) {
397 if (!(std::isalnum(str[
i]) || str[i] ==
'_')) {
407 template <
typename T>
411 const std::vector<T>& ext_funcs,
412 const std::string processor) {
445 "Cannot bind function with invalid UDF/UDTF function name: " + name);
448 int minimal_score = std::numeric_limits<int>::max();
451 int optimal_variant = -1;
453 std::vector<SQLTypeInfo> type_infos_input;
454 for (
auto atype : func_args) {
455 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
456 if (dynamic_cast<const Analyzer::ColumnVar*>(atype.get())) {
458 type_infos_input.push_back(ti);
462 type_infos_input.push_back(atype->get_type_info());
509 std::vector<std::vector<SQLTypeInfo>> type_infos_variants;
510 for (
auto ti : type_infos_input) {
511 if (type_infos_variants.begin() == type_infos_variants.end()) {
512 type_infos_variants.push_back({ti});
513 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
514 if (ti.is_column()) {
516 mti.set_dimension(1);
517 type_infos_variants.push_back({mti});
522 std::vector<std::vector<SQLTypeInfo>> new_type_infos_variants;
523 for (
auto& type_infos : type_infos_variants) {
524 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
525 if (ti.is_column()) {
526 auto new_type_infos = type_infos;
527 const auto& last = type_infos.back();
528 if (last.is_column_list() && last.get_subtype() == ti.get_subtype()) {
530 new_type_infos.back().set_dimension(last.get_dimension() + 1);
534 mti.set_dimension(1);
535 new_type_infos.push_back(mti);
537 new_type_infos_variants.push_back(new_type_infos);
540 type_infos.push_back(ti);
542 type_infos_variants.insert(type_infos_variants.end(),
543 new_type_infos_variants.begin(),
544 new_type_infos_variants.end());
548 for (
auto ext_func : ext_funcs) {
550 auto ext_func_args = ext_func.getInputArgs();
551 int index_variant = -1;
552 for (
const auto& type_infos : type_infos_variants) {
554 int penalty_score = 0;
556 for (
const auto& ti : type_infos) {
566 if ((
size_t)pos == ext_func_args.size()) {
569 if (penalty_score < minimal_score) {
571 minimal_score = penalty_score;
572 optimal_variant = index_variant;
583 if (!ext_funcs.size()) {
584 message =
"Function " + name +
"(" + sarg_types +
") not supported.";
587 if constexpr (std::is_same_v<T, table_functions::TableFunction>) {
588 message =
"Could not bind " + name +
"(" + sarg_types +
") to any " + processor +
589 " UDTF implementation.";
590 }
else if constexpr (std::is_same_v<T, ExtensionFunction>) {
591 message =
"Could not bind " + name +
"(" + sarg_types +
") to any " + processor +
592 " UDF implementation.";
594 LOG(
FATAL) <<
"bind_function: unknown extension function type "
597 message +=
"\n Existing extension function implementations:";
598 for (
const auto& ext_func : ext_funcs) {
599 message +=
"\n " + ext_func.toStringSQL();
604 return {ext_funcs[optimal], type_infos_variants[optimal_variant]};
607 const std::tuple<table_functions::TableFunction, std::vector<SQLTypeInfo>>
610 const std::vector<table_functions::TableFunction>& table_funcs,
612 std::string processor = (is_gpu ?
"GPU" :
"CPU");
613 return bind_function<table_functions::TableFunction>(
614 name, input_args, table_funcs, processor);
622 std::string processor =
"GPU";
624 if (!ext_funcs.size()) {
631 bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor));
635 processor =
"GPU|CPU";
638 bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor));
649 std::vector<ExtensionFunction> ext_funcs =
651 std::string processor = (is_gpu ?
"GPU" :
"CPU");
653 bind_function<ExtensionFunction>(
name, func_args, ext_funcs, processor));
661 for (
size_t i = 0;
i < function_oper->
getArity(); ++
i) {
662 func_args.push_back(function_oper->
getOwnArg(
i));
667 const std::tuple<table_functions::TableFunction, std::vector<SQLTypeInfo>>
672 std::vector<table_functions::TableFunction> table_funcs =
678 switch (ext_arg_type) {
694 switch (ext_arg_type) {
710 switch (ext_arg_type) {
726 switch (ext_arg_type) {
739 switch (ext_arg_type) {
755 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_column_list(const ExtArgumentType ext_arg_type)
bool is_ext_arg_type_geo(const ExtArgumentType ext_arg_type)
auto generate_column_type(const SQLTypes subtype)
ExtArgumentType get_column_list_arg_elem_type(const ExtArgumentType ext_arg_column_list_type)
HOST DEVICE SQLTypes get_type() const
int get_logical_size() const
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
auto generate_column_list_type(const SQLTypes subtype)
ExtArgumentType get_column_arg_elem_type(const ExtArgumentType ext_arg_column_type)
std::tuple< T, std::vector< SQLTypeInfo > > bind_function(std::string name, Analyzer::ExpressionPtrVector func_args, const std::vector< T > &ext_funcs, const std::string processor)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
HOST DEVICE EncodingType get_compression() const
bool is_ext_arg_type_scalar(const ExtArgumentType ext_arg_type)
std::string get_type_name() const
const std::tuple< table_functions::TableFunction, std::vector< SQLTypeInfo > > bind_table_function(std::string name, Analyzer::ExpressionPtrVector input_args, const std::vector< table_functions::TableFunction > &table_funcs, const bool is_gpu)
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)