19 #include <boost/algorithm/string/join.hpp>
29 const std::string&
name) {
38 const std::string&
name) {
48 const bool is_runtime) {
49 std::unordered_set<std::string> names;
51 for (
auto funcs : collections) {
52 for (
auto& pair : *funcs) {
55 names.insert(udf.
getName(
false));
63 const std::string&
name) {
64 std::vector<ExtensionFunction> ext_funcs = {};
67 for (
auto funcs : collections) {
68 const auto it = funcs->find(uname);
69 if (it == funcs->end()) {
72 auto ext_func_sigs = it->second;
73 std::copy(ext_func_sigs.begin(), ext_func_sigs.end(), std::back_inserter(ext_funcs));
79 const std::string&
name,
81 std::vector<ExtensionFunction> ext_funcs = {};
84 for (
auto funcs : collections) {
85 const auto it = funcs->find(uname);
86 if (it == funcs->end()) {
89 auto ext_func_sigs = it->second;
90 std::copy_if(ext_func_sigs.begin(),
92 std::back_inserter(ext_funcs),
93 [is_gpu](
auto sig) {
return (is_gpu ? sig.isGPU() : sig.isCPU()); });
99 const std::string&
name,
101 std::vector<ExtensionFunction> ext_funcs = {};
104 for (
auto funcs : collections) {
105 const auto it = funcs->find(uname);
106 if (it == funcs->end()) {
109 auto ext_func_sigs = it->second;
110 std::copy_if(ext_func_sigs.begin(),
112 std::back_inserter(ext_funcs),
113 [arity](
auto sig) {
return arity == sig.getInputArgs().size(); });
119 const std::string&
name,
122 std::vector<ExtensionFunction> ext_funcs = {};
125 for (
auto funcs : collections) {
126 const auto it = funcs->find(uname);
127 if (it == funcs->end()) {
130 auto ext_func_sigs = it->second;
131 std::copy_if(ext_func_sigs.begin(),
133 std::back_inserter(ext_funcs),
134 [arity, rtype](
auto sig) {
141 if (arity > sig.getInputArgs().size()) {
157 bool declare =
false) {
190 return (declare ?
"{i8*, i64, i8}*" :
"Array<i8>");
192 return (declare ?
"{i16*, i64, i8}*" :
"Array<i16>");
194 return (declare ?
"{i32*, i64, i8}*" :
"Array<i32>");
196 return (declare ?
"{i64*, i64, i8}*" :
"Array<i64>");
198 return (declare ?
"{float*, i64, i8}*" :
"Array<float>");
200 return (declare ?
"{double*, i64, i8}*" :
"Array<double>");
202 return (declare ?
"{i1*, i64, i8}*" :
"Array<i1>");
204 return (declare ?
"{i32*, i64, i8}*" :
"Array<TextEncodingDict>");
208 return "geo_multi_point";
210 return "geo_linestring";
212 return "geo_multi_linestring";
214 return "geo_polygon";
216 return "geo_multi_polygon";
220 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"Column<i8>");
222 return (declare ? (byval ?
"{i16*, i64}" :
"i8*") :
"Column<i16>");
224 return (declare ? (byval ?
"{i32*, i64}" :
"i8*") :
"Column<i32>");
226 return (declare ? (byval ?
"{i64*, i64}" :
"i8*") :
"Column<i64>");
228 return (declare ? (byval ?
"{float*, i64}" :
"i8*") :
"Column<float>");
230 return (declare ? (byval ?
"{double*, i64}" :
"i8*") :
"Column<double>");
232 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"Column<bool>");
234 return (declare ? (byval ?
"{i32*, i64}" :
"i8*") :
"Column<TextEncodingDict>");
236 return (declare ? (byval ?
"{i64*, i64}" :
"i8*") :
"Column<timestamp>");
238 return (declare ? (byval ?
"{i8*, i64}" :
"i8*") :
"TextEncodingNone");
240 return (declare ?
"{i8*, i32}*" :
"TextEncodingDict");
242 return (declare ?
"{ i64 }" :
"timestamp");
244 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i8>");
246 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i16>");
248 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i32>");
250 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<i64>");
252 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<float>");
254 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<double>");
256 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<bool>");
258 return (declare ?
"{i8**, i64, i64}*" :
"ColumnList<TextEncodingDict>");
260 return (declare ?
"{i8*, i64}*" :
"Column<Array<i8>>");
262 return (declare ?
"{i8*, i64}*" :
"Column<Array<i16>>");
264 return (declare ?
"{i8*, i64}*" :
"Column<Array<i32>>");
266 return (declare ?
"{i8*, i64}*" :
"Column<Array<i64>>");
268 return (declare ?
"{i8*, i64}*" :
"Column<Array<float>>");
270 return (declare ?
"{i8*, i64}*" :
"Column<Array<double>>");
272 return (declare ?
"{i8*, i64}*" :
"Column<Array<bool>>");
274 return (declare ?
"{i8*, i64}" :
"Column<Array<TextEncodingDict>>");
276 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<i8>");
278 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<i16>");
280 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<i32>");
282 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<i64>");
284 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<float>");
286 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<double>");
288 return (declare ?
"{i8**, i64, i64}*" :
"ColumnListArray<bool>");
290 return (declare ?
"{i8**, i64, i64}" :
"ColumnList<Array<TextEncodingDict>>");
299 const auto idx = str.find(
"__");
300 if (idx == std::string::npos) {
303 CHECK_GT(idx, std::string::size_type(0));
304 return str.substr(0, idx);
318 #define EXTARGTYPECASE(EXTARGTYPE, ELEMTYPE, ENCODING, ARRAYENCODING) \
319 case ExtArgumentType::EXTARGTYPE: \
321 c = kENCODING_##ENCODING; \
323 case ExtArgumentType::Array##EXTARGTYPE: \
325 c = kENCODING_##ENCODING; \
326 subtype = ELEMTYPE; \
328 case ExtArgumentType::Column##EXTARGTYPE: \
330 c = kENCODING_##ENCODING; \
331 subtype = ELEMTYPE; \
333 case ExtArgumentType::ColumnList##EXTARGTYPE: \
334 type = kCOLUMN_LIST; \
335 c = kENCODING_##ENCODING; \
336 subtype = ELEMTYPE; \
338 case ExtArgumentType::ColumnArray##EXTARGTYPE: \
340 subtype = ELEMTYPE; \
341 c = kENCODING_##ARRAYENCODING; \
343 case ExtArgumentType::ColumnListArray##EXTARGTYPE: \
344 type = kCOLUMN_LIST; \
345 subtype = ELEMTYPE; \
346 c = kENCODING_##ARRAYENCODING; \
349 switch (ext_arg_type) {
373 <<
"` cannot be converted to SQLTypes.";
380 const std::vector<ExtensionFunction>& ext_funcs,
383 for (
auto sig : ext_funcs) {
384 r += tab + sig.toString() +
"\n";
390 const std::vector<SQLTypeInfo>& arg_types) {
392 for (
auto sig = arg_types.begin(); sig != arg_types.end();) {
393 r += sig->get_type_name();
395 if (sig != arg_types.end()) {
403 const std::vector<ExtArgumentType>& sig_types) {
405 for (
auto t = sig_types.begin(); t != sig_types.end();) {
408 if (t != sig_types.end()) {
416 const std::vector<ExtArgumentType>& sig_types) {
418 for (
auto t = sig_types.begin(); t != sig_types.end();) {
421 if (t != sig_types.end()) {
463 return "ARRAY<TINYINT>";
465 return "ARRAY<SMALLINT>";
469 return "ARRAY<BIGINT>";
471 return "ARRAY<FLOAT>";
473 return "ARRAY<DOUBLE>";
475 return "ARRAY<BOOLEAN>";
477 return "ARRAY<TEXT ENCODING DICT>";
479 return "COLUMN<TINYINT>";
481 return "COLUMN<SMALLINT>";
483 return "COLUMN<INT>";
485 return "COLUMN<BIGINT>";
487 return "COLUMN<FLOAT>";
489 return "COLUMN<DOUBLE>";
491 return "COLUMN<BOOLEAN>";
493 return "COLUMN<TEXT ENCODING DICT>";
495 return "COLUMN<TIMESTAMP(9)>";
505 return "MULTILINESTRING";
509 return "MULTIPOLYGON";
513 return "TEXT ENCODING NONE";
515 return "TEXT ENCODING DICT";
517 return "TIMESTAMP(9)";
519 return "COLUMNLIST<TINYINT>";
521 return "COLUMNLIST<SMALLINT>";
523 return "COLUMNLIST<INT>";
525 return "COLUMNLIST<BIGINT>";
527 return "COLUMNLIST<FLOAT>";
529 return "COLUMNLIST<DOUBLE>";
531 return "COLUMNLIST<BOOLEAN>";
533 return "COLUMNLIST<TEXT ENCODING DICT>";
535 return "COLUMN<ARRAY<TINYINT>>";
537 return "COLUMN<ARRAY<SMALLINT>>";
539 return "COLUMN<ARRAY<INT>>";
541 return "COLUMN<ARRAY<BIGINT>>";
543 return "COLUMN<ARRAY<FLOAT>>";
545 return "COLUMN<ARRAY<DOUBLE>>";
547 return "COLUMN<ARRAY<BOOLEAN>>";
549 return "COLUMN<ARRAY<TEXT ENCODING DICT>>";
551 return "COLUMNLIST<ARRAY<TINYINT>>";
553 return "COLUMNLIST<ARRAY<SMALLINT>>";
555 return "COLUMNLIST<ARRAY<INT>>";
557 return "COLUMNLIST<ARRAY<BIGINT>>";
559 return "COLUMNLIST<ARRAY<FLOAT>>";
561 return "COLUMNLIST<ARRAY<DOUBLE>>";
563 return "COLUMNLIST<ARRAY<BOOLEAN>>";
565 return "COLUMNLIST<ARRAY<TEXT ENCODING DICT>>";
594 const std::unordered_set<std::string>& udf_decls,
596 std::vector<std::string> declarations;
598 const auto& signatures = kv.second;
599 CHECK(!signatures.empty());
600 for (
const auto& signature : kv.second) {
603 if (!udf_decls.empty() && udf_decls.find(signature.getName()) != udf_decls.end()) {
607 std::string decl_prefix;
608 std::vector<std::string> arg_strs;
611 decl_prefix =
"declare void @" + signature.getName();
612 arg_strs.emplace_back(
618 " @" + signature.getName();
620 for (
const auto arg : signature.getInputArgs()) {
629 if (kv.second.isRuntime() || kv.second.useDefaultSizer()) {
634 if (!((is_gpu && kv.second.isGPU()) || (!is_gpu && kv.second.isCPU()))) {
637 std::string decl_prefix{
641 std::vector<std::string> arg_strs;
642 for (
const auto arg : kv.second.getArgs(
true)) {
655 if (type_name ==
"bool" || type_name ==
"i1") {
658 if (type_name ==
"i8") {
661 if (type_name ==
"i16") {
664 if (type_name ==
"i32") {
667 if (type_name ==
"i64") {
670 if (type_name ==
"float") {
673 if (type_name ==
"double") {
676 if (type_name ==
"void") {
679 if (type_name ==
"i8*") {
682 if (type_name ==
"i16*") {
685 if (type_name ==
"i32*") {
688 if (type_name ==
"i64*") {
691 if (type_name ==
"float*") {
694 if (type_name ==
"double*") {
697 if (type_name ==
"i1*" || type_name ==
"bool*") {
700 if (type_name ==
"Array<i8>") {
703 if (type_name ==
"Array<i16>") {
706 if (type_name ==
"Array<i32>") {
709 if (type_name ==
"Array<i64>") {
712 if (type_name ==
"Array<float>") {
715 if (type_name ==
"Array<double>") {
718 if (type_name ==
"Array<bool>" || type_name ==
"Array<i1>") {
721 if (type_name ==
"Array<TextEncodingDict>") {
724 if (type_name ==
"geo_point") {
727 if (type_name ==
"geo_multi_point") {
730 if (type_name ==
"geo_linestring") {
733 if (type_name ==
"geo_multi_linestring") {
736 if (type_name ==
"geo_polygon") {
739 if (type_name ==
"geo_multi_polygon") {
742 if (type_name ==
"cursor") {
745 if (type_name ==
"Column<i8>") {
748 if (type_name ==
"Column<i16>") {
751 if (type_name ==
"Column<i32>") {
754 if (type_name ==
"Column<i64>") {
757 if (type_name ==
"Column<float>") {
760 if (type_name ==
"Column<double>") {
763 if (type_name ==
"Column<bool>") {
766 if (type_name ==
"Column<TextEncodingDict>") {
769 if (type_name ==
"Column<timestamp>") {
772 if (type_name ==
"TextEncodingNone") {
775 if (type_name ==
"TextEncodingDict") {
778 if (type_name ==
"timestamp") {
781 if (type_name ==
"ColumnList<i8>") {
784 if (type_name ==
"ColumnList<i16>") {
787 if (type_name ==
"ColumnList<i32>") {
790 if (type_name ==
"ColumnList<i64>") {
793 if (type_name ==
"ColumnList<float>") {
796 if (type_name ==
"ColumnList<double>") {
799 if (type_name ==
"ColumnList<bool>") {
802 if (type_name ==
"ColumnList<TextEncodingDict>") {
805 if (type_name ==
"Column<Array<i8>>") {
808 if (type_name ==
"Column<Array<i16>>") {
811 if (type_name ==
"Column<Array<i32>>") {
814 if (type_name ==
"Column<Array<i64>>") {
817 if (type_name ==
"Column<Array<float>>") {
820 if (type_name ==
"Column<Array<double>>") {
823 if (type_name ==
"Column<Array<bool>>") {
826 if (type_name ==
"Column<Array<TextEncodingDict>>") {
829 if (type_name ==
"ColumnList<Array<i8>>") {
832 if (type_name ==
"ColumnList<Array<i16>>") {
835 if (type_name ==
"ColumnList<Array<i32>>") {
838 if (type_name ==
"ColumnList<Array<i64>>") {
841 if (type_name ==
"ColumnList<Array<float>>") {
844 if (type_name ==
"ColumnList<Array<double>>") {
847 if (type_name ==
"ColumnList<Array<bool>>") {
850 if (type_name ==
"ColumnList<Array<TextEncodingDict>>") {
859 using SignatureMap = std::unordered_map<std::string, std::vector<ExtensionFunction>>;
862 const std::string& json_func_sigs,
863 const bool is_runtime) {
864 rapidjson::Document func_sigs;
865 func_sigs.Parse(json_func_sigs.c_str());
866 CHECK(func_sigs.IsArray());
867 for (
auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
869 CHECK(func_sigs_it->IsObject());
872 std::vector<ExtArgumentType>
args;
873 const auto& args_serialized =
field(*func_sigs_it,
"args");
874 CHECK(args_serialized.IsArray());
875 for (
auto args_serialized_it = args_serialized.Begin();
876 args_serialized_it != args_serialized.End();
877 ++args_serialized_it) {
905 if (!json_func_sigs.empty()) {
915 if (!json_func_sigs.empty()) {
920 std::unordered_map<std::string, std::vector<ExtensionFunction>>
923 std::unordered_map<std::string, std::vector<ExtensionFunction>>
926 std::unordered_map<std::string, std::vector<ExtensionFunction>>
static void addUdfs(const std::string &json_func_sigs)
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs, const bool is_runtime)
std::string drop_suffix(const std::string &str)
static std::vector< ExtensionFunction > get_ext_funcs(const std::string &name)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::vector< ExtensionFunction > * get(const std::string &name)
static void clearRTUdfs()
std::string toSignature() const
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
std::string toString(const QueryDescriptionType &type)
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
Supported runtime functions management and retrieval.
static std::vector< ExtensionFunction > * get_udf(const std::string &name)
#define EXTARGTYPECASE(EXTARGTYPE, ELEMTYPE, ENCODING, ARRAYENCODING)
DEVICE auto copy(ARGS &&...args)
ExtArgumentType deserialize_type(const std::string &type_name)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
static std::unordered_set< std::string > get_udfs_name(const bool is_runtime)
Checked json field retrieval.
Argument type based extension function binding.
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)