19 #include <boost/algorithm/string/join.hpp>
29 const std::string&
name) {
37 const std::string&
name) {
46 const std::string&
name,
48 std::vector<ExtensionFunction> ext_funcs = {};
51 for (
auto funcs : collections) {
52 const auto it = funcs->find(uname);
53 if (it == funcs->end()) {
56 auto ext_func_sigs = it->second;
57 std::copy_if(ext_func_sigs.begin(),
59 std::back_inserter(ext_funcs),
60 [is_gpu](
auto sig) {
return (is_gpu ? sig.isGPU() : sig.isCPU()); });
66 const std::string&
name,
68 std::vector<ExtensionFunction> ext_funcs = {};
71 for (
auto funcs : collections) {
72 const auto it = funcs->find(uname);
73 if (it == funcs->end()) {
76 auto ext_func_sigs = it->second;
77 std::copy_if(ext_func_sigs.begin(),
79 std::back_inserter(ext_funcs),
80 [arity](
auto sig) {
return arity == sig.getArgs().size(); });
86 const std::string&
name,
89 std::vector<ExtensionFunction> ext_funcs = {};
92 for (
auto funcs : collections) {
93 const auto it = funcs->find(uname);
94 if (it == funcs->end()) {
97 auto ext_func_sigs = it->second;
98 std::copy_if(ext_func_sigs.begin(),
100 std::back_inserter(ext_funcs),
101 [arity, rtype](
auto sig) {
108 if (arity > sig.getArgs().size()) {
124 bool declare =
false) {
157 return (declare ?
"{i8*, i64, i8}*" :
"Array<i8>");
159 return (declare ?
"{i16*, i64, i8}*" :
"Array<i16>");
161 return (declare ?
"{i32*, i64, i8}*" :
"Array<i32>");
163 return (declare ?
"{i64*, i64, i8}*" :
"Array<i64>");
165 return (declare ?
"{float*, i64, i8}*" :
"Array<float>");
167 return (declare ?
"{double*, i64, i8}*" :
"Array<double>");
169 return (declare ?
"{i1*, i64, i8}*" :
"Array<i1>");
173 return "geo_linestring";
175 return "geo_polygon";
177 return "geo_multi_polygon";
181 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"Column<i8>");
183 return (declare ? (byval ?
"{i16*, i64}" :
"i8*") :
"Column<i16>");
185 return (declare ? (byval ?
"{i32*, i64}" :
"i8*") :
"Column<i32>");
187 return (declare ? (byval ?
"{i64*, i64}" :
"i8*") :
"Column<i64>");
189 return (declare ? (byval ?
"{float*, i64}" :
"i8*") :
"Column<float>");
191 return (declare ? (byval ?
"{double*, i64}" :
"i8*") :
"Column<double>");
193 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"Column<bool>");
195 return (declare ? (byval ?
"{i32*, i64}" :
"i8*") :
"Column<TextEncodingDict>");
197 return (declare ? (byval ?
"{i64*, i64}" :
"i8*") :
"Column<timestamp>");
199 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"TextEncodingNone");
201 return (declare ?
"{i8*, i32}*" :
"TextEncodingDict");
203 return (declare ?
"{ i64 }" :
"timestamp");
205 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i8>");
207 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i16>");
209 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i32>");
211 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i64>");
213 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<float>");
215 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<double>");
217 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<bool>");
219 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<TextEncodingDict>");
228 const auto idx = str.find(
"__");
229 if (idx == std::string::npos) {
232 CHECK_GT(idx, std::string::size_type(0));
233 return str.substr(0, idx);
243 switch (ext_arg_type) {
314 <<
"` cannot be converted to SQLTypeInfo.";
320 const std::vector<ExtensionFunction>& ext_funcs,
323 for (
auto sig : ext_funcs) {
324 r += tab + sig.toString() +
"\n";
330 const std::vector<SQLTypeInfo>& arg_types) {
332 for (
auto sig = arg_types.begin(); sig != arg_types.end();) {
333 r += sig->get_type_name();
335 if (sig != arg_types.end()) {
343 const std::vector<ExtArgumentType>& sig_types) {
345 for (
auto t = sig_types.begin(); t != sig_types.end();) {
348 if (t != sig_types.end()) {
356 const std::vector<ExtArgumentType>& sig_types) {
358 for (
auto t = sig_types.begin(); t != sig_types.end();) {
361 if (t != sig_types.end()) {
403 return "ARRAY<TINYINT>";
405 return "ARRAY<SMALLINT>";
409 return "ARRAY<BIGINT>";
411 return "ARRAY<FLOAT>";
413 return "ARRAY<DOUBLE>";
415 return "ARRAY<BOOLEAN>";
417 return "COLUMN<TINYINT>";
419 return "COLUMN<SMALLINT>";
421 return "COLUMN<INT>";
423 return "COLUMN<BIGINT>";
425 return "COLUMN<FLOAT>";
427 return "COLUMN<DOUBLE>";
429 return "COLUMN<BOOLEAN>";
431 return "COLUMN<TEXT ENCODING DICT>";
433 return "COLUMN<TIMESTAMP(9)>";
443 return "MULTIPOLYGON";
447 return "TEXT ENCODING NONE";
449 return "TEXT ENCODING DICT";
451 return "TIMESTAMP(9)";
453 return "COLUMNLIST<TINYINT>";
455 return "COLUMNLIST<SMALLINT>";
457 return "COLUMNLIST<INT>";
459 return "COLUMNLIST<BIGINT>";
461 return "COLUMNLIST<FLOAT>";
463 return "COLUMNLIST<DOUBLE>";
465 return "COLUMNLIST<BOOLEAN>";
467 return "COLUMNLIST<TEXT ENCODING DICT>";
491 const std::unordered_set<std::string>& udf_decls,
493 std::vector<std::string> declarations;
495 const auto& signatures = kv.second;
496 CHECK(!signatures.empty());
497 for (
const auto& signature : kv.second) {
500 if (!udf_decls.empty() && udf_decls.find(signature.getName()) != udf_decls.end()) {
504 std::string decl_prefix;
505 std::vector<std::string> arg_strs;
508 decl_prefix =
"declare void @" + signature.getName();
509 arg_strs.emplace_back(
515 " @" + signature.getName();
517 for (
const auto arg : signature.getArgs()) {
526 if (kv.second.isRuntime() || kv.second.useDefaultSizer()) {
531 if (!((is_gpu && kv.second.isGPU()) || (!is_gpu && kv.second.isCPU()))) {
534 std::string decl_prefix{
538 std::vector<std::string> arg_strs;
539 for (
const auto arg : kv.second.getArgs(
true)) {
552 if (type_name ==
"bool" || type_name ==
"i1") {
555 if (type_name ==
"i8") {
558 if (type_name ==
"i16") {
561 if (type_name ==
"i32") {
564 if (type_name ==
"i64") {
567 if (type_name ==
"float") {
570 if (type_name ==
"double") {
573 if (type_name ==
"void") {
576 if (type_name ==
"i8*") {
579 if (type_name ==
"i16*") {
582 if (type_name ==
"i32*") {
585 if (type_name ==
"i64*") {
588 if (type_name ==
"float*") {
591 if (type_name ==
"double*") {
594 if (type_name ==
"i1*" || type_name ==
"bool*") {
597 if (type_name ==
"Array<i8>") {
600 if (type_name ==
"Array<i16>") {
603 if (type_name ==
"Array<i32>") {
606 if (type_name ==
"Array<i64>") {
609 if (type_name ==
"Array<float>") {
612 if (type_name ==
"Array<double>") {
615 if (type_name ==
"Array<bool>" || type_name ==
"Array<i1>") {
618 if (type_name ==
"geo_point") {
621 if (type_name ==
"geo_linestring") {
624 if (type_name ==
"geo_polygon") {
627 if (type_name ==
"geo_multi_polygon") {
630 if (type_name ==
"cursor") {
633 if (type_name ==
"Column<i8>") {
636 if (type_name ==
"Column<i16>") {
639 if (type_name ==
"Column<i32>") {
642 if (type_name ==
"Column<i64>") {
645 if (type_name ==
"Column<float>") {
648 if (type_name ==
"Column<double>") {
651 if (type_name ==
"Column<bool>") {
654 if (type_name ==
"Column<TextEncodingDict>") {
657 if (type_name ==
"Column<timestamp>") {
660 if (type_name ==
"TextEncodingNone") {
663 if (type_name ==
"TextEncodingDict") {
666 if (type_name ==
"timestamp") {
669 if (type_name ==
"ColumnList<i8>") {
672 if (type_name ==
"ColumnList<i16>") {
675 if (type_name ==
"ColumnList<i32>") {
678 if (type_name ==
"ColumnList<i64>") {
681 if (type_name ==
"ColumnList<float>") {
684 if (type_name ==
"ColumnList<double>") {
687 if (type_name ==
"ColumnList<bool>") {
690 if (type_name ==
"ColumnList<TextEncodingDict>") {
699 using SignatureMap = std::unordered_map<std::string, std::vector<ExtensionFunction>>;
702 const std::string& json_func_sigs) {
703 rapidjson::Document func_sigs;
704 func_sigs.Parse(json_func_sigs.c_str());
705 CHECK(func_sigs.IsArray());
706 for (
auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
708 CHECK(func_sigs_it->IsObject());
711 std::vector<ExtArgumentType>
args;
712 const auto& args_serialized =
field(*func_sigs_it,
"args");
713 CHECK(args_serialized.IsArray());
714 for (
auto args_serialized_it = args_serialized.Begin();
715 args_serialized_it != args_serialized.End();
716 ++args_serialized_it) {
744 if (!json_func_sigs.empty()) {
754 if (!json_func_sigs.empty()) {
759 std::unordered_map<std::string, std::vector<ExtensionFunction>>
762 std::unordered_map<std::string, std::vector<ExtensionFunction>>
765 std::unordered_map<std::string, std::vector<ExtensionFunction>>
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name, const bool is_gpu)
static void addUdfs(const std::string &json_func_sigs)
std::string drop_suffix(const std::string &str)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::vector< ExtensionFunction > * get(const std::string &name)
static void clearRTUdfs()
auto generate_column_type(const SQLTypes subtype)
const std::string json_str(const rapidjson::Value &obj) noexcept
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
const std::vector< ExtArgumentType > args_
static void add(const std::string &json_func_sigs)
std::unordered_map< std::string, std::vector< ExtensionFunction >> SignatureMap
const std::string getName(bool keep_suffix=true) const
HOST DEVICE SQLTypes get_type() const
std::string toStringSQL() const
std::string toString() const
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
static std::vector< ExtensionFunction > * get_udf(const std::string &name)
ExtArgumentType deserialize_type(const std::string &type_name)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
std::string toString(const Executor::ExtModuleKinds &kind)
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)
auto generate_array_type(const SQLTypes subtype)
std::string serialize_type(const ExtArgumentType type, bool byval=true, bool declare=false)
const ExtArgumentType ret_
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
static std::unordered_map< std::string, TableFunction > functions_
constexpr auto type_name() noexcept
static std::vector< std::string > getLLVMDeclarations(const std::unordered_set< std::string > &udf_decls, const bool is_gpu=false)
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)
static std::string toStringSQL(const std::vector< ExtArgumentType > &sig_types)
static void addRTUdfs(const std::string &json_func_sigs)