OmniSciDB  addbbd5075
 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::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 85 of file ExtensionFunctionsWhitelist.h.

Member Function Documentation

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

Definition at line 409 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and functions_.

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

409  {
410  // Valid json_func_sigs example:
411  // [
412  // {
413  // "name":"sum",
414  // "ret":"i32",
415  // "args":[
416  // "i32",
417  // "i32"
418  // ]
419  // }
420  // ]
421 
422  addCommon(functions_, json_func_sigs);
423 }
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 383 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(), and to_upper().

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

384  {
385  rapidjson::Document func_sigs;
386  func_sigs.Parse(json_func_sigs.c_str());
387  CHECK(func_sigs.IsArray());
388  for (auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
389  ++func_sigs_it) {
390  CHECK(func_sigs_it->IsObject());
391  const auto name = json_str(field(*func_sigs_it, "name"));
392  const auto ret = deserialize_type(json_str(field(*func_sigs_it, "ret")));
393  std::vector<ExtArgumentType> args;
394  const auto& args_serialized = field(*func_sigs_it, "args");
395  CHECK(args_serialized.IsArray());
396  for (auto args_serialized_it = args_serialized.Begin();
397  args_serialized_it != args_serialized.End();
398  ++args_serialized_it) {
399  args.push_back(deserialize_type(json_str(*args_serialized_it)));
400  }
401  signatures[to_upper(drop_suffix(name))].emplace_back(name, args, ret);
402  }
403 }
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
CHECK(cgen_state)
ExtArgumentType deserialize_type(const std::string &type_name)
std::string to_upper(const std::string &str)

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

References addCommon(), and rt_udf_functions_.

435  {
436  if (!json_func_sigs.empty()) {
437  addCommon(rt_udf_functions_, json_func_sigs);
438  }
439 }
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 425 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and udf_functions_.

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

425  {
426  if (!json_func_sigs.empty()) {
427  addCommon(udf_functions_, json_func_sigs);
428  }
429 }
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 431 of file ExtensionFunctionsWhitelist.cpp.

References rt_udf_functions_.

431  {
432  rt_udf_functions_.clear();
433 }
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 27 of file ExtensionFunctionsWhitelist.cpp.

References functions_, and to_upper().

28  {
29  const auto it = functions_.find(to_upper(name));
30  if (it == functions_.end()) {
31  return nullptr;
32  }
33  return &it->second;
34 }
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)
static

Definition at line 44 of file ExtensionFunctionsWhitelist.cpp.

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

Referenced by bind_function().

45  {
46  std::vector<ExtensionFunction> ext_funcs = {};
47  const auto collections = {&functions_, &udf_functions_, &rt_udf_functions_};
48  const auto uname = to_upper(name);
49  for (auto funcs : collections) {
50  const auto it = funcs->find(uname);
51  if (it == funcs->end()) {
52  continue;
53  }
54  auto ext_func_sigs = it->second;
55  std::copy(ext_func_sigs.begin(), ext_func_sigs.end(), std::back_inserter(ext_funcs));
56  }
57  return ext_funcs;
58 }
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)

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

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

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

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

References ext_arg_type_to_type_info(), functions_, SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), kBOOLEAN, kTINYINT, rt_udf_functions_, to_upper(), and udf_functions_.

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

References to_upper(), and udf_functions_.

36  {
37  const auto it = udf_functions_.find(to_upper(name));
38  if (it == udf_functions_.end()) {
39  return nullptr;
40  }
41  return &it->second;
42 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > udf_functions_
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)
static

Definition at line 246 of file ExtensionFunctionsWhitelist.cpp.

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

247  {
248  std::vector<std::string> declarations;
249  for (const auto& kv : functions_) {
250  const auto& signatures = kv.second;
251  CHECK(!signatures.empty());
252  for (const auto& signature : kv.second) {
253  // If there is a udf function declaration matching an extension function signature
254  // do not emit a duplicate declaration.
255  if (!udf_decls.empty() && udf_decls.find(signature.getName()) != udf_decls.end()) {
256  continue;
257  }
258 
259  std::string decl_prefix{"declare " + serialize_type(signature.getRet()) + " @" +
260  signature.getName()};
261  std::vector<std::string> arg_strs;
262  for (const auto arg : signature.getArgs()) {
263  arg_strs.push_back(serialize_type(arg));
264  }
265  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
266  ");");
267  }
268  }
269 
271  if (kv.second.isRuntime()) {
272  // Runtime UDTFs are defined in LLVM/NVVM IR module
273  continue;
274  }
275  std::string decl_prefix{"declare " + serialize_type(ExtArgumentType::Int32) + " @" +
276  kv.first};
277  std::vector<std::string> arg_strs;
278  for (const auto arg : kv.second.getArgs()) {
279  arg_strs.push_back(serialize_type(arg));
280  }
281  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
282  ");");
283  }
284  return declarations;
285 }
std::string join(T const &container, std::string const &delim)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
CHECK(cgen_state)
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 204 of file ExtensionFunctionsWhitelist.cpp.

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

206  {
207  std::string r = "";
208  for (auto sig : ext_funcs) {
209  r += tab + sig.toString() + "\n";
210  }
211  return r;
212 }

+ Here is the caller graph for this function:

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

Definition at line 214 of file ExtensionFunctionsWhitelist.cpp.

215  {
216  std::string r = "";
217  for (auto sig = arg_types.begin(); sig != arg_types.end();) {
218  r += sig->get_type_name();
219  sig++;
220  if (sig != arg_types.end()) {
221  r += ", ";
222  }
223  }
224  return r;
225 }
std::string ExtensionFunctionsWhitelist::toString ( const std::vector< ExtArgumentType > &  sig_types)
static

Definition at line 227 of file ExtensionFunctionsWhitelist.cpp.

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

228  {
229  std::string r = "";
230  for (auto t = sig_types.begin(); t != sig_types.end();) {
231  r += serialize_type(*t);
232  t++;
233  if (t != sig_types.end()) {
234  r += ", ";
235  }
236  }
237  return r;
238 }

+ Here is the call graph for this function:

Member Data Documentation

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

Definition at line 122 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 125 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 123 of file ExtensionFunctionsWhitelist.h.

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


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