OmniSciDB  4201147b46
 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 398 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().

405  {
406  static const std::map<std::string, std::string> empty = {};
407 
408  auto func_annotations =
409  (annotations.size() == sql_args.size() + output_args.size() + 1 ? annotations.back()
410  : empty);
411  auto mgr_annotation = func_annotations.find("uses_manager");
412  bool uses_manager = mgr_annotation != func_annotations.end() &&
413  boost::algorithm::to_lower_copy(mgr_annotation->second) == "true";
414 
415  auto tf = TableFunction(name,
416  sizer,
417  input_args,
418  output_args,
419  sql_args,
420  annotations,
421  is_runtime,
422  uses_manager);
423  const auto tf_name = tf.getName(true /* drop_suffix */, true /* lower */);
424  if (!g_enable_dev_table_functions && !is_runtime &&
425  !is_table_function_whitelisted(tf_name)) {
426  return;
427  }
428  auto sig = tf.getSignature(/* include_name */ true, /* include_output */ false);
429  for (auto it = functions_.begin(); it != functions_.end();) {
430  if (it->second.getName() == name) {
431  if (it->second.isRuntime()) {
432  LOG(WARNING)
433  << "Overriding existing run-time table function (reset not called?): "
434  << name;
435  it = functions_.erase(it);
436  } else {
437  throw std::runtime_error("Will not override existing load-time table function: " +
438  name);
439  }
440  } else {
441  if (sig == it->second.getSignature(/* include_name */ true,
442  /* include_output */ false) &&
443  ((tf.isCPU() && it->second.isCPU()) || (tf.isGPU() && it->second.isGPU()))) {
444  LOG(WARNING)
445  << "The existing (1) and added (2) table functions have the same signature `"
446  << sig << "`:\n"
447  << " 1: " << it->second.toString() << "\n 2: " << tf.toString() << "\n";
448  }
449  ++it;
450  }
451  }
452 
453  functions_.emplace(name, tf);
455  auto input_args2 = input_args;
456  input_args2.erase(input_args2.begin() + sizer.val - 1);
457 
458  auto sql_args2 = sql_args;
459  auto sql_sizer_pos = tf.getSqlOutputRowSizeParameter();
460  sql_args2.erase(sql_args2.begin() + sql_sizer_pos);
461 
463  sizer,
464  input_args2,
465  output_args,
466  sql_args2,
467  annotations,
468  is_runtime,
469  uses_manager);
470  auto sig = tf2.getSignature(/* include_name */ true, /* include_output */ false);
471  for (auto it = functions_.begin(); it != functions_.end();) {
472  if (sig == it->second.getSignature(/* include_name */ true,
473  /* include_output */ false) &&
474  ((tf2.isCPU() && it->second.isCPU()) || (tf2.isGPU() && it->second.isGPU()))) {
475  LOG(WARNING)
476  << "The existing (1) and added (2) table functions have the same signature `"
477  << sig << "`:\n"
478  << " 1: " << it->second.toString() << "\n 2: " << tf2.toString() << "\n";
479  }
480  ++it;
481  }
483  }
484 }
#define LOG(tag)
Definition: Logger.h:216
#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 566 of file TableFunctionsFactory.cpp.

References get_table_funcs().

567  {
568  std::vector<TableFunction> table_funcs;
569  for (const auto& tf : get_table_funcs(name)) {
570  if (is_gpu ? tf.isGPU() : tf.isCPU()) {
571  table_funcs.emplace_back(tf);
572  }
573  }
574  return table_funcs;
575 }
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 577 of file TableFunctionsFactory.cpp.

References table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::drop_suffix_impl(), functions_, setup::name, and to_lower().

578  {
579  std::vector<TableFunction> table_funcs;
580  auto table_func_name = name;
581  boost::algorithm::to_lower(table_func_name);
582  for (const auto& pair : functions_) {
583  auto fname = drop_suffix_impl(pair.first);
584  if (fname == table_func_name) {
585  table_funcs.push_back(pair.second);
586  }
587  }
588  return table_funcs;
589 }
std::string to_lower(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 591 of file TableFunctionsFactory.cpp.

References functions_.

591  {
592  std::vector<TableFunction> table_funcs;
593  for (const auto& pair : functions_) {
594  if (pair.second.isRuntime() == is_runtime) {
595  table_funcs.push_back(pair.second);
596  }
597  }
598  return table_funcs;
599 }
static std::unordered_map< std::string, TableFunction > functions_
std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( )
static

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

601  {
602  std::vector<TableFunction> table_funcs;
603  for (const auto& pair : functions_) {
604  table_funcs.push_back(pair.second);
605  }
606  return table_funcs;
607 }
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 492 of file TableFunctionsFactory.cpp.

References functions_, and g_enable_table_functions.

Referenced by DBHandler::register_runtime_extension_functions().

492  {
494  return;
495  }
496  for (auto it = functions_.begin(); it != functions_.end();) {
497  if (it->second.isRuntime()) {
498  it = functions_.erase(it);
499  } else {
500  ++it;
501  }
502  }
503 }
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: