OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anonymous_namespace{ExtensionFunctionsBinding.cpp} Namespace Reference

Functions

ExtArgumentType get_column_arg_elem_type (const ExtArgumentType ext_arg_column_type)
 
ExtArgumentType get_column_list_arg_elem_type (const ExtArgumentType ext_arg_column_list_type)
 
ExtArgumentType get_array_arg_elem_type (const ExtArgumentType ext_arg_array_type)
 
static int match_arguments (const SQLTypeInfo &arg_type, int sig_pos, const std::vector< ExtArgumentType > &sig_types, int &penalty_score)
 
bool is_valid_identifier (std::string str)
 

Function Documentation

ExtArgumentType anonymous_namespace{ExtensionFunctionsBinding.cpp}::get_array_arg_elem_type ( const ExtArgumentType  ext_arg_array_type)

Definition at line 81 of file ExtensionFunctionsBinding.cpp.

References ArrayBool, ArrayDouble, ArrayFloat, ArrayInt16, ArrayInt32, ArrayInt64, ArrayInt8, Bool, Double, Float, Int16, Int32, Int64, Int8, and UNREACHABLE.

Referenced by match_arguments().

+ Here is the caller graph for this function:

ExtArgumentType anonymous_namespace{ExtensionFunctionsBinding.cpp}::get_column_arg_elem_type ( const ExtArgumentType  ext_arg_column_type)

Definition at line 36 of file ExtensionFunctionsBinding.cpp.

References Bool, ColumnBool, ColumnDouble, ColumnFloat, ColumnInt16, ColumnInt32, ColumnInt64, ColumnInt8, Double, Float, Int16, Int32, Int64, Int8, and UNREACHABLE.

Referenced by match_arguments().

+ Here is the caller graph for this function:

ExtArgumentType anonymous_namespace{ExtensionFunctionsBinding.cpp}::get_column_list_arg_elem_type ( const ExtArgumentType  ext_arg_column_list_type)

Definition at line 58 of file ExtensionFunctionsBinding.cpp.

References Bool, ColumnListBool, ColumnListDouble, ColumnListFloat, ColumnListInt16, ColumnListInt32, ColumnListInt64, ColumnListInt8, Double, Float, Int16, Int32, Int64, Int8, and UNREACHABLE.

Referenced by match_arguments().

+ Here is the caller graph for this function:

bool anonymous_namespace{ExtensionFunctionsBinding.cpp}::is_valid_identifier ( std::string  str)

Definition at line 387 of file ExtensionFunctionsBinding.cpp.

References i.

Referenced by bind_function().

387  {
388  if (!str.size()) {
389  return false;
390  }
391 
392  if (!(std::isalpha(str[0]) || str[0] == '_')) {
393  return false;
394  }
395 
396  for (size_t i = 1; i < str.size(); i++) {
397  if (!(std::isalnum(str[i]) || str[i] == '_')) {
398  return false;
399  }
400  }
401 
402  return true;
403 }

+ Here is the caller graph for this function:

static int anonymous_namespace{ExtensionFunctionsBinding.cpp}::match_arguments ( const SQLTypeInfo arg_type,
int  sig_pos,
const std::vector< ExtArgumentType > &  sig_types,
int &  penalty_score 
)
static

Definition at line 103 of file ExtensionFunctionsBinding.cpp.

References Bool, CHECK, Double, ext_arg_type_to_type_info(), Float, GeoLineString, GeoMultiPolygon, GeoPoint, GeoPolygon, get_array_arg_elem_type(), get_column_arg_elem_type(), get_column_list_arg_elem_type(), SQLTypeInfo::get_compression(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), Int16, Int32, Int64, Int8, SQLTypeInfo::is_array(), is_ext_arg_type_array(), is_ext_arg_type_column(), is_ext_arg_type_column_list(), kARRAY, kBIGINT, kBOOLEAN, kCOLUMN, kCOLUMN_LIST, kDECIMAL, kDOUBLE, kENCODING_DICT, kENCODING_NONE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNULLT, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTEXT, kTINYINT, PBool, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, TextEncodingDict32, TextEncodingNone, to_string(), and ExtensionFunctionsWhitelist::toString().

Referenced by bind_function().

106  {
107  /*
108  Returns non-negative integer `offset` if `arg_type` and
109  `sig_types[sig_pos:sig_pos + offset]` match.
110 
111  The `offset` value can be interpreted as the number of extension
112  function arguments that is consumed by the given `arg_type`. For
113  instance, for scalar types the offset is always 1, for array
114  types the offset is 2: one argument for array pointer value and
115  one argument for the array size value, etc.
116 
117  Returns -1 when the types of an argument and the corresponding
118  extension function argument(s) mismatch, or when downcasting would
119  be effective.
120 
121  In case of non-negative `offset` result, the function updates
122  penalty_score argument as follows:
123 
124  add 1000 if arg_type is non-scalar, otherwise:
125  add 1000 * sizeof(sig_type) / sizeof(arg_type)
126  add 1000000 if type kinds differ (integer vs double, for instance)
127 
128  */
129  int max_pos = sig_types.size() - 1;
130  if (sig_pos > max_pos) {
131  return -1;
132  }
133  auto stype = sig_types[sig_pos];
134  switch (arg_type.get_type()) {
135  case kBOOLEAN:
136  if (stype == ExtArgumentType::Bool) {
137  penalty_score += 1000;
138  return 1;
139  }
140  break;
141  case kTINYINT:
142  switch (stype) {
144  penalty_score += 1000;
145  break;
147  penalty_score += 2000;
148  break;
150  penalty_score += 4000;
151  break;
153  penalty_score += 8000;
154  break;
156  penalty_score += 1008000;
157  break; // temporary: allow integers as double arguments
158  default:
159  return -1;
160  }
161  return 1;
162  case kSMALLINT:
163  switch (stype) {
165  penalty_score += 1000;
166  break;
168  penalty_score += 2000;
169  break;
171  penalty_score += 4000;
172  break;
174  penalty_score += 1004000;
175  break; // temporary: allow integers as double arguments
176  default:
177  return -1;
178  }
179  return 1;
180  case kINT:
181  switch (stype) {
183  penalty_score += 1000;
184  break;
186  penalty_score += 2000;
187  break;
189  penalty_score += 1002000;
190  break; // temporary: allow integers as double arguments
191  default:
192  return -1;
193  }
194  return 1;
195  case kBIGINT:
196  switch (stype) {
198  penalty_score += 1000;
199  break;
201  penalty_score += 1001000;
202  break; // temporary: allow integers as double arguments
203  default:
204  return -1;
205  }
206  return 1;
207  case kFLOAT:
208  switch (stype) {
210  penalty_score += 1000;
211  break;
213  penalty_score += 2000;
214  break; // is it ok to use floats as double arguments?
215  default:
216  return -1;
217  }
218  return 1;
219  case kDOUBLE:
220  if (stype == ExtArgumentType::Double) {
221  penalty_score += 1000;
222  return 1;
223  }
224  break;
225 
226  case kPOINT:
227  case kLINESTRING:
228  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
229  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
230  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
231  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
232  penalty_score += 1000;
233  return 2;
234  } else if (stype == ExtArgumentType::GeoPoint ||
236  penalty_score += 1000;
237  return 1;
238  }
239  break;
240  case kARRAY:
241  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
242  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
243  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
244  stype == ExtArgumentType::PBool) &&
245  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
246  penalty_score += 1000;
247  return 2;
248  } else if (is_ext_arg_type_array(stype)) {
249  // array arguments must match exactly
250  CHECK(arg_type.is_array());
251  const auto stype_ti = ext_arg_type_to_type_info(get_array_arg_elem_type(stype));
252  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
253  /* Boolean array has the same low-level structure as Int8 array. */
254  penalty_score += 1000;
255  return 1;
256  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
257  penalty_score += 1000;
258  return 1;
259  } else {
260  return -1;
261  }
262  }
263  break;
264  case kPOLYGON:
265  if (stype == ExtArgumentType::PInt8 && sig_pos + 3 < max_pos &&
266  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
267  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
268  sig_types[sig_pos + 3] == ExtArgumentType::Int64) {
269  penalty_score += 1000;
270  return 4;
271  } else if (stype == ExtArgumentType::GeoPolygon) {
272  penalty_score += 1000;
273  return 1;
274  }
275 
276  break;
277 
278  case kMULTIPOLYGON:
279  if (stype == ExtArgumentType::PInt8 && sig_pos + 5 < max_pos &&
280  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
281  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
282  sig_types[sig_pos + 3] == ExtArgumentType::Int64 &&
283  sig_types[sig_pos + 4] == ExtArgumentType::PInt32 &&
284  sig_types[sig_pos + 5] == ExtArgumentType::Int64) {
285  penalty_score += 1000;
286  return 6;
287  } else if (stype == ExtArgumentType::GeoMultiPolygon) {
288  penalty_score += 1000;
289  return 1;
290  }
291  break;
292  case kDECIMAL:
293  case kNUMERIC:
294  if (stype == ExtArgumentType::Double && arg_type.get_logical_size() == 8) {
295  penalty_score += 1000;
296  return 1;
297  }
298  if (stype == ExtArgumentType::Float && arg_type.get_logical_size() == 4) {
299  penalty_score += 1000;
300  return 1;
301  }
302  break;
303  case kNULLT: // NULL maps to a pointer and size argument
304  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
305  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
306  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
307  stype == ExtArgumentType::PBool) &&
308  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
309  penalty_score += 1000;
310  return 2;
311  }
312  break;
313  case kCOLUMN:
314  if (is_ext_arg_type_column(stype)) {
315  // column arguments must match exactly
316  const auto stype_ti = ext_arg_type_to_type_info(get_column_arg_elem_type(stype));
317  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
318  /* Boolean column has the same low-level structure as Int8 column. */
319  penalty_score += 1000;
320  return 1;
321  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
322  penalty_score += 1000;
323  return 1;
324  } else {
325  return -1;
326  }
327  }
328  break;
329  case kCOLUMN_LIST:
330  if (is_ext_arg_type_column_list(stype)) {
331  // column_list arguments must match exactly
332  const auto stype_ti =
334  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
335  /* Boolean column_list has the same low-level structure as Int8 column_list. */
336  penalty_score += 10000;
337  return 1;
338  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
339  penalty_score += 10000;
340  return 1;
341  } else {
342  return -1;
343  }
344  }
345  break;
346  case kTEXT:
347  switch (arg_type.get_compression()) {
348  case kENCODING_NONE:
349  if (stype == ExtArgumentType::TextEncodingNone) {
350  penalty_score += 1000;
351  return 1;
352  }
353  return -1;
354  case kENCODING_DICT:
356  penalty_score += 1000;
357  return 1;
358  }
359  default:;
360  // todo: dict(8) and dict(16) encodings
361  }
362  /* Not implemented types:
363  kCHAR
364  kVARCHAR
365  kTIME
366  kTIMESTAMP
367  kDATE
368  kINTERVAL_DAY_TIME
369  kINTERVAL_YEAR_MONTH
370  kGEOMETRY
371  kGEOGRAPHY
372  kEVAL_CONTEXT_TYPE
373  kVOID
374  kCURSOR
375  */
376  default:
377  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
378  ": support for " + arg_type.get_type_name() +
379  "(type=" + std::to_string(arg_type.get_type()) + ")" +
380  +" not implemented: \n pos=" + std::to_string(sig_pos) +
381  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
382  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
383  }
384  return -1;
385 }
ExtArgumentType get_array_arg_elem_type(const ExtArgumentType ext_arg_array_type)
bool is_ext_arg_type_column(const ExtArgumentType ext_arg_type)
ExtArgumentType get_column_list_arg_elem_type(const ExtArgumentType ext_arg_column_list_type)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:314
std::string to_string(char const *&&v)
bool is_ext_arg_type_column_list(const ExtArgumentType ext_arg_type)
int get_logical_size() const
Definition: sqltypes.h:325
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
ExtArgumentType get_column_arg_elem_type(const ExtArgumentType ext_arg_column_type)
Definition: sqltypes.h:51
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
std::string get_type_name() const
Definition: sqltypes.h:417
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
#define CHECK(condition)
Definition: Logger.h:203
Definition: sqltypes.h:44
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:713
bool is_array() const
Definition: sqltypes.h:497
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: