OmniSciDB  bf83d84833
 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_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 58 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:

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

Definition at line 344 of file ExtensionFunctionsBinding.cpp.

Referenced by bind_function().

344  {
345  if (!str.size()) {
346  return false;
347  }
348 
349  if (!(std::isalpha(str[0]) || str[0] == '_')) {
350  return false;
351  }
352 
353  for (size_t i = 1; i < str.size(); i++) {
354  if (!(std::isalnum(str[i]) || str[i] == '_')) {
355  return false;
356  }
357  }
358 
359  return true;
360 }

+ 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 80 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(), 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(), kARRAY, kBIGINT, kBOOLEAN, kCOLUMN, 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().

83  {
84  /*
85  Returns non-negative integer `offset` if `arg_type` and
86  `sig_types[sig_pos:sig_pos + offset]` match.
87 
88  The `offset` value can be interpreted as the number of extension
89  function arguments that is consumed by the given `arg_type`. For
90  instance, for scalar types the offset is always 1, for array
91  types the offset is 2: one argument for array pointer value and
92  one argument for the array size value, etc.
93 
94  Returns -1 when the types of an argument and the corresponding
95  extension function argument(s) mismatch, or when downcasting would
96  be effective.
97 
98  In case of non-negative `offset` result, the function updates
99  penalty_score argument as follows:
100 
101  add 1000 if arg_type is non-scalar, otherwise:
102  add 1000 * sizeof(sig_type) / sizeof(arg_type)
103  add 1000000 if type kinds differ (integer vs double, for instance)
104 
105  */
106  auto stype = sig_types[sig_pos];
107  int max_pos = sig_types.size() - 1;
108  switch (arg_type.get_type()) {
109  case kBOOLEAN:
110  if (stype == ExtArgumentType::Bool) {
111  penalty_score += 1000;
112  return 1;
113  }
114  break;
115  case kTINYINT:
116  switch (stype) {
118  penalty_score += 1000;
119  break;
121  penalty_score += 2000;
122  break;
124  penalty_score += 4000;
125  break;
127  penalty_score += 8000;
128  break;
130  penalty_score += 1008000;
131  break; // temporary: allow integers as double arguments
132  default:
133  return -1;
134  }
135  return 1;
136  case kSMALLINT:
137  switch (stype) {
139  penalty_score += 1000;
140  break;
142  penalty_score += 2000;
143  break;
145  penalty_score += 4000;
146  break;
148  penalty_score += 1004000;
149  break; // temporary: allow integers as double arguments
150  default:
151  return -1;
152  }
153  return 1;
154  case kINT:
155  switch (stype) {
157  penalty_score += 1000;
158  break;
160  penalty_score += 2000;
161  break;
163  penalty_score += 1002000;
164  break; // temporary: allow integers as double arguments
165  default:
166  return -1;
167  }
168  return 1;
169  case kBIGINT:
170  switch (stype) {
172  penalty_score += 1000;
173  break;
175  penalty_score += 1001000;
176  break; // temporary: allow integers as double arguments
177  default:
178  return -1;
179  }
180  return 1;
181  case kFLOAT:
182  switch (stype) {
184  penalty_score += 1000;
185  break;
187  penalty_score += 2000;
188  break; // is it ok to use floats as double arguments?
189  default:
190  return -1;
191  }
192  return 1;
193  case kDOUBLE:
194  if (stype == ExtArgumentType::Double) {
195  penalty_score += 1000;
196  return 1;
197  }
198  break;
199 
200  case kPOINT:
201  case kLINESTRING:
202  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
203  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
204  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
205  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
206  penalty_score += 1000;
207  return 2;
208  } else if (stype == ExtArgumentType::GeoPoint ||
210  penalty_score += 1000;
211  return 1;
212  }
213  break;
214  case kARRAY:
215  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
216  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
217  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
218  stype == ExtArgumentType::PBool) &&
219  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
220  penalty_score += 1000;
221  return 2;
222  } else if (is_ext_arg_type_array(stype)) {
223  // array arguments must match exactly
224  CHECK(arg_type.is_array());
225  const auto stype_ti = ext_arg_type_to_type_info(get_array_arg_elem_type(stype));
226  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
227  /* Boolean array has the same low-level structure as Int8 array. */
228  penalty_score += 1000;
229  return 1;
230  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
231  penalty_score += 1000;
232  return 1;
233  } else {
234  return -1;
235  }
236  }
237  break;
238  case kPOLYGON:
239  if (stype == ExtArgumentType::PInt8 && sig_pos + 3 < max_pos &&
240  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
241  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
242  sig_types[sig_pos + 3] == ExtArgumentType::Int64) {
243  penalty_score += 1000;
244  return 4;
245  } else if (stype == ExtArgumentType::GeoPolygon) {
246  penalty_score += 1000;
247  return 1;
248  }
249 
250  break;
251 
252  case kMULTIPOLYGON:
253  if (stype == ExtArgumentType::PInt8 && sig_pos + 5 < max_pos &&
254  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
255  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
256  sig_types[sig_pos + 3] == ExtArgumentType::Int64 &&
257  sig_types[sig_pos + 4] == ExtArgumentType::PInt32 &&
258  sig_types[sig_pos + 5] == ExtArgumentType::Int64) {
259  penalty_score += 1000;
260  return 6;
261  } else if (stype == ExtArgumentType::GeoMultiPolygon) {
262  penalty_score += 1000;
263  return 1;
264  }
265  break;
266  case kDECIMAL:
267  case kNUMERIC:
268  if (stype == ExtArgumentType::Double && arg_type.get_logical_size() == 8) {
269  penalty_score += 1000;
270  return 1;
271  }
272  if (stype == ExtArgumentType::Float && arg_type.get_logical_size() == 4) {
273  penalty_score += 1000;
274  return 1;
275  }
276  break;
277  case kNULLT: // NULL maps to a pointer and size argument
278  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
279  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
280  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
281  stype == ExtArgumentType::PBool) &&
282  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
283  penalty_score += 1000;
284  return 2;
285  }
286  break;
287  case kCOLUMN:
288  if (is_ext_arg_type_column(stype)) {
289  // column arguments must match exactly
290  const auto stype_ti = ext_arg_type_to_type_info(get_column_arg_elem_type(stype));
291  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
292  /* Boolean column has the same low-level structure as Int8 column. */
293  penalty_score += 1000;
294  return 1;
295  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
296  penalty_score += 1000;
297  return 1;
298  } else {
299  return -1;
300  }
301  }
302  break;
303  case kTEXT:
304  switch (arg_type.get_compression()) {
305  case kENCODING_NONE:
306  if (stype == ExtArgumentType::TextEncodingNone) {
307  penalty_score += 1000;
308  return 1;
309  }
310  return -1;
311  case kENCODING_DICT:
313  penalty_score += 1000;
314  return 1;
315  }
316  default:;
317  // todo: dict(8) and dict(16) encodings
318  }
319  /* Not implemented types:
320  kCHAR
321  kVARCHAR
322  kTIME
323  kTIMESTAMP
324  kDATE
325  kINTERVAL_DAY_TIME
326  kINTERVAL_YEAR_MONTH
327  kGEOMETRY
328  kGEOGRAPHY
329  kEVAL_CONTEXT_TYPE
330  kVOID
331  kCURSOR
332  */
333  default:
334  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
335  ": support for " + arg_type.get_type_name() +
336  "(type=" + std::to_string(arg_type.get_type()) + ")" +
337  +" not implemented: \n pos=" + std::to_string(sig_pos) +
338  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
339  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
340  }
341  return -1;
342 }
ExtArgumentType get_array_arg_elem_type(const ExtArgumentType ext_arg_array_type)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:311
std::string to_string(char const *&&v)
int get_logical_size() const
Definition: sqltypes.h:322
ExtArgumentType get_column_arg_elem_type(const ExtArgumentType ext_arg_column_type)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
Definition: sqltypes.h:51
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
std::string get_type_name() const
Definition: sqltypes.h:414
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
#define CHECK(condition)
Definition: Logger.h:197
Definition: sqltypes.h:44
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:697
bool is_array() const
Definition: sqltypes.h:486
SQLTypeInfo ext_arg_type_to_type_info(const ExtArgumentType ext_arg_type)
bool is_ext_arg_type_column(const ExtArgumentType ext_arg_type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function: