OmniSciDB  95562058bd
 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)
 
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)
 

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 96 of file ExtensionFunctionsWhitelist.h.

Member Function Documentation

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

Definition at line 605 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and functions_.

Referenced by QueryRunner::QueryRunner::QueryRunner().

605  {
606  // Valid json_func_sigs example:
607  // [
608  // {
609  // "name":"sum",
610  // "ret":"i32",
611  // "args":[
612  // "i32",
613  // "i32"
614  // ]
615  // }
616  // ]
617 
618  addCommon(functions_, json_func_sigs);
619 }
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 579 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().

580  {
581  rapidjson::Document func_sigs;
582  func_sigs.Parse(json_func_sigs.c_str());
583  CHECK(func_sigs.IsArray());
584  for (auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
585  ++func_sigs_it) {
586  CHECK(func_sigs_it->IsObject());
587  const auto name = json_str(field(*func_sigs_it, "name"));
588  const auto ret = deserialize_type(json_str(field(*func_sigs_it, "ret")));
589  std::vector<ExtArgumentType> args;
590  const auto& args_serialized = field(*func_sigs_it, "args");
591  CHECK(args_serialized.IsArray());
592  for (auto args_serialized_it = args_serialized.Begin();
593  args_serialized_it != args_serialized.End();
594  ++args_serialized_it) {
595  args.push_back(deserialize_type(json_str(*args_serialized_it)));
596  }
597  signatures[to_upper(drop_suffix(name))].emplace_back(name, args, ret);
598  }
599 }
const std::string json_str(const rapidjson::Value &obj) noexcept
Definition: JsonAccessors.h:44
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:197
string name
Definition: setup.py:35

+ 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 631 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and rt_udf_functions_.

631  {
632  if (!json_func_sigs.empty()) {
633  addCommon(rt_udf_functions_, json_func_sigs);
634  }
635 }
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 621 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and udf_functions_.

Referenced by QueryRunner::QueryRunner::QueryRunner().

621  {
622  if (!json_func_sigs.empty()) {
623  addCommon(udf_functions_, json_func_sigs);
624  }
625 }
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 627 of file ExtensionFunctionsWhitelist.cpp.

References rt_udf_functions_.

627  {
628  rt_udf_functions_.clear();
629 }
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 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)
string name
Definition: setup.py:35

+ Here is the call graph for this function:

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

Definition at line 45 of file ExtensionFunctionsWhitelist.cpp.

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

Referenced by bind_function().

46  {
47  std::vector<ExtensionFunction> ext_funcs = {};
48  const auto collections = {&functions_, &udf_functions_, &rt_udf_functions_};
49  const auto uname = to_upper(name);
50  for (auto funcs : collections) {
51  const auto it = funcs->find(uname);
52  if (it == funcs->end()) {
53  continue;
54  }
55  auto ext_func_sigs = it->second;
56  std::copy(ext_func_sigs.begin(), ext_func_sigs.end(), std::back_inserter(ext_funcs));
57  }
58  return ext_funcs;
59 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
std::string to_upper(const std::string &str)
string name
Definition: setup.py:35

+ 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 61 of file ExtensionFunctionsWhitelist.cpp.

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

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

+ 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 81 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_.

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

+ Here is the call graph for this function:

std::vector< std::string > ExtensionFunctionsWhitelist::getLLVMDeclarations ( const std::unordered_set< std::string > &  udf_decls)
static

Definition at line 418 of file ExtensionFunctionsWhitelist.cpp.

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

419  {
420  std::vector<std::string> declarations;
421  for (const auto& kv : functions_) {
422  const auto& signatures = kv.second;
423  CHECK(!signatures.empty());
424  for (const auto& signature : kv.second) {
425  // If there is a udf function declaration matching an extension function signature
426  // do not emit a duplicate declaration.
427  if (!udf_decls.empty() && udf_decls.find(signature.getName()) != udf_decls.end()) {
428  continue;
429  }
430 
431  std::string decl_prefix;
432  std::vector<std::string> arg_strs;
433 
434  if (is_ext_arg_type_array(signature.getRet())) {
435  decl_prefix = "declare void @" + signature.getName();
436  arg_strs.emplace_back(serialize_type(signature.getRet()));
437  } else {
438  decl_prefix =
439  "declare " + serialize_type(signature.getRet()) + " @" + signature.getName();
440  }
441  for (const auto arg : signature.getArgs()) {
442  arg_strs.push_back(serialize_type(arg));
443  }
444  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
445  ");");
446  }
447  }
448 
450  if (kv.second.isRuntime()) {
451  // Runtime UDTFs are defined in LLVM/NVVM IR module
452  continue;
453  }
454  std::string decl_prefix{"declare " + serialize_type(ExtArgumentType::Int32) + " @" +
455  kv.first};
456  std::vector<std::string> arg_strs;
457  for (const auto arg : kv.second.getArgs()) {
458  arg_strs.push_back(serialize_type(arg));
459  }
460  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
461  ");");
462  }
463  return declarations;
464 }
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)
#define CHECK(condition)
Definition: Logger.h:197
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 273 of file ExtensionFunctionsWhitelist.cpp.

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

275  {
276  std::string r = "";
277  for (auto sig : ext_funcs) {
278  r += tab + sig.toString() + "\n";
279  }
280  return r;
281 }

+ Here is the caller graph for this function:

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

Definition at line 283 of file ExtensionFunctionsWhitelist.cpp.

284  {
285  std::string r = "";
286  for (auto sig = arg_types.begin(); sig != arg_types.end();) {
287  r += sig->get_type_name();
288  sig++;
289  if (sig != arg_types.end()) {
290  r += ", ";
291  }
292  }
293  return r;
294 }
std::string ExtensionFunctionsWhitelist::toString ( const std::vector< ExtArgumentType > &  sig_types)
static

Definition at line 296 of file ExtensionFunctionsWhitelist.cpp.

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

297  {
298  std::string r = "";
299  for (auto t = sig_types.begin(); t != sig_types.end();) {
300  r += serialize_type(*t);
301  t++;
302  if (t != sig_types.end()) {
303  r += ", ";
304  }
305  }
306  return r;
307 }

+ Here is the call graph for this function:

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

Definition at line 322 of file ExtensionFunctionsWhitelist.cpp.

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

322  {
323  return serialize_type(sig_type);
324 }

+ Here is the call graph for this function:

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

Definition at line 309 of file ExtensionFunctionsWhitelist.cpp.

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

310  {
311  std::string r = "";
312  for (auto t = sig_types.begin(); t != sig_types.end();) {
314  t++;
315  if (t != sig_types.end()) {
316  r += ", ";
317  }
318  }
319  return r;
320 }
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 326 of file ExtensionFunctionsWhitelist.cpp.

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, ColumnBool, ColumnDouble, ColumnFloat, ColumnInt16, ColumnInt32, ColumnInt64, ColumnInt8, Cursor, Double, Float, GeoLineString, GeoMultiPolygon, GeoPoint, GeoPolygon, Int16, Int32, Int64, Int8, PBool, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, UNREACHABLE, and Void.

326  {
327  switch (sig_type) {
329  return "TINYINT";
331  return "SMALLINT";
333  return "INTEGER";
335  return "BIGINT";
337  return "FLOAT";
339  return "DOUBLE";
341  return "BOOLEAN";
343  return "TINYINT[]";
345  return "SMALLINT[]";
347  return "INT[]";
349  return "BIGINT[]";
351  return "FLOAT[]";
353  return "DOUBLE[]";
355  return "BOOLEAN[]";
357  return "ARRAY<TINYINT>";
359  return "ARRAY<SMALLINT>";
361  return "ARRAY<INT>";
363  return "ARRAY<BIGINT>";
365  return "ARRAY<FLOAT>";
367  return "ARRAY<DOUBLE>";
369  return "ARRAY<BOOLEAN>";
371  return "COLUMN<TINYINT>";
373  return "COLUMN<SMALLINT>";
375  return "COLUMN<INT>";
377  return "COLUMN<BIGINT>";
379  return "COLUMN<FLOAT>";
381  return "COLUMN<DOUBLE>";
383  return "COLUMN<BOOLEAN>";
385  return "CURSOR";
387  return "POINT";
389  return "LINESTRING";
391  return "POLYGON";
393  return "MULTIPOLYGON";
395  return "VOID";
396  default:
397  UNREACHABLE();
398  }
399  return "";
400 }
#define UNREACHABLE()
Definition: Logger.h:241

Member Data Documentation

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

Definition at line 136 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 139 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 137 of file ExtensionFunctionsWhitelist.h.

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


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