OmniSciDB  04ee39c94c
ExtensionFunctionsWhitelist Class Reference

#include <ExtensionFunctionsWhitelist.h>

+ Collaboration diagram for ExtensionFunctionsWhitelist:

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< ExtensionFunctionget_ext_funcs (const std::string &name)
 
static std::vector< ExtensionFunctionget_ext_funcs (const std::string &name, size_t arity)
 
static std::vector< ExtensionFunctionget_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 ()
 

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

Member Function Documentation

◆ add()

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

Definition at line 325 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and functions_.

Referenced by MapDHandler::MapDHandler(), and QueryRunner::QueryRunner::QueryRunner().

325  {
326  // Valid json_func_sigs example:
327  // [
328  // {
329  // "name":"sum",
330  // "ret":"i32",
331  // "args":[
332  // "i32",
333  // "i32"
334  // ]
335  // }
336  // ]
337 
338  addCommon(functions_, json_func_sigs);
339 }
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:

◆ addCommon()

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

Definition at line 299 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().

300  {
301  rapidjson::Document func_sigs;
302  func_sigs.Parse(json_func_sigs.c_str());
303  CHECK(func_sigs.IsArray());
304  for (auto func_sigs_it = func_sigs.Begin(); func_sigs_it != func_sigs.End();
305  ++func_sigs_it) {
306  CHECK(func_sigs_it->IsObject());
307  const auto name = json_str(field(*func_sigs_it, "name"));
308  const auto ret = deserialize_type(json_str(field(*func_sigs_it, "ret")));
309  std::vector<ExtArgumentType> args;
310  const auto& args_serialized = field(*func_sigs_it, "args");
311  CHECK(args_serialized.IsArray());
312  for (auto args_serialized_it = args_serialized.Begin();
313  args_serialized_it != args_serialized.End();
314  ++args_serialized_it) {
315  args.push_back(deserialize_type(json_str(*args_serialized_it)));
316  }
317  signatures[to_upper(drop_suffix(name))].emplace_back(name, args, ret);
318  }
319 }
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:187
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addRTUdfs()

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

Definition at line 351 of file ExtensionFunctionsWhitelist.cpp.

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

Referenced by MapDHandler::register_runtime_udf().

351  {
352  if (!json_func_sigs.empty()) {
353  addCommon(rt_udf_functions_, json_func_sigs);
354  }
355 }
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:
+ Here is the caller graph for this function:

◆ addUdfs()

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

Definition at line 341 of file ExtensionFunctionsWhitelist.cpp.

References addCommon(), and udf_functions_.

Referenced by MapDHandler::MapDHandler(), and QueryRunner::QueryRunner::QueryRunner().

341  {
342  if (!json_func_sigs.empty()) {
343  addCommon(udf_functions_, json_func_sigs);
344  }
345 }
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:

◆ clearRTUdfs()

void ExtensionFunctionsWhitelist::clearRTUdfs ( )
static

Definition at line 347 of file ExtensionFunctionsWhitelist.cpp.

References rt_udf_functions_.

Referenced by MapDHandler::register_runtime_udf().

347  {
348  rt_udf_functions_.clear();
349 }
static std::unordered_map< std::string, std::vector< ExtensionFunction > > rt_udf_functions_
+ Here is the caller graph for this function:

◆ get()

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

Definition at line 26 of file ExtensionFunctionsWhitelist.cpp.

References functions_, and to_upper().

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

◆ get_ext_funcs() [1/3]

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

Definition at line 43 of file ExtensionFunctionsWhitelist.cpp.

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

Referenced by bind_function().

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

◆ get_ext_funcs() [2/3]

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

Definition at line 59 of file ExtensionFunctionsWhitelist.cpp.

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

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

◆ get_ext_funcs() [3/3]

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

Definition at line 79 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_.

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

◆ get_udf()

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

Definition at line 34 of file ExtensionFunctionsWhitelist.cpp.

References to_upper(), and udf_functions_.

Referenced by TEST_F().

35  {
36  const auto it = udf_functions_.find(to_upper(name));
37  if (it == udf_functions_.end()) {
38  return nullptr;
39  }
40  return &it->second;
41 }
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:
+ Here is the caller graph for this function:

◆ getLLVMDeclarations()

std::vector< std::string > ExtensionFunctionsWhitelist::getLLVMDeclarations ( )
static

Definition at line 221 of file ExtensionFunctionsWhitelist.cpp.

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

221  {
222  std::vector<std::string> declarations;
223  for (const auto& kv : functions_) {
224  const auto& signatures = kv.second;
225  CHECK(!signatures.empty());
226  for (const auto& signature : kv.second) {
227  std::string decl_prefix{"declare " + serialize_type(signature.getRet()) + " @" +
228  signature.getName()};
229  std::vector<std::string> arg_strs;
230  for (const auto arg : signature.getArgs()) {
231  arg_strs.push_back(serialize_type(arg));
232  }
233  declarations.push_back(decl_prefix + "(" + boost::algorithm::join(arg_strs, ", ") +
234  ");");
235  }
236  }
237  return declarations;
238 }
std::string join(T const &container, std::string const &delim)
static std::unordered_map< std::string, std::vector< ExtensionFunction > > functions_
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the call graph for this function:

◆ toString() [1/3]

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

Definition at line 179 of file ExtensionFunctionsWhitelist.cpp.

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

181  {
182  std::string r = "";
183  for (auto sig : ext_funcs) {
184  r += tab + sig.toString() + "\n";
185  }
186  return r;
187 }
+ Here is the caller graph for this function:

◆ toString() [2/3]

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

Definition at line 189 of file ExtensionFunctionsWhitelist.cpp.

190  {
191  std::string r = "";
192  for (auto sig = arg_types.begin(); sig != arg_types.end();) {
193  r += sig->get_type_name();
194  sig++;
195  if (sig != arg_types.end()) {
196  r += ", ";
197  }
198  }
199  return r;
200 }

◆ toString() [3/3]

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

Definition at line 202 of file ExtensionFunctionsWhitelist.cpp.

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

203  {
204  std::string r = "";
205  for (auto t = sig_types.begin(); t != sig_types.end();) {
206  r += serialize_type(*t);
207  t++;
208  if (t != sig_types.end()) {
209  r += ", ";
210  }
211  }
212  return r;
213 }
+ Here is the call graph for this function:

Member Data Documentation

◆ functions_

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

◆ rt_udf_functions_

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

Definition at line 111 of file ExtensionFunctionsWhitelist.h.

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

◆ udf_functions_

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

Definition at line 109 of file ExtensionFunctionsWhitelist.h.

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


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