OmniSciDB  dfae7c3b14
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)
 

Function Documentation

◆ get_array_arg_elem_type()

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:

◆ get_column_arg_elem_type()

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:

◆ match_arguments()

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_elem_type(), SQLTypeInfo::get_logical_size(), SQLTypeInfo::get_type(), SQLTypeInfo::get_type_name(), Int16, Int32, Int64, Int8, SQLTypeInfo::is_array(), SQLTypeInfo::is_column(), is_ext_arg_type_array(), is_ext_arg_type_column(), kARRAY, kBIGINT, kBOOLEAN, kCOLUMN, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNULLT, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTINYINT, PBool, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, 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  CHECK(arg_type.is_column());
291  const auto stype_ti = ext_arg_type_to_type_info(get_column_arg_elem_type(stype));
292  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
293  /* Boolean column has the same low-level structure as Int8 column. */
294  penalty_score += 1000;
295  return 1;
296  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
297  penalty_score += 1000;
298  return 1;
299  } else {
300  return -1;
301  }
302  }
303  break;
304  /* Not implemented types:
305  kCHAR
306  kVARCHAR
307  kTIME
308  kTIMESTAMP
309  kTEXT
310  kDATE
311  kINTERVAL_DAY_TIME
312  kINTERVAL_YEAR_MONTH
313  kGEOMETRY
314  kGEOGRAPHY
315  kEVAL_CONTEXT_TYPE
316  kVOID
317  kCURSOR
318  */
319  default:
320  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
321  ": support for " + arg_type.get_type_name() +
322  "(type=" + std::to_string(arg_type.get_type()) + ")" +
323  +" not implemented: \n pos=" + std::to_string(sig_pos) +
324  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
325  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
326  }
327  return -1;
328 }
ExtArgumentType get_array_arg_elem_type(const ExtArgumentType ext_arg_array_type)
bool is_array() const
Definition: sqltypes.h:425
std::string to_string(char const *&&v)
int get_logical_size() const
Definition: sqltypes.h:270
bool is_column() const
Definition: sqltypes.h:430
ExtArgumentType get_column_arg_elem_type(const ExtArgumentType ext_arg_column_type)
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
std::string get_type_name() const
Definition: sqltypes.h:362
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:624
#define CHECK(condition)
Definition: Logger.h:197
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:259
Definition: sqltypes.h:47
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: