OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtensionFunctionsWhitelist Class Reference

#include <ExtensionFunctionsWhitelist.h>

Static Public Member Functions

static void add (const std::string &json_func_sigs)
 
static void addUdfs (const std::string &json_func_sigs)
 
static void clearRTUdfs ()
 
static void addRTUdfs (const std::string &json_func_sigs)
 
static std::vector
< ExtensionFunction > * 
get (const std::string &name)
 
static std::vector
< ExtensionFunction > * 
get_udf (const std::string &name)
 
static std::vector
< ExtensionFunction
get_ext_funcs (const std::string &name, const bool is_gpu)
 
static std::vector
< ExtensionFunction
get_ext_funcs (const std::string &name, size_t arity)
 
static std::vector
< ExtensionFunction
get_ext_funcs (const std::string &name, size_t arity, const SQLTypeInfo &rtype)
 
static std::string toString (const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
 
static std::string toString (const std::vector< SQLTypeInfo > &arg_types)
 
static std::string toString (const std::vector< ExtArgumentType > &sig_types)
 
static std::string toStringSQL (const std::vector< ExtArgumentType > &sig_types)
 
static std::string toString (const ExtArgumentType &sig_type)
 
static std::string toStringSQL (const ExtArgumentType &sig_type)
 
static std::vector< std::string > getLLVMDeclarations (const std::unordered_set< std::string > &udf_decls, const bool is_gpu=false)
 

Static Private Member Functions

static void addCommon (std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)
 

Static Private Attributes

static std::unordered_map
< std::string, std::vector
< ExtensionFunction > > 
functions_
 
static std::unordered_map
< std::string, std::vector
< ExtensionFunction > > 
udf_functions_
 
static std::unordered_map
< std::string, std::vector
< ExtensionFunction > > 
rt_udf_functions_
 

Detailed Description

Definition at line 115 of file ExtensionFunctionsWhitelist.h.

Member Function Documentation

void ExtensionFunctionsWhitelist::add ( const std::string &  json_func_sigs)
static

Definition at line 699 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and functions_.

Referenced by DBHandler::initialize(), and QueryRunner::QueryRunner::QueryRunner().

699  {
700  // Valid json_func_sigs example:
701  // [
702  // {
703  // "name":"sum",
704  // "ret":"i32",
705  // "args":[
706  // "i32",
707  // "i32"
708  // ]
709  // }
710  // ]
711 
712  addCommon(functions_, json_func_sigs);
713 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExtensionFunctionsWhitelist::addCommon ( std::unordered_map< std::string, std::vector< ExtensionFunction >> &  sigs,
const std::string &  json_func_sigs 
)
staticprivate

Definition at line 673 of file ExtensionFunctionsWhitelist.cpp.

References run_benchmark_import::args, CHECK, anonymous_namespace{ExtensionFunctionsWhitelist.cpp}::deserialize_type(), anonymous_namespace{ExtensionFunctionsWhitelist.cpp}::drop_suffix(), field(), json_str(), setup::name, and to_upper().

Referenced by add(), addRTUdfs(), and addUdfs().

674  {
675  rapidjson::Document func_sigs;
676  func_sigs.Parse(json_func_sigs.c_str());
677  CHECK(func_sigs.IsArray());
678  for (auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
679  ++func_sigs_it) {
680  CHECK(func_sigs_it->IsObject());
681  const auto name = json_str(field(*func_sigs_it, "name"));
682  const auto ret = deserialize_type(json_str(field(*func_sigs_it, "ret")));
683  std::vector<ExtArgumentType> args;
684  const auto& args_serialized = field(*func_sigs_it, "args");
685  CHECK(args_serialized.IsArray());
686  for (auto args_serialized_it = args_serialized.Begin();
687  args_serialized_it != args_serialized.End();
688  ++args_serialized_it) {
689  args.push_back(deserialize_type(json_str(*args_serialized_it)));
690  }
691  signatures[to_upper(drop_suffix(name))].emplace_back(name, args, ret);
692  }
693 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
string name
Definition: setup.in.py:72
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
ExtArgumentType deserialize_type(const std::string &type_name)
std::string to_upper(const std::string &str)
#define CHECK(condition)
Definition: Logger.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExtensionFunctionsWhitelist::addRTUdfs ( const std::string &  json_func_sigs)
static

Definition at line 725 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and rt_udf_functions_.

725  {
726  if (!json_func_sigs.empty()) {
727  addCommon(rt_udf_functions_, json_func_sigs);
728  }
729 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)

+ Here is the call graph for this function:

void ExtensionFunctionsWhitelist::addUdfs ( const std::string &  json_func_sigs)
static

Definition at line 715 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and udf_functions_.

Referenced by DBHandler::initialize(), and QueryRunner::QueryRunner::QueryRunner().

715  {
716  if (!json_func_sigs.empty()) {
717  addCommon(udf_functions_, json_func_sigs);
718  }
719 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static void addCommon(std::unordered_map< std::string, std::vector< ExtensionFunction >> &sigs, const std::string &json_func_sigs)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ExtensionFunctionsWhitelist::clearRTUdfs ( )
static

Definition at line 721 of file ExtensionFunctionsWhitelist.cpp.

References rt_udf_functions_.

721  {
722  rt_udf_functions_.clear();
723 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
std::vector< ExtensionFunction > * ExtensionFunctionsWhitelist::get ( const std::string &  name)
static

Definition at line 28 of file ExtensionFunctionsWhitelist.cpp.

References functions_, and to_upper().

29  {
30  const auto it = functions_.find(to_upper(name));
31  if (it == functions_.end()) {
32  return nullptr;
33  }
34  return &it->second;
35 }
string name
Definition: setup.in.py:72
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

std::vector< ExtensionFunction > ExtensionFunctionsWhitelist::get_ext_funcs ( const std::string &  name,
const bool  is_gpu 
)
static

Definition at line 45 of file ExtensionFunctionsWhitelist.cpp.

References functions_, rt_udf_functions_, to_upper(), and udf_functions_.

Referenced by bind_function().

47  {
48  std::vector<ExtensionFunction> ext_funcs = {};
49  const auto collections = {&functions_, &udf_functions_, &rt_udf_functions_};
50  const auto uname = to_upper(name);
51  for (auto funcs : collections) {
52  const auto it = funcs->find(uname);
53  if (it == funcs->end()) {
54  continue;
55  }
56  auto ext_func_sigs = it->second;
57  std::copy_if(ext_func_sigs.begin(),
58  ext_func_sigs.end(),
59  std::back_inserter(ext_funcs),
60  [is_gpu](auto sig) { return (is_gpu ? sig.isGPU() : sig.isCPU()); });
61  }
62  return ext_funcs;
63 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
string name
Definition: setup.in.py:72
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< ExtensionFunction > ExtensionFunctionsWhitelist::get_ext_funcs ( const std::string &  name,
size_t  arity 
)
static

Definition at line 65 of file ExtensionFunctionsWhitelist.cpp.

References functions_, rt_udf_functions_, to_upper(), and udf_functions_.

67  {
68  std::vector<ExtensionFunction> ext_funcs = {};
69  const auto collections = {&functions_, &udf_functions_, &rt_udf_functions_};
70  const auto uname = to_upper(name);
71  for (auto funcs : collections) {
72  const auto it = funcs->find(uname);
73  if (it == funcs->end()) {
74  continue;
75  }
76  auto ext_func_sigs = it->second;
77  std::copy_if(ext_func_sigs.begin(),
78  ext_func_sigs.end(),
79  std::back_inserter(ext_funcs),
80  [arity](auto sig) { return arity == sig.getArgs().size(); });
81  }
82  return ext_funcs;
83 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
string name
Definition: setup.in.py:72
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

std::vector< ExtensionFunction > ExtensionFunctionsWhitelist::get_ext_funcs ( const std::string &  name,
size_t  arity,
const SQLTypeInfo rtype 
)
static

Definition at line 85 of file ExtensionFunctionsWhitelist.cpp.

References ext_arg_type_to_type_info(), functions_, SQLTypeInfo::get_type(), kBOOLEAN, kTINYINT, rt_udf_functions_, to_upper(), and udf_functions_.

88  {
89  std::vector<ExtensionFunction> ext_funcs = {};
90  const auto collections = {&functions_, &udf_functions_, &rt_udf_functions_};
91  const auto uname = to_upper(name);
92  for (auto funcs : collections) {
93  const auto it = funcs->find(uname);
94  if (it == funcs->end()) {
95  continue;
96  }
97  auto ext_func_sigs = it->second;
98  std::copy_if(ext_func_sigs.begin(),
99  ext_func_sigs.end(),
100  std::back_inserter(ext_funcs),
101  [arity, rtype](auto sig) {
102  // Ideally, arity should be equal to the number of
103  // sig arguments but there seems to be many cases
104  // where some sig arguments will be represented
105  // with multiple arguments, for instance, array
106  // argument is translated to data pointer and array
107  // size arguments.
108  if (arity > sig.getArgs().size()) {
109  return false;
110  }
111  auto rt = rtype.get_type();
112  auto st = ext_arg_type_to_type_info(sig.getRet()).get_type();
113  return (st == rt || (st == kTINYINT && rt == kBOOLEAN));
114  });
115  }
116  return ext_funcs;
117 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
string name
Definition: setup.in.py:72
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)

+ Here is the call graph for this function:

std::vector< ExtensionFunction > * ExtensionFunctionsWhitelist::get_udf ( const std::string &  name)
static

Definition at line 36 of file ExtensionFunctionsWhitelist.cpp.

References to_upper(), and udf_functions_.

37  {
38  const auto it = udf_functions_.find(to_upper(name));
39  if (it == udf_functions_.end()) {
40  return nullptr;
41  }
42  return &it->second;
43 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
string name
Definition: setup.in.py:72
std::string to_upper(const std::string &str)

+ Here is the call graph for this function:

std::vector< std::string > ExtensionFunctionsWhitelist::getLLVMDeclarations ( const std::unordered_set< std::string > &  udf_decls,
const bool  is_gpu = false 
)
static

Definition at line 474 of file ExtensionFunctionsWhitelist.cpp.

References CHECK, functions_, table_functions::TableFunctionsFactory::functions_, Int32, is_ext_arg_type_array(), join(), and anonymous_namespace{ExtensionFunctionsWhitelist.cpp}::serialize_type().

476  {
477  std::vector<std::string> declarations;
478  for (const auto& kv : functions_) {
479  const auto& signatures = kv.second;
480  CHECK(!signatures.empty());
481  for (const auto& signature : kv.second) {
482  // If there is a udf function declaration matching an extension function signature
483  // do not emit a duplicate declaration.
484  if (!udf_decls.empty() && udf_decls.find(signature.getName()) != udf_decls.end()) {
485  continue;
486  }
487 
488  std::string decl_prefix;
489  std::vector<std::string> arg_strs;
490 
491  if (is_ext_arg_type_array(signature.getRet())) {
492  decl_prefix = "declare void @" + signature.getName();
493  arg_strs.emplace_back(serialize_type(signature.getRet()));
494  } else {
495  decl_prefix =
496  "declare " + serialize_type(signature.getRet()) + " @" + signature.getName();
497  }
498  for (const auto arg : signature.getArgs()) {
499  arg_strs.push_back(serialize_type(arg));
500  }
501  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
502  ");");
503  }
504  }
505 
507  if (kv.second.isRuntime() || kv.second.useDefaultSizer()) {
508  // Runtime UDTFs are defined in LLVM/NVVM IR module
509  // UDTFs using default sizer share LLVM IR
510  continue;
511  }
512  if (!((is_gpu && kv.second.isGPU()) || (!is_gpu && kv.second.isCPU()))) {
513  continue;
514  }
515  std::string decl_prefix{"declare " + serialize_type(ExtArgumentType::Int32) + " @" +
516  kv.first};
517  std::vector<std::string> arg_strs;
518  for (const auto arg : kv.second.getArgs(/* ensure_column = */ true)) {
519  arg_strs.push_back(serialize_type(arg, /* byval= */ kv.second.isRuntime()));
520  }
521  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
522  ");");
523  }
524  return declarations;
525 }
std::string join(T const &container, std::string const &delim)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
std::string serialize_type(const ExtArgumentType type, bool byval=true)
#define CHECK(condition)
Definition: Logger.h:203
static std::unordered_map< std::string, TableFunction > functions_

+ Here is the call graph for this function:

std::string ExtensionFunctionsWhitelist::toString ( const std::vector< ExtensionFunction > &  ext_funcs,
std::string  tab = "" 
)
static

Definition at line 307 of file ExtensionFunctionsWhitelist.cpp.

References test_fsi::r.

Referenced by bind_function(), table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::ext_arg_pointer_type_to_type_info(), table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::ext_arg_type_to_type_info_output(), table_functions::TableFunction::getSignature(), anonymous_namespace{ExtensionFunctionsBinding.cpp}::match_arguments(), ExtensionFunction::toString(), toString(), and table_functions::TableFunction::toString().

309  {
310  std::string r = "";
311  for (auto sig : ext_funcs) {
312  r += tab + sig.toString() + "\n";
313  }
314  return r;
315 }
tuple r
Definition: test_fsi.py:16

+ Here is the caller graph for this function:

std::string ExtensionFunctionsWhitelist::toString ( const std::vector< SQLTypeInfo > &  arg_types)
static

Definition at line 317 of file ExtensionFunctionsWhitelist.cpp.

References test_fsi::r.

318  {
319  std::string r = "";
320  for (auto sig = arg_types.begin(); sig != arg_types.end();) {
321  r += sig->get_type_name();
322  sig++;
323  if (sig != arg_types.end()) {
324  r += ", ";
325  }
326  }
327  return r;
328 }
tuple r
Definition: test_fsi.py:16
std::string ExtensionFunctionsWhitelist::toString ( const std::vector< ExtArgumentType > &  sig_types)
static

Definition at line 330 of file ExtensionFunctionsWhitelist.cpp.

References test_fsi::r, anonymous_namespace{ExtensionFunctionsWhitelist.cpp}::serialize_type(), and t.

331  {
332  std::string r = "";
333  for (auto t = sig_types.begin(); t != sig_types.end();) {
334  r += serialize_type(*t);
335  t++;
336  if (t != sig_types.end()) {
337  r += ", ";
338  }
339  }
340  return r;
341 }
tuple r
Definition: test_fsi.py:16
std::string serialize_type(const ExtArgumentType type, bool byval=true)
char * t

+ Here is the call graph for this function:

std::string ExtensionFunctionsWhitelist::toString ( const ExtArgumentType sig_type)
static

Definition at line 356 of file ExtensionFunctionsWhitelist.cpp.

References anonymous_namespace{ExtensionFunctionsWhitelist.cpp}::serialize_type().

356  {
357  return serialize_type(sig_type);
358 }
std::string serialize_type(const ExtArgumentType type, bool byval=true)

+ Here is the call graph for this function:

std::string ExtensionFunctionsWhitelist::toStringSQL ( const std::vector< ExtArgumentType > &  sig_types)
static

Definition at line 343 of file ExtensionFunctionsWhitelist.cpp.

References test_fsi::r, and t.

Referenced by ExtensionFunction::toStringSQL(), and table_functions::TableFunction::toStringSQL().

344  {
345  std::string r = "";
346  for (auto t = sig_types.begin(); t != sig_types.end();) {
348  t++;
349  if (t != sig_types.end()) {
350  r += ", ";
351  }
352  }
353  return r;
354 }
tuple r
Definition: test_fsi.py:16
char * t
static std::string toStringSQL(const std::vector< ExtArgumentType > &sig_types)

+ Here is the caller graph for this function:

std::string ExtensionFunctionsWhitelist::toStringSQL ( const ExtArgumentType sig_type)
static

Definition at line 360 of file ExtensionFunctionsWhitelist.cpp.

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, ColumnBool, ColumnDouble, ColumnFloat, ColumnInt16, ColumnInt32, ColumnInt64, ColumnInt8, ColumnListBool, ColumnListDouble, ColumnListFloat, ColumnListInt16, ColumnListInt32, ColumnListInt64, ColumnListInt8, Cursor, Double, Float, GeoLineString, GeoMultiPolygon, GeoPoint, GeoPolygon, Int16, Int32, Int64, Int8, PBool, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, TextEncodingDict16, TextEncodingDict32, TextEncodingDict8, TextEncodingNone, UNREACHABLE, and Void.

360  {
361  switch (sig_type) {
363  return "TINYINT";
365  return "SMALLINT";
367  return "INTEGER";
369  return "BIGINT";
371  return "FLOAT";
373  return "DOUBLE";
375  return "BOOLEAN";
377  return "TINYINT[]";
379  return "SMALLINT[]";
381  return "INT[]";
383  return "BIGINT[]";
385  return "FLOAT[]";
387  return "DOUBLE[]";
389  return "BOOLEAN[]";
391  return "ARRAY<TINYINT>";
393  return "ARRAY<SMALLINT>";
395  return "ARRAY<INT>";
397  return "ARRAY<BIGINT>";
399  return "ARRAY<FLOAT>";
401  return "ARRAY<DOUBLE>";
403  return "ARRAY<BOOLEAN>";
405  return "COLUMN<TINYINT>";
407  return "COLUMN<SMALLINT>";
409  return "COLUMN<INT>";
411  return "COLUMN<BIGINT>";
413  return "COLUMN<FLOAT>";
415  return "COLUMN<DOUBLE>";
417  return "COLUMN<BOOLEAN>";
419  return "CURSOR";
421  return "POINT";
423  return "LINESTRING";
425  return "POLYGON";
427  return "MULTIPOLYGON";
429  return "VOID";
431  return "TEXT ENCODING NONE";
433  return "TEXT ENCODING DICT(8)";
435  return "TEXT ENCODING DICT(16)";
437  return "TEXT ENCODING DICT(32)";
439  return "COLUMNLIST<TINYINT>";
441  return "COLUMNLIST<SMALLINT>";
443  return "COLUMNLIST<INT>";
445  return "COLUMNLIST<BIGINT>";
447  return "COLUMNLIST<FLOAT>";
449  return "COLUMNLIST<DOUBLE>";
451  return "COLUMNLIST<BOOLEAN>";
452  default:
453  UNREACHABLE();
454  }
455  return "";
456 }
#define UNREACHABLE()
Definition: Logger.h:247

Member Data Documentation

std::unordered_map< std::string, std::vector< ExtensionFunction > > ExtensionFunctionsWhitelist::functions_
staticprivate

Definition at line 157 of file ExtensionFunctionsWhitelist.h.

Referenced by add(), get(), get_ext_funcs(), and getLLVMDeclarations().

std::unordered_map< std::string, std::vector< ExtensionFunction > > ExtensionFunctionsWhitelist::rt_udf_functions_
staticprivate

Definition at line 162 of file ExtensionFunctionsWhitelist.h.

Referenced by addRTUdfs(), clearRTUdfs(), and get_ext_funcs().

std::unordered_map< std::string, std::vector< ExtensionFunction > > ExtensionFunctionsWhitelist::udf_functions_
staticprivate

Definition at line 159 of file ExtensionFunctionsWhitelist.h.

Referenced by addUdfs(), get_ext_funcs(), and get_udf().


The documentation for this class was generated from the following files: