OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
table_functions::TableFunctionsFactory Class Reference

#include <TableFunctionsFactory.h>

Static Public Member Functions

static void add (const std::string &name, const TableFunctionOutputRowSizer sizer, const std::vector< ExtArgumentType > &input_args, const std::vector< ExtArgumentType > &output_args, const std::vector< ExtArgumentType > &sql_args, const std::vector< std::map< std::string, std::string >> &annotations, bool is_runtime=false)
 
static std::vector< TableFunctionget_table_funcs (const std::string &name, const bool is_gpu)
 
static std::vector< TableFunctionget_table_funcs (const std::string &name)
 
static std::vector< TableFunctionget_table_funcs (const bool is_runtime)
 
static std::vector< TableFunctionget_table_funcs ()
 
static void init ()
 
static void reset ()
 

Static Private Attributes

static std::unordered_map
< std::string, TableFunction
functions_
 

Friends

class ::ExtensionFunctionsWhitelist
 

Detailed Description

Definition at line 350 of file TableFunctionsFactory.h.

Member Function Documentation

void table_functions::TableFunctionsFactory::add ( const std::string &  name,
const TableFunctionOutputRowSizer  sizer,
const std::vector< ExtArgumentType > &  input_args,
const std::vector< ExtArgumentType > &  output_args,
const std::vector< ExtArgumentType > &  sql_args,
const std::vector< std::map< std::string, std::string >> &  annotations,
bool  is_runtime = false 
)
static

Definition at line 353 of file TableFunctionsFactory.cpp.

References DEFAULT_ROW_MULTIPLIER_SUFFIX, functions_, g_enable_dev_table_functions, table_functions::is_table_function_whitelisted(), table_functions::kUserSpecifiedRowMultiplier, LOG, setup::name, table_functions::TableFunctionOutputRowSizer::type, generate_TableFunctionsFactory_init::uses_manager(), table_functions::TableFunctionOutputRowSizer::val, and logger::WARNING.

Referenced by DBHandler::register_runtime_extension_functions().

360  {
361  static const std::map<std::string, std::string> empty = {};
362 
363  auto func_annotations =
364  (annotations.size() == sql_args.size() + output_args.size() + 1 ? annotations.back()
365  : empty);
366  auto mgr_annotation = func_annotations.find("uses_manager");
367  bool uses_manager = mgr_annotation != func_annotations.end() &&
368  boost::algorithm::to_lower_copy(mgr_annotation->second) == "true";
369 
370  auto tf = TableFunction(name,
371  sizer,
372  input_args,
373  output_args,
374  sql_args,
375  annotations,
376  is_runtime,
377  uses_manager);
378  const auto tf_name = tf.getName(true /* drop_suffix */, true /* lower */);
379  if (!g_enable_dev_table_functions && !is_runtime &&
380  !is_table_function_whitelisted(tf_name)) {
381  return;
382  }
383  auto sig = tf.getSignature(/* include_name */ true, /* include_output */ false);
384  for (auto it = functions_.begin(); it != functions_.end();) {
385  if (it->second.getName() == name) {
386  if (it->second.isRuntime()) {
387  LOG(WARNING)
388  << "Overriding existing run-time table function (reset not called?): "
389  << name;
390  it = functions_.erase(it);
391  } else {
392  throw std::runtime_error("Will not override existing load-time table function: " +
393  name);
394  }
395  } else {
396  if (sig == it->second.getSignature(/* include_name */ true,
397  /* include_output */ false) &&
398  ((tf.isCPU() && it->second.isCPU()) || (tf.isGPU() && it->second.isGPU()))) {
399  LOG(WARNING)
400  << "The existing (1) and added (2) table functions have the same signature `"
401  << sig << "`:\n"
402  << " 1: " << it->second.toString() << "\n 2: " << tf.toString() << "\n";
403  }
404  ++it;
405  }
406  }
407 
408  functions_.emplace(name, tf);
410  auto input_args2 = input_args;
411  input_args2.erase(input_args2.begin() + sizer.val - 1);
412 
413  auto sql_args2 = sql_args;
414  auto sql_sizer_pos = tf.getSqlOutputRowSizeParameter();
415  sql_args2.erase(sql_args2.begin() + sql_sizer_pos);
416 
417  auto annotations2 = annotations;
418  annotations2.erase(annotations2.begin() + sql_sizer_pos);
419 
421  sizer,
422  input_args2,
423  output_args,
424  sql_args2,
425  annotations2,
426  is_runtime,
427  uses_manager);
428  auto sig = tf2.getSignature(/* include_name */ true, /* include_output */ false);
429  for (auto it = functions_.begin(); it != functions_.end();) {
430  if (sig == it->second.getSignature(/* include_name */ true,
431  /* include_output */ false) &&
432  ((tf2.isCPU() && it->second.isCPU()) || (tf2.isGPU() && it->second.isGPU()))) {
433  LOG(WARNING)
434  << "The existing (1) and added (2) table functions have the same signature `"
435  << sig << "`:\n"
436  << " 1: " << it->second.toString() << "\n 2: " << tf2.toString() << "\n";
437  }
438  ++it;
439  }
441  }
442 }
#define LOG(tag)
Definition: Logger.h:285
#define DEFAULT_ROW_MULTIPLIER_SUFFIX
bool g_enable_dev_table_functions
Definition: Execute.cpp:113
bool is_table_function_whitelisted(const std::string &function_name)
static std::unordered_map< std::string, TableFunction > functions_
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( const std::string &  name,
const bool  is_gpu 
)
static

Definition at line 524 of file TableFunctionsFactory.cpp.

References get_table_funcs().

525  {
526  std::vector<TableFunction> table_funcs;
527  for (const auto& tf : get_table_funcs(name)) {
528  if (is_gpu ? tf.isGPU() : tf.isCPU()) {
529  table_funcs.emplace_back(tf);
530  }
531  }
532  return table_funcs;
533 }
static std::vector< TableFunction > get_table_funcs()
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( const std::string &  name)
static

Definition at line 535 of file TableFunctionsFactory.cpp.

References anonymous_namespace{RowFunctionManager.h}::drop_suffix_impl(), functions_, setup::name, and to_lower().

536  {
537  std::vector<TableFunction> table_funcs;
538  auto table_func_name = name;
539  boost::algorithm::to_lower(table_func_name);
540  for (const auto& pair : functions_) {
541  auto fname = drop_suffix_impl(pair.first);
542  if (fname == table_func_name) {
543  table_funcs.push_back(pair.second);
544  }
545  }
546  return table_funcs;
547 }
std::string to_lower(const std::string &str)
std::string drop_suffix_impl(const std::string &str)
static std::unordered_map< std::string, TableFunction > functions_
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( const bool  is_runtime)
static

Definition at line 549 of file TableFunctionsFactory.cpp.

References functions_.

549  {
550  std::vector<TableFunction> table_funcs;
551  for (const auto& pair : functions_) {
552  if (pair.second.isRuntime() == is_runtime) {
553  table_funcs.push_back(pair.second);
554  }
555  }
556  return table_funcs;
557 }
static std::unordered_map< std::string, TableFunction > functions_
std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( )
static

Definition at line 559 of file TableFunctionsFactory.cpp.

References functions_.

Referenced by bind_table_function(), ShowTableFunctionsCommand::execute(), ShowRuntimeTableFunctionsCommand::execute(), DBHandler::get_runtime_table_function_names(), get_table_funcs(), DBHandler::get_table_function_details(), DBHandler::get_table_function_names(), DBHandler::initialize(), QueryRunner::QueryRunner::QueryRunner(), and DBHandler::register_runtime_extension_functions().

559  {
560  std::vector<TableFunction> table_funcs;
561  for (const auto& pair : functions_) {
562  table_funcs.push_back(pair.second);
563  }
564  return table_funcs;
565 }
static std::unordered_map< std::string, TableFunction > functions_

+ Here is the caller graph for this function:

static void table_functions::TableFunctionsFactory::init ( )
static

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

+ Here is the caller graph for this function:

void table_functions::TableFunctionsFactory::reset ( )
static

Definition at line 450 of file TableFunctionsFactory.cpp.

References functions_, and g_enable_table_functions.

Referenced by DBHandler::register_runtime_extension_functions().

450  {
452  return;
453  }
454  for (auto it = functions_.begin(); it != functions_.end();) {
455  if (it->second.isRuntime()) {
456  it = functions_.erase(it);
457  } else {
458  ++it;
459  }
460  }
461 }
static std::unordered_map< std::string, TableFunction > functions_
bool g_enable_table_functions
Definition: Execute.cpp:112

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ::ExtensionFunctionsWhitelist
friend

Definition at line 371 of file TableFunctionsFactory.h.

Member Data Documentation

std::unordered_map< std::string, TableFunction > table_functions::TableFunctionsFactory::functions_
staticprivate

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