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

#include <TableFunctionsFactory.h>

+ Collaboration diagram for table_functions::TableFunction:

Public Member Functions

 TableFunction (const std::string &name, const TableFunctionOutputRowSizer output_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, bool uses_manager)
 
std::vector< ExtArgumentTypegetArgs (const bool ensure_column=false) const
 
const std::vector
< ExtArgumentType > & 
getInputArgs () const
 
const std::vector
< ExtArgumentType > & 
getOutputArgs () const
 
const std::vector
< ExtArgumentType > & 
getSqlArgs () const
 
const std::vector< std::map
< std::string, std::string > > & 
getAnnotations () const
 
const ExtArgumentType getRet () const
 
SQLTypeInfo getInputSQLType (const size_t idx) const
 
SQLTypeInfo getOutputSQLType (const size_t idx) const
 
int32_t countScalarArgs () const
 
size_t getInputsSize () const
 
size_t getOutputsSize () const
 
std::string getName (const bool drop_suffix=false, const bool lower=false) const
 
std::string getSignature (const bool include_name, const bool include_output) const
 
bool hasCompileTimeOutputSizeConstant () const
 
bool hasPreFlightOutputSizer () const
 
bool hasUserSpecifiedOutputSizeConstant () const
 
bool hasConstantOutputSize () const
 
bool hasTableFunctionSpecifiedParameter () const
 
bool hasUserSpecifiedOutputSizeParameter () const
 
bool hasNonUserSpecifiedOutputSize () const
 
bool hasOutputSizeIndependentOfInputSize () const
 
bool hasOutputSizeKnownPreLaunch () const
 
bool hasUserSpecifiedOutputSizeMultiplier () const
 
bool mayRequireCastingInputTypes () const
 
OutputBufferSizeType getOutputRowSizeType () const
 
size_t getOutputRowSizeParameter () const
 
bool containsPreFlightFn () const
 
std::string getPreFlightFnName () const
 
const std::map< std::string,
std::string > 
getAnnotations (const size_t idx) const
 
const std::map< std::string,
std::string > 
getInputAnnotations (const size_t input_arg_idx) const
 
const std::string getInputAnnotation (const size_t input_arg_idx, const std::string &key, const std::string &default_) const
 
const std::map< std::string,
std::string > 
getOutputAnnotations (const size_t output_arg_idx) const
 
const std::string getOutputAnnotation (const size_t output_arg_idx, const std::string &key, const std::string &default_) const
 
const std::string getFunctionAnnotation (const std::string &key, const std::string &default_) const
 
const std::map< std::string,
std::string > 
getFunctionAnnotations () const
 
const std::vector< std::string > getCursorFields (const size_t sql_idx) const
 
const std::string getArgTypes (const bool use_input_args) const
 
const std::string getArgNames (const bool use_input_args) const
 
std::pair< int32_t, int32_t > getInputID (const size_t idx) const
 
size_t getSqlOutputRowSizeParameter () const
 
size_t getOutputRowSizeParameter (const std::vector< SQLTypeInfo > &variant) const
 
bool isRuntime () const
 
bool usesManager () const
 
bool isGPU () const
 
bool isCPU () const
 
bool useDefaultSizer () const
 
std::string toString () const
 
std::string toStringSQL () const
 

Private Attributes

const std::string name_
 
const TableFunctionOutputRowSizer output_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_
 
const bool is_runtime_
 
const bool uses_manager_
 

Detailed Description

Definition at line 126 of file TableFunctionsFactory.h.

Constructor & Destructor Documentation

table_functions::TableFunction::TableFunction ( const std::string &  name,
const TableFunctionOutputRowSizer  output_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,
bool  uses_manager 
)
inline

Definition at line 128 of file TableFunctionsFactory.h.

136  : name_(name)
137  , output_sizer_(output_sizer)
138  , input_args_(input_args)
139  , output_args_(output_args)
140  , sql_args_(sql_args)
141  , annotations_(annotations)
142  , is_runtime_(is_runtime)
const TableFunctionOutputRowSizer output_sizer_
const std::vector< std::map< std::string, std::string > > annotations_
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
const std::vector< ExtArgumentType > input_args_
string name
Definition: setup.in.py:72

Member Function Documentation

bool table_functions::TableFunction::containsPreFlightFn ( ) const

Definition at line 99 of file TableFunctionsFactory.cpp.

References annotations_, getInputAnnotations(), hasPreFlightOutputSizer(), and input_args_.

Referenced by TableFunctionExecutionContext::execute(), and Executor::executeTableFunction().

99  {
100  if (hasPreFlightOutputSizer()) {
101  return true;
102  }
103  // workaround for default args
104  for (size_t idx = 0; idx < std::min(input_args_.size(), annotations_.size()); idx++) {
105  const auto& ann = getInputAnnotations(idx);
106  if (ann.find("require") != ann.end()) {
107  return true;
108  }
109  }
110  return false;
111 }
const std::vector< std::map< std::string, std::string > > annotations_
const std::map< std::string, std::string > getInputAnnotations(const size_t input_arg_idx) const
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32_t table_functions::TableFunction::countScalarArgs ( ) const

Definition at line 89 of file TableFunctionsFactory.cpp.

References input_args_, and is_ext_arg_type_scalar().

89  {
90  int32_t scalar_args = 0;
91  for (const auto& ext_arg : input_args_) {
92  if (is_ext_arg_type_scalar(ext_arg)) {
93  scalar_args += 1;
94  }
95  }
96  return scalar_args;
97 }
bool is_ext_arg_type_scalar(const ExtArgumentType ext_arg_type)
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

const std::vector<std::map<std::string, std::string> >& table_functions::TableFunction::getAnnotations ( ) const
inline

Definition at line 161 of file TableFunctionsFactory.h.

References annotations_.

Referenced by getFunctionAnnotations(), getInputAnnotations(), getOutputAnnotations(), and ThriftSerializers::to_thrift().

161  {
162  return annotations_;
163  }
const std::vector< std::map< std::string, std::string > > annotations_

+ Here is the caller graph for this function:

const std::map< std::string, std::string > table_functions::TableFunction::getAnnotations ( const size_t  idx) const

Definition at line 113 of file TableFunctionsFactory.cpp.

References annotations_, CHECK_LE, output_args_, and sql_args_.

114  {
115  CHECK_LE(idx, sql_args_.size() + output_args_.size());
116  if (annotations_.empty() || idx >= annotations_.size()) {
117  static const std::map<std::string, std::string> empty = {};
118  return empty;
119  }
120  return annotations_[idx];
121 }
const std::vector< std::map< std::string, std::string > > annotations_
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
#define CHECK_LE(x, y)
Definition: Logger.h:304
const std::string table_functions::TableFunction::getArgNames ( const bool  use_input_args) const

Definition at line 209 of file TableFunctionsFactory.cpp.

References getCursorFields(), getInputAnnotation(), getOutputAnnotation(), join(), setup::name, output_args_, and sql_args_.

209  {
210  std::vector<std::string> names;
211  if (use_input_args) {
212  for (size_t idx = 0; idx < sql_args_.size(); idx++) {
213  const std::vector<std::string> cursor_fields = getCursorFields(idx);
214  if (cursor_fields.empty()) {
215  const std::string& name = getInputAnnotation(idx, "name", "''");
216  names.emplace_back(name);
217  } else {
218  names.emplace_back("Cursor<" + boost::algorithm::join(cursor_fields, ", ") + ">");
219  }
220  }
221  } else {
222  for (size_t idx = 0; idx < output_args_.size(); idx++) {
223  const std::string& name = getOutputAnnotation(idx, "name", "''");
224  names.emplace_back(name);
225  }
226  }
227 
228  return "[" + boost::algorithm::join(names, ", ") + "]";
229 }
const std::string getOutputAnnotation(const size_t output_arg_idx, const std::string &key, const std::string &default_) const
std::string join(T const &container, std::string const &delim)
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
const std::string getInputAnnotation(const size_t input_arg_idx, const std::string &key, const std::string &default_) const
const std::vector< std::string > getCursorFields(const size_t sql_idx) const
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

std::vector<ExtArgumentType> table_functions::TableFunction::getArgs ( const bool  ensure_column = false) const
inline

Definition at line 145 of file TableFunctionsFactory.h.

References run_benchmark_import::args, ext_arg_type_ensure_column(), input_args_, and output_args_.

145  {
146  std::vector<ExtArgumentType> args;
147  args.insert(args.end(), input_args_.begin(), input_args_.end());
148  if (ensure_column) {
149  // map row dtype to column type
150  std::for_each(output_args_.begin(), output_args_.end(), [&args](auto t) {
151  args.push_back(ext_arg_type_ensure_column(t));
152  });
153  } else {
154  args.insert(args.end(), output_args_.begin(), output_args_.end());
155  }
156  return args;
157  }
const std::vector< ExtArgumentType > output_args_
ExtArgumentType ext_arg_type_ensure_column(const ExtArgumentType ext_arg_type)
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

const std::string table_functions::TableFunction::getArgTypes ( const bool  use_input_args) const

Definition at line 185 of file TableFunctionsFactory.cpp.

References getCursorFields(), input_args_, join(), output_args_, sql_args_, and ExtensionFunctionsWhitelist::toString().

185  {
186  if (use_input_args) {
187  std::vector<std::string> arg_types;
188  size_t arg_idx = 0;
189  for (size_t sql_idx = 0; sql_idx < sql_args_.size(); sql_idx++) {
190  const std::vector<std::string> cursor_fields = getCursorFields(sql_idx);
191  if (cursor_fields.empty()) {
192  // fields => {}
193  arg_types.emplace_back(
195  } else {
196  std::vector<std::string> vec;
197  for (size_t i = 0; i < cursor_fields.size(); i++) {
198  vec.emplace_back(ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]));
199  }
200  arg_types.emplace_back("Cursor<" + boost::algorithm::join(vec, ", ") + ">");
201  }
202  }
203  return "[" + boost::algorithm::join(arg_types, ", ") + "]";
204  } else {
206  }
207 }
std::string join(T const &container, std::string const &delim)
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
const std::vector< std::string > getCursorFields(const size_t sql_idx) const
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

const std::vector< std::string > table_functions::TableFunction::getCursorFields ( const size_t  sql_idx) const

Definition at line 172 of file TableFunctionsFactory.cpp.

References getInputAnnotation(), parse_ast::line, and split().

Referenced by getArgNames(), getArgTypes(), and getSignature().

173  {
174  std::vector<std::string> fields;
175  const std::string& line = getInputAnnotation(sql_idx, "fields", "");
176  if (line.empty()) {
177  static const std::vector<std::string> empty = {};
178  return empty;
179  }
180  std::string substr = line.substr(1, line.size() - 2);
181  boost::split(fields, substr, boost::is_any_of(", "), boost::token_compress_on);
182  return fields;
183 }
std::vector< std::string > split(std::string_view str, std::string_view delim, std::optional< size_t > maxsplit)
split apart a string into a vector of substrings
const std::string getInputAnnotation(const size_t input_arg_idx, const std::string &key, const std::string &default_) const
tuple line
Definition: parse_ast.py:10

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string table_functions::TableFunction::getFunctionAnnotation ( const std::string &  key,
const std::string &  default_ 
) const

Definition at line 161 of file TableFunctionsFactory.cpp.

References getFunctionAnnotations().

163  {
164  const std::map<std::string, std::string> ann = getFunctionAnnotations();
165  const auto& it = ann.find(key);
166  if (it != ann.end()) {
167  return it->second;
168  }
169  return default_;
170 }
const std::map< std::string, std::string > getFunctionAnnotations() const

+ Here is the call graph for this function:

const std::map< std::string, std::string > table_functions::TableFunction::getFunctionAnnotations ( ) const

Definition at line 157 of file TableFunctionsFactory.cpp.

References getAnnotations(), output_args_, and sql_args_.

Referenced by getFunctionAnnotation().

157  {
158  return getAnnotations(sql_args_.size() + output_args_.size());
159 }
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
const std::vector< std::map< std::string, std::string > > & getAnnotations() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string table_functions::TableFunction::getInputAnnotation ( const size_t  input_arg_idx,
const std::string &  key,
const std::string &  default_ 
) const

Definition at line 129 of file TableFunctionsFactory.cpp.

References getInputAnnotations().

Referenced by getArgNames(), getCursorFields(), and getSignature().

131  {
132  const std::map<std::string, std::string> ann = getInputAnnotations(input_arg_idx);
133  const auto& it = ann.find(key);
134  if (it != ann.end()) {
135  return it->second;
136  }
137  return default_;
138 }
const std::map< std::string, std::string > getInputAnnotations(const size_t input_arg_idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::map< std::string, std::string > table_functions::TableFunction::getInputAnnotations ( const size_t  input_arg_idx) const

Definition at line 123 of file TableFunctionsFactory.cpp.

References CHECK_LT, getAnnotations(), and input_args_.

Referenced by containsPreFlightFn(), and getInputAnnotation().

124  {
125  CHECK_LT(input_arg_idx, input_args_.size());
126  return getAnnotations(input_arg_idx);
127 }
#define CHECK_LT(x, y)
Definition: Logger.h:303
const std::vector< ExtArgumentType > input_args_
const std::vector< std::map< std::string, std::string > > & getAnnotations() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<ExtArgumentType>& table_functions::TableFunction::getInputArgs ( ) const
inline

Definition at line 158 of file TableFunctionsFactory.h.

References input_args_.

Referenced by ThriftSerializers::to_thrift().

158 { return input_args_; }
const std::vector< ExtArgumentType > input_args_

+ Here is the caller graph for this function:

std::pair< int32_t, int32_t > table_functions::TableFunction::getInputID ( const size_t  idx) const

Definition at line 231 of file TableFunctionsFactory.cpp.

References ColumnListTextEncodingDict, ColumnTextEncodingDict, getOutputAnnotations(), input_args_, PREFIX_LENGTH, TextEncodingDict, and UNREACHABLE.

231  {
232  // if the annotation is of the form args<INT,INT>, it is refering to a column list
233 #define PREFIX_LENGTH 5
234  const auto& annotation = getOutputAnnotations(idx);
235  auto annot = annotation.find("input_id");
236  if (annot == annotation.end()) {
237  size_t lo = 0;
238  for (const auto& ext_arg : input_args_) {
239  switch (ext_arg) {
243  return std::make_pair(lo, 0);
244  default:
245  lo++;
246  }
247  }
248  UNREACHABLE();
249  }
250 
251  const std::string& input_id = annot->second;
252 
253  if (input_id == "args<-1>") {
254  // empty input id! -1 seems to be the magic number used in RelAlgExecutor.cpp
255  return {-1, -1};
256  }
257 
258  size_t comma = input_id.find(",");
259  int32_t gt = input_id.size() - 1;
260  int32_t lo = std::stoi(input_id.substr(PREFIX_LENGTH, comma - 1));
261 
262  if (comma == std::string::npos) {
263  return std::make_pair(lo, 0);
264  }
265  int32_t hi = std::stoi(input_id.substr(comma + 1, gt - comma - 1));
266  return std::make_pair(lo, hi);
267 }
#define PREFIX_LENGTH
#define UNREACHABLE()
Definition: Logger.h:337
const std::map< std::string, std::string > getOutputAnnotations(const size_t output_arg_idx) const
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

SQLTypeInfo table_functions::TableFunction::getInputSQLType ( const size_t  idx) const

Definition at line 78 of file TableFunctionsFactory.cpp.

References CHECK_LT, table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::ext_arg_pointer_type_to_type_info(), and input_args_.

78  {
79  CHECK_LT(idx, input_args_.size());
81 }
SQLTypeInfo ext_arg_pointer_type_to_type_info(const ExtArgumentType ext_arg_type)
#define CHECK_LT(x, y)
Definition: Logger.h:303
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

size_t table_functions::TableFunction::getInputsSize ( ) const
inline

Definition at line 171 of file TableFunctionsFactory.h.

References input_args_.

171 { return input_args_.size(); }
const std::vector< ExtArgumentType > input_args_
std::string table_functions::TableFunction::getName ( const bool  drop_suffix = false,
const bool  lower = false 
) const

Definition at line 476 of file TableFunctionsFactory.cpp.

References anonymous_namespace{RowFunctionManager.h}::drop_suffix_impl(), name_, run_benchmark_import::result, and to_lower().

Referenced by TableFunctionCompilationContext::compile(), TableFunctionCompilationContext::generateTableFunctionCall(), getPreFlightFnName(), getSignature(), and ThriftSerializers::to_thrift().

476  {
477  std::string result = name_;
478  if (drop_suffix) {
479  result = drop_suffix_impl(result);
480  }
481  if (lower) {
483  }
484  return result;
485 }
std::string to_lower(const std::string &str)
std::string drop_suffix_impl(const std::string &str)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string table_functions::TableFunction::getOutputAnnotation ( const size_t  output_arg_idx,
const std::string &  key,
const std::string &  default_ 
) const

Definition at line 146 of file TableFunctionsFactory.cpp.

References getOutputAnnotations().

Referenced by getArgNames().

148  {
149  const std::map<std::string, std::string> ann = getOutputAnnotations(output_arg_idx);
150  const auto& it = ann.find(key);
151  if (it != ann.end()) {
152  return it->second;
153  }
154  return default_;
155 }
const std::map< std::string, std::string > getOutputAnnotations(const size_t output_arg_idx) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::map< std::string, std::string > table_functions::TableFunction::getOutputAnnotations ( const size_t  output_arg_idx) const

Definition at line 140 of file TableFunctionsFactory.cpp.

References CHECK_LT, getAnnotations(), output_args_, and sql_args_.

Referenced by getInputID(), and getOutputAnnotation().

141  {
142  CHECK_LT(output_arg_idx, output_args_.size());
143  return getAnnotations(output_arg_idx + sql_args_.size());
144 }
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
#define CHECK_LT(x, y)
Definition: Logger.h:303
const std::vector< std::map< std::string, std::string > > & getAnnotations() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::vector<ExtArgumentType>& table_functions::TableFunction::getOutputArgs ( ) const
inline

Definition at line 159 of file TableFunctionsFactory.h.

References output_args_.

Referenced by ThriftSerializers::to_thrift().

159 { return output_args_; }
const std::vector< ExtArgumentType > output_args_

+ Here is the caller graph for this function:

size_t table_functions::TableFunction::getOutputRowSizeParameter ( ) const
inline

Definition at line 239 of file TableFunctionsFactory.h.

References output_sizer_, and table_functions::TableFunctionOutputRowSizer::val.

Referenced by getSqlOutputRowSizeParameter(), and ThriftSerializers::to_thrift().

+ Here is the caller graph for this function:

size_t table_functions::TableFunction::getOutputRowSizeParameter ( const std::vector< SQLTypeInfo > &  variant) const
inline

Definition at line 266 of file TableFunctionsFactory.h.

References hasUserSpecifiedOutputSizeMultiplier(), output_sizer_, and table_functions::TableFunctionOutputRowSizer::val.

266  {
267  auto val = output_sizer_.val;
269  size_t col_index = 0;
270  size_t func_arg_index = 0;
271  for (const auto& ti : variant) {
272  func_arg_index++;
273  if (ti.is_column_list()) {
274  col_index += ti.get_dimension();
275  } else {
276  col_index++;
277  }
278  if (func_arg_index == val) {
279  val = col_index;
280  break;
281  }
282  }
283  }
284  return val;
285  }
const TableFunctionOutputRowSizer output_sizer_

+ Here is the call graph for this function:

OutputBufferSizeType table_functions::TableFunction::getOutputRowSizeType ( ) const
inline

Definition at line 237 of file TableFunctionsFactory.h.

References output_sizer_, and table_functions::TableFunctionOutputRowSizer::type.

Referenced by anonymous_namespace{TableFunctionExecutionContext.cpp}::get_output_row_count(), and ThriftSerializers::to_thrift().

237 { return output_sizer_.type; }
const TableFunctionOutputRowSizer output_sizer_

+ Here is the caller graph for this function:

SQLTypeInfo table_functions::TableFunction::getOutputSQLType ( const size_t  idx) const

Definition at line 83 of file TableFunctionsFactory.cpp.

References CHECK_LT, table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::ext_arg_type_to_type_info_output(), and output_args_.

83  {
84  CHECK_LT(idx, output_args_.size());
85  // TODO(adb): conditionally handle nulls
87 }
SQLTypeInfo ext_arg_type_to_type_info_output(const ExtArgumentType ext_arg_type)
const std::vector< ExtArgumentType > output_args_
#define CHECK_LT(x, y)
Definition: Logger.h:303

+ Here is the call graph for this function:

size_t table_functions::TableFunction::getOutputsSize ( ) const
inline

Definition at line 172 of file TableFunctionsFactory.h.

References output_args_.

172 { return output_args_.size(); }
const std::vector< ExtArgumentType > output_args_
std::string table_functions::TableFunction::getPreFlightFnName ( ) const

Definition at line 519 of file TableFunctionsFactory.cpp.

References getName(), and PREFLIGHT_SUFFIX.

Referenced by TableFunctionCompilationContext::generateTableFunctionCall().

519  {
520  // gets the name of the pre flight function associated with this table function
521  return getName(false, true) + PREFLIGHT_SUFFIX;
522 }
#define PREFLIGHT_SUFFIX
std::string getName(const bool drop_suffix=false, const bool lower=false) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const ExtArgumentType table_functions::TableFunction::getRet ( ) const
inline

Definition at line 164 of file TableFunctionsFactory.h.

References Int32.

std::string table_functions::TableFunction::getSignature ( const bool  include_name,
const bool  include_output 
) const

Definition at line 487 of file TableFunctionsFactory.cpp.

References run_benchmark_import::args, getCursorFields(), getInputAnnotation(), getName(), input_args_, join(), setup::name, output_args_, sql_args_, ExtensionFunctionsWhitelist::toString(), and run_benchmark_import::type.

488  {
489  std::string sig;
490  if (include_name) {
491  sig += getName(/*drop_suffix=*/true, /*lower=*/true);
492  }
493 
494  size_t arg_idx = 0;
495  std::vector<std::string> args;
496  for (size_t sql_idx = 0; sql_idx < sql_args_.size(); sql_idx++) {
497  const std::vector<std::string> cursor_fields = getCursorFields(sql_idx);
498  if (cursor_fields.empty()) {
499  const auto& type = ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]);
500  const auto& name = getInputAnnotation(sql_idx, "name", "");
501  args.emplace_back(name.empty() ? type : (type + " " + name));
502  } else {
503  std::vector<std::string> vec;
504  for (size_t i = 0; i < cursor_fields.size(); i++) {
505  const auto& type = ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]);
506  const auto& name = cursor_fields[i];
507  vec.emplace_back((name.empty() ? type : type + " " + name));
508  }
509  args.emplace_back("Cursor<" + boost::algorithm::join(vec, ", ") + ">");
510  }
511  }
512  sig += "(" + boost::algorithm::join(args, ", ") + ")";
513  if (include_output) {
515  }
516  return sig;
517 }
std::string join(T const &container, std::string const &delim)
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
const std::string getInputAnnotation(const size_t input_arg_idx, const std::string &key, const std::string &default_) const
std::string getName(const bool drop_suffix=false, const bool lower=false) const
const std::vector< std::string > getCursorFields(const size_t sql_idx) const
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
const std::vector< ExtArgumentType > input_args_
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

const std::vector<ExtArgumentType>& table_functions::TableFunction::getSqlArgs ( ) const
inline

Definition at line 160 of file TableFunctionsFactory.h.

References sql_args_.

Referenced by ThriftSerializers::to_thrift().

160 { return sql_args_; }
const std::vector< ExtArgumentType > sql_args_

+ Here is the caller graph for this function:

size_t table_functions::TableFunction::getSqlOutputRowSizeParameter ( ) const

Definition at line 269 of file TableFunctionsFactory.cpp.

References CHECK, getOutputRowSizeParameter(), hasUserSpecifiedOutputSizeMultiplier(), input_args_, is_ext_arg_type_nonscalar(), is_ext_arg_type_scalar(), and sql_args_.

269  {
270  /*
271  This function differs from getOutputRowSizeParameter() since it returns the correct
272  index for the sizer in the sql_args list. For instance, consider the example below:
273 
274  RowMultiplier=4
275  input_args=[{i32*, i64}, {i32*, i64}, {i32*, i64}, i32, {i32*, i64}, {i32*, i64},
276  i32] sql_args=[cursor, i32, cursor, i32]
277 
278  Non-scalar args are aggregated in a cursor inside the sql_args list and the new
279  sizer index is 2 rather than 4 originally specified.
280  */
281 
283  size_t sizer = getOutputRowSizeParameter(); // lookup until reach the sizer arg
284  int32_t ext_arg_index = 0, sql_arg_index = 0;
285 
286  auto same_kind = [&](const ExtArgumentType& ext_arg, const ExtArgumentType& sql_arg) {
287  return ((is_ext_arg_type_scalar(ext_arg) && is_ext_arg_type_scalar(sql_arg)) ||
289  };
290 
291  while ((size_t)ext_arg_index < sizer) {
292  if ((size_t)ext_arg_index == sizer - 1)
293  return sql_arg_index;
294 
295  const auto& ext_arg = input_args_[ext_arg_index];
296  const auto& sql_arg = sql_args_[sql_arg_index];
297 
298  if (same_kind(ext_arg, sql_arg)) {
299  ++ext_arg_index;
300  ++sql_arg_index;
301  } else {
302  CHECK(same_kind(ext_arg, sql_args_[sql_arg_index - 1]));
303  ext_arg_index += 1;
304  }
305  }
306 
307  CHECK(false);
308  }
309 
310  return getOutputRowSizeParameter();
311 }
bool is_ext_arg_type_scalar(const ExtArgumentType ext_arg_type)
bool is_ext_arg_type_nonscalar(const ExtArgumentType ext_arg_type)
const std::vector< ExtArgumentType > sql_args_
#define CHECK(condition)
Definition: Logger.h:291
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

bool table_functions::TableFunction::hasCompileTimeOutputSizeConstant ( ) const
inline
bool table_functions::TableFunction::hasPreFlightOutputSizer ( ) const
inline

Definition at line 182 of file TableFunctionsFactory.h.

References table_functions::kPreFlightParameter, output_sizer_, and table_functions::TableFunctionOutputRowSizer::type.

Referenced by containsPreFlightFn(), and TableFunctionCompilationContext::generateEntryPoint().

+ Here is the caller graph for this function:

bool table_functions::TableFunction::hasTableFunctionSpecifiedParameter ( ) const
inline

Definition at line 195 of file TableFunctionsFactory.h.

References table_functions::kTableFunctionSpecifiedParameter, output_sizer_, and table_functions::TableFunctionOutputRowSizer::type.

Referenced by Executor::executeTableFunction(), and TableFunctionExecutionContext::launchGpuCode().

+ Here is the caller graph for this function:

bool table_functions::TableFunction::hasUserSpecifiedOutputSizeMultiplier ( ) const
inline

Definition at line 223 of file TableFunctionsFactory.h.

References table_functions::kUserSpecifiedRowMultiplier, output_sizer_, and table_functions::TableFunctionOutputRowSizer::type.

Referenced by getOutputRowSizeParameter(), and getSqlOutputRowSizeParameter().

+ Here is the caller graph for this function:

bool table_functions::TableFunction::isCPU ( ) const
inline

Definition at line 295 of file TableFunctionsFactory.h.

References name_, and usesManager().

295  {
296  return usesManager() || (name_.find("_gpu_", name_.find("__")) == std::string::npos);
297  }

+ Here is the call graph for this function:

bool table_functions::TableFunction::isGPU ( ) const
inline

Definition at line 291 of file TableFunctionsFactory.h.

References name_, and usesManager().

291  {
292  return !usesManager() && (name_.find("_cpu_", name_.find("__")) == std::string::npos);
293  }

+ Here is the call graph for this function:

bool table_functions::TableFunction::isRuntime ( ) const
inline

Definition at line 287 of file TableFunctionsFactory.h.

References is_runtime_.

Referenced by TableFunctionCompilationContext::passColumnsByValue().

287 { return is_runtime_; }

+ Here is the caller graph for this function:

bool table_functions::TableFunction::mayRequireCastingInputTypes ( ) const
inline

Definition at line 227 of file TableFunctionsFactory.h.

References ColumnTimestamp, input_args_, and Timestamp.

Referenced by TableFunctionCompilationContext::generateEntryPoint().

227  {
228  for (auto& input : input_args_) {
229  if (input == ExtArgumentType::Timestamp ||
231  return true;
232  }
233  }
234  return false;
235  }
const std::vector< ExtArgumentType > input_args_

+ Here is the caller graph for this function:

std::string table_functions::TableFunction::toString ( ) const
inline

Definition at line 304 of file TableFunctionsFactory.h.

References annotations_, input_args_, is_runtime_, name_, output_args_, output_sizer_, run_benchmark_import::result, sql_args_, ExtensionFunctionsWhitelist::toString(), and uses_manager_.

304  {
305  auto result = "TableFunction(" + name_ + ", input_args=[";
307  result += "], output_args=[";
309  result += "], sql_args=[";
311  result += "], is_runtime=" + std::string((is_runtime_ ? "true" : "false"));
312  result += ", uses_manager=" + std::string((uses_manager_ ? "true" : "false"));
313  result += ", sizer=" + ::toString(output_sizer_);
314  result += ", annotations=[";
315  for (auto annotation : annotations_) {
316  if (annotation.empty()) {
317  result += "{}, ";
318  } else {
319  result += "{";
320  for (auto it : annotation) {
321  result += ::toString(it.first) + ": " + ::toString(it.second);
322  }
323  result += "}, ";
324  }
325  }
326  result += "])";
327  return result;
328  }
const TableFunctionOutputRowSizer output_sizer_
const std::vector< std::map< std::string, std::string > > annotations_
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
const std::vector< ExtArgumentType > input_args_

+ Here is the call graph for this function:

std::string table_functions::TableFunction::toStringSQL ( ) const
inline

Definition at line 330 of file TableFunctionsFactory.h.

References input_args_, name_, output_args_, run_benchmark_import::result, and ExtensionFunctionsWhitelist::toStringSQL().

330  {
331  auto result = name_ + "(";
333  result += ") -> (";
335  result += ")";
336  return result;
337  }
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > input_args_
static std::string toStringSQL(const std::vector< ExtArgumentType > &sig_types)

+ Here is the call graph for this function:

bool table_functions::TableFunction::useDefaultSizer ( ) const
inline

Definition at line 299 of file TableFunctionsFactory.h.

References name_.

299  {
300  // Functions that use a default sizer value have one less argument
301  return (name_.find("_default_", name_.find("__")) != std::string::npos);
302  }
bool table_functions::TableFunction::usesManager ( ) const
inline

Definition at line 289 of file TableFunctionsFactory.h.

References uses_manager_.

Referenced by TableFunctionCompilationContext::generateCastsForInputTypes(), TableFunctionCompilationContext::generateEntryPoint(), isCPU(), and isGPU().

+ Here is the caller graph for this function:

Member Data Documentation

const std::vector<std::map<std::string, std::string> > table_functions::TableFunction::annotations_
private

Definition at line 345 of file TableFunctionsFactory.h.

Referenced by containsPreFlightFn(), getAnnotations(), and toString().

const bool table_functions::TableFunction::is_runtime_
private

Definition at line 346 of file TableFunctionsFactory.h.

Referenced by isRuntime(), and toString().

const std::string table_functions::TableFunction::name_
private

Definition at line 340 of file TableFunctionsFactory.h.

Referenced by getName(), isCPU(), isGPU(), toString(), toStringSQL(), and useDefaultSizer().

const std::vector<ExtArgumentType> table_functions::TableFunction::sql_args_
private
const bool table_functions::TableFunction::uses_manager_
private

Definition at line 347 of file TableFunctionsFactory.h.

Referenced by toString(), and usesManager().


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