OmniSciDB  72c90bc290
 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 ()
 
template<const char * filename>
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 341 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 440 of file TableFunctionsFactory.cpp.

References DEFAULT_ROW_MULTIPLIER_SUFFIX, functions_, g_enable_dev_table_functions, table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::is_table_function_whitelisted(), table_functions::kUserSpecifiedRowMultiplier, LOG, setup::name, generate_TableFunctionsFactory_init::uses_manager(), table_functions::TableFunctionOutputRowSizer::val, and logger::WARNING.

Referenced by DBHandler::register_runtime_extension_functions().

447  {
448  static const std::map<std::string, std::string> empty = {};
449 
450  auto func_annotations =
451  (annotations.size() == sql_args.size() + output_args.size() + 1 ? annotations.back()
452  : empty);
453  auto mgr_annotation = func_annotations.find("uses_manager");
454  bool uses_manager = mgr_annotation != func_annotations.end() &&
455  boost::algorithm::to_lower_copy(mgr_annotation->second) == "true";
456 
457  auto tf = TableFunction(name,
458  sizer,
459  input_args,
460  output_args,
461  sql_args,
462  annotations,
463  is_runtime,
464  uses_manager);
465  const auto tf_name = tf.getName(true /* drop_suffix */, true /* lower */);
466  if (!g_enable_dev_table_functions && !is_runtime &&
467  !is_table_function_whitelisted(tf_name)) {
468  return;
469  }
470  auto sig = tf.getSignature(/* include_name */ true, /* include_output */ false);
471  for (auto it = functions_.begin(); it != functions_.end();) {
472  if (it->second.getName() == name) {
473  if (it->second.isRuntime()) {
474  LOG(WARNING)
475  << "Overriding existing run-time table function (reset not called?): "
476  << name;
477  it = functions_.erase(it);
478  } else {
479  throw std::runtime_error("Will not override existing load-time table function: " +
480  name);
481  }
482  } else {
483  if (sig == it->second.getSignature(/* include_name */ true,
484  /* include_output */ false) &&
485  ((tf.isCPU() && it->second.isCPU()) || (tf.isGPU() && it->second.isGPU()))) {
486  LOG(WARNING)
487  << "The existing (1) and added (2) table functions have the same signature `"
488  << sig << "`:\n"
489  << " 1: " << it->second.toString() << "\n 2: " << tf.toString() << "\n";
490  }
491  ++it;
492  }
493  }
494 
495  functions_.emplace(name, tf);
497  auto input_args2 = input_args;
498  input_args2.erase(input_args2.begin() + sizer.val - 1);
499 
500  auto sql_args2 = sql_args;
501  auto sql_sizer_pos = tf.getSqlOutputRowSizeParameter();
502  sql_args2.erase(sql_args2.begin() + sql_sizer_pos);
503 
504  auto annotations2 = annotations;
505  annotations2.erase(annotations2.begin() + sql_sizer_pos);
506 
508  sizer,
509  input_args2,
510  output_args,
511  sql_args2,
512  annotations2,
513  is_runtime,
514  uses_manager);
515  auto sig = tf2.getSignature(/* include_name */ true, /* include_output */ false);
516  for (auto it = functions_.begin(); it != functions_.end();) {
517  if (sig == it->second.getSignature(/* include_name */ true,
518  /* include_output */ false) &&
519  ((tf2.isCPU() && it->second.isCPU()) || (tf2.isGPU() && it->second.isGPU()))) {
520  LOG(WARNING)
521  << "The existing (1) and added (2) table functions have the same signature `"
522  << sig << "`:\n"
523  << " 1: " << it->second.toString() << "\n 2: " << tf2.toString() << "\n";
524  }
525  ++it;
526  }
528  }
529 }
#define LOG(tag)
Definition: Logger.h:285
#define DEFAULT_ROW_MULTIPLIER_SUFFIX
bool is_table_function_whitelisted(std::string_view const function_name)
bool g_enable_dev_table_functions
Definition: Execute.cpp:120
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 611 of file TableFunctionsFactory.cpp.

References get_table_funcs().

612  {
613  std::vector<TableFunction> table_funcs;
614  for (const auto& tf : get_table_funcs(name)) {
615  if (is_gpu ? tf.isGPU() : tf.isCPU()) {
616  table_funcs.emplace_back(tf);
617  }
618  }
619  return table_funcs;
620 }
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 622 of file TableFunctionsFactory.cpp.

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

623  {
624  std::vector<TableFunction> table_funcs;
625  auto table_func_name = name;
626  boost::algorithm::to_lower(table_func_name);
627  for (const auto& pair : functions_) {
628  auto fname = drop_suffix_impl(pair.first);
629  if (fname == table_func_name) {
630  table_funcs.push_back(pair.second);
631  }
632  }
633  return table_funcs;
634 }
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 636 of file TableFunctionsFactory.cpp.

References functions_.

636  {
637  std::vector<TableFunction> table_funcs;
638  for (const auto& pair : functions_) {
639  if (pair.second.isRuntime() == is_runtime) {
640  table_funcs.push_back(pair.second);
641  }
642  }
643  return table_funcs;
644 }
static std::unordered_map< std::string, TableFunction > functions_
std::vector< TableFunction > table_functions::TableFunctionsFactory::get_table_funcs ( )
static

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

646  {
647  std::vector<TableFunction> table_funcs;
648  for (const auto& pair : functions_) {
649  table_funcs.push_back(pair.second);
650  }
651  return table_funcs;
652 }
static std::unordered_map< std::string, TableFunction > functions_

+ Here is the caller graph for this function:

template<const char * filename>
static void table_functions::TableFunctionsFactory::init ( )
static
void table_functions::TableFunctionsFactory::reset ( )
static

Definition at line 537 of file TableFunctionsFactory.cpp.

References functions_, and g_enable_table_functions.

Referenced by DBHandler::register_runtime_extension_functions().

537  {
539  return;
540  }
541  for (auto it = functions_.begin(); it != functions_.end();) {
542  if (it->second.isRuntime()) {
543  it = functions_.erase(it);
544  } else {
545  ++it;
546  }
547  }
548 }
static std::unordered_map< std::string, TableFunction > functions_
bool g_enable_table_functions
Definition: Execute.cpp:117

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ::ExtensionFunctionsWhitelist
friend

Definition at line 363 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: