OmniSciDB  4201147b46
 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 160 of file TableFunctionsFactory.cpp.

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

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

160  {
161  if (hasPreFlightOutputSizer()) {
162  return true;
163  }
164  // workaround for default args
165  for (size_t idx = 0; idx < std::min(input_args_.size(), annotations_.size()); idx++) {
166  const auto& ann = getInputAnnotations(idx);
167  if (ann.find("require") != ann.end()) {
168  return true;
169  }
170  }
171  return false;
172 }
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 150 of file TableFunctionsFactory.cpp.

References input_args_, and is_ext_arg_type_scalar().

150  {
151  int32_t scalar_args = 0;
152  for (const auto& ext_arg : input_args_) {
153  if (is_ext_arg_type_scalar(ext_arg)) {
154  scalar_args += 1;
155  }
156  }
157  return scalar_args;
158 }
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 174 of file TableFunctionsFactory.cpp.

References annotations_, CHECK_LE, output_args_, and sql_args_.

175  {
176  CHECK_LE(idx, sql_args_.size() + output_args_.size());
177  if (annotations_.empty() || idx >= annotations_.size()) {
178  static const std::map<std::string, std::string> empty = {};
179  return empty;
180  }
181  return annotations_[idx];
182 }
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:233
const std::string table_functions::TableFunction::getArgNames ( const bool  use_input_args) const

Definition at line 270 of file TableFunctionsFactory.cpp.

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

270  {
271  std::vector<std::string> names;
272  if (use_input_args) {
273  for (size_t idx = 0; idx < sql_args_.size(); idx++) {
274  const std::vector<std::string> cursor_fields = getCursorFields(idx);
275  if (cursor_fields.empty()) {
276  const std::string& name = getInputAnnotation(idx, "name", "''");
277  names.emplace_back(name);
278  } else {
279  names.emplace_back("Cursor<" + boost::algorithm::join(cursor_fields, ", ") + ">");
280  }
281  }
282  } else {
283  for (size_t idx = 0; idx < output_args_.size(); idx++) {
284  const std::string& name = getOutputAnnotation(idx, "name", "''");
285  names.emplace_back(name);
286  }
287  }
288 
289  return "[" + boost::algorithm::join(names, ", ") + "]";
290 }
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 246 of file TableFunctionsFactory.cpp.

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

246  {
247  if (use_input_args) {
248  std::vector<std::string> arg_types;
249  size_t arg_idx = 0;
250  for (size_t sql_idx = 0; sql_idx < sql_args_.size(); sql_idx++) {
251  const std::vector<std::string> cursor_fields = getCursorFields(sql_idx);
252  if (cursor_fields.empty()) {
253  // fields => {}
254  arg_types.emplace_back(
256  } else {
257  std::vector<std::string> vec;
258  for (size_t i = 0; i < cursor_fields.size(); i++) {
259  vec.emplace_back(ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]));
260  }
261  arg_types.emplace_back("Cursor<" + boost::algorithm::join(vec, ", ") + ">");
262  }
263  }
264  return "[" + boost::algorithm::join(arg_types, ", ") + "]";
265  } else {
267  }
268 }
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 233 of file TableFunctionsFactory.cpp.

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

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

234  {
235  std::vector<std::string> fields;
236  const std::string& line = getInputAnnotation(sql_idx, "fields", "");
237  if (line.empty()) {
238  static const std::vector<std::string> empty = {};
239  return empty;
240  }
241  std::string substr = line.substr(1, line.size() - 2);
242  boost::split(fields, substr, boost::is_any_of(", "), boost::token_compress_on);
243  return fields;
244 }
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 222 of file TableFunctionsFactory.cpp.

References getFunctionAnnotations().

224  {
225  const std::map<std::string, std::string> ann = getFunctionAnnotations();
226  const auto& it = ann.find(key);
227  if (it != ann.end()) {
228  return it->second;
229  }
230  return default_;
231 }
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 218 of file TableFunctionsFactory.cpp.

References getAnnotations(), output_args_, and sql_args_.

Referenced by getFunctionAnnotation().

218  {
219  return getAnnotations(sql_args_.size() + output_args_.size());
220 }
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 190 of file TableFunctionsFactory.cpp.

References getInputAnnotations().

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

192  {
193  const std::map<std::string, std::string> ann = getInputAnnotations(input_arg_idx);
194  const auto& it = ann.find(key);
195  if (it != ann.end()) {
196  return it->second;
197  }
198  return default_;
199 }
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 184 of file TableFunctionsFactory.cpp.

References CHECK_LT, getAnnotations(), and input_args_.

Referenced by containsPreFlightFn(), and getInputAnnotation().

185  {
186  CHECK_LT(input_arg_idx, input_args_.size());
187  return getAnnotations(input_arg_idx);
188 }
#define CHECK_LT(x, y)
Definition: Logger.h:232
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 292 of file TableFunctionsFactory.cpp.

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

292  {
293  // if the annotation is of the form args<INT,INT>, it is refering to a column list
294 #define PREFIX_LENGTH 5
295  const auto& annotation = getOutputAnnotations(idx);
296  auto annot = annotation.find("input_id");
297  if (annot == annotation.end()) {
298  size_t lo = 0;
299  for (const auto& ext_arg : input_args_) {
300  switch (ext_arg) {
304  return std::make_pair(lo, 0);
305  default:
306  lo++;
307  }
308  }
309  UNREACHABLE();
310  }
311 
312  const std::string& input_id = annot->second;
313 
314  if (input_id == "args<-1>") {
315  // empty input id! -1 seems to be the magic number used in RelAlgExecutor.cpp
316  return {-1, -1};
317  }
318 
319  size_t comma = input_id.find(",");
320  int32_t gt = input_id.size() - 1;
321  int32_t lo = std::stoi(input_id.substr(PREFIX_LENGTH, comma - 1));
322 
323  if (comma == std::string::npos) {
324  return std::make_pair(lo, 0);
325  }
326  int32_t hi = std::stoi(input_id.substr(comma + 1, gt - comma - 1));
327  return std::make_pair(lo, hi);
328 }
#define PREFIX_LENGTH
#define UNREACHABLE()
Definition: Logger.h:266
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 139 of file TableFunctionsFactory.cpp.

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

139  {
140  CHECK_LT(idx, input_args_.size());
142 }
SQLTypeInfo ext_arg_pointer_type_to_type_info(const ExtArgumentType ext_arg_type)
#define CHECK_LT(x, y)
Definition: Logger.h:232
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 518 of file TableFunctionsFactory.cpp.

References table_functions::anonymous_namespace{TableFunctionsFactory.cpp}::drop_suffix_impl(), name_, run_benchmark_import::result, and to_lower().

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

518  {
519  std::string result = name_;
520  if (drop_suffix) {
521  result = drop_suffix_impl(result);
522  }
523  if (lower) {
525  }
526  return result;
527 }
std::string to_lower(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 207 of file TableFunctionsFactory.cpp.

References getOutputAnnotations().

Referenced by getArgNames().

209  {
210  const std::map<std::string, std::string> ann = getOutputAnnotations(output_arg_idx);
211  const auto& it = ann.find(key);
212  if (it != ann.end()) {
213  return it->second;
214  }
215  return default_;
216 }
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 201 of file TableFunctionsFactory.cpp.

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

Referenced by getInputID(), and getOutputAnnotation().

202  {
203  CHECK_LT(output_arg_idx, output_args_.size());
204  return getAnnotations(output_arg_idx + sql_args_.size());
205 }
const std::vector< ExtArgumentType > output_args_
const std::vector< ExtArgumentType > sql_args_
#define CHECK_LT(x, y)
Definition: Logger.h:232
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 144 of file TableFunctionsFactory.cpp.

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

144  {
145  CHECK_LT(idx, output_args_.size());
146  // TODO(adb): conditionally handle nulls
148 }
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:232

+ 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 561 of file TableFunctionsFactory.cpp.

References getName(), and PREFLIGHT_SUFFIX.

Referenced by TableFunctionCompilationContext::generateTableFunctionCall().

561  {
562  // gets the name of the pre flight function associated with this table function
563  return getName(false, true) + PREFLIGHT_SUFFIX;
564 }
#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 529 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.

530  {
531  std::string sig;
532  if (include_name) {
533  sig += getName(/*drop_suffix=*/true, /*lower=*/true);
534  }
535 
536  size_t arg_idx = 0;
537  std::vector<std::string> args;
538  for (size_t sql_idx = 0; sql_idx < sql_args_.size(); sql_idx++) {
539  const std::vector<std::string> cursor_fields = getCursorFields(sql_idx);
540  if (cursor_fields.empty()) {
541  const auto& type = ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]);
542  const auto& name = getInputAnnotation(sql_idx, "name", "");
543  args.emplace_back(name.empty() ? type : (type + " " + name));
544  } else {
545  std::vector<std::string> vec;
546  for (size_t i = 0; i < cursor_fields.size(); i++) {
547  const auto& type = ExtensionFunctionsWhitelist::toString(input_args_[arg_idx++]);
548  const auto& name = cursor_fields[i];
549  vec.emplace_back((name.empty() ? type : type + " " + name));
550  }
551  args.emplace_back("Cursor<" + boost::algorithm::join(vec, ", ") + ">");
552  }
553  }
554  sig += "(" + boost::algorithm::join(args, ", ") + ")";
555  if (include_output) {
557  }
558  return sig;
559 }
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 330 of file TableFunctionsFactory.cpp.

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

330  {
331  /*
332  This function differs from getOutputRowSizeParameter() since it returns the correct
333  index for the sizer in the sql_args list. For instance, consider the example below:
334 
335  RowMultiplier=4
336  input_args=[{i32*, i64}, {i32*, i64}, {i32*, i64}, i32, {i32*, i64}, {i32*, i64},
337  i32] sql_args=[cursor, i32, cursor, i32]
338 
339  Non-scalar args are aggregated in a cursor inside the sql_args list and the new
340  sizer index is 2 rather than 4 originally specified.
341  */
342 
344  size_t sizer = getOutputRowSizeParameter(); // lookup until reach the sizer arg
345  int32_t ext_arg_index = 0, sql_arg_index = 0;
346 
347  auto same_kind = [&](const ExtArgumentType& ext_arg, const ExtArgumentType& sql_arg) {
348  return ((is_ext_arg_type_scalar(ext_arg) && is_ext_arg_type_scalar(sql_arg)) ||
350  };
351 
352  while ((size_t)ext_arg_index < sizer) {
353  if ((size_t)ext_arg_index == sizer - 1)
354  return sql_arg_index;
355 
356  const auto& ext_arg = input_args_[ext_arg_index];
357  const auto& sql_arg = sql_args_[sql_arg_index];
358 
359  if (same_kind(ext_arg, sql_arg)) {
360  ++ext_arg_index;
361  ++sql_arg_index;
362  } else {
363  CHECK(same_kind(ext_arg, sql_args_[sql_arg_index - 1]));
364  ext_arg_index += 1;
365  }
366  }
367 
368  CHECK(false);
369  }
370 
371  return getOutputRowSizeParameter();
372 }
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:222
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: