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

Functions

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

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

Definition at line 37 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:

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 59 of file ExtensionFunctionsBinding.cpp.

References Bool, CHECK(), Double, ext_arg_type_to_type_info(), Float, GeoLineString, GeoMultiPolygon, GeoPoint, GeoPolygon, get_array_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(), is_ext_arg_type_array(), kARRAY, kBIGINT, kBOOLEAN, 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().

62  {
63  /*
64  Returns non-negative integer `offset` if `arg_type` and
65  `sig_types[sig_pos:sig_pos + offset]` match.
66 
67  The `offset` value can be interpreted as the number of extension
68  function arguments that is consumed by the given `arg_type`. For
69  instance, for scalar types the offset is always 1, for array
70  types the offset is 2: one argument for array pointer value and
71  one argument for the array size value, etc.
72 
73  Returns -1 when the types of an argument and the corresponding
74  extension function argument(s) mismatch, or when downcasting would
75  be effective.
76 
77  In case of non-negative `offset` result, the function updates
78  penalty_score argument as follows:
79 
80  add 1000 if arg_type is non-scalar, otherwise:
81  add 1000 * sizeof(sig_type) / sizeof(arg_type)
82  add 1000000 if type kinds differ (integer vs double, for instance)
83 
84  */
85  auto stype = sig_types[sig_pos];
86  int max_pos = sig_types.size() - 1;
87 
88  switch (arg_type.get_type()) {
89  case kBOOLEAN:
90  if (stype == ExtArgumentType::Bool) {
91  penalty_score += 1000;
92  return 1;
93  }
94  break;
95  case kTINYINT:
96  switch (stype) {
98  penalty_score += 1000;
99  break;
101  penalty_score += 2000;
102  break;
104  penalty_score += 4000;
105  break;
107  penalty_score += 8000;
108  break;
110  penalty_score += 1008000;
111  break; // temporary: allow integers as double arguments
112  default:
113  return -1;
114  }
115  return 1;
116  case kSMALLINT:
117  switch (stype) {
119  penalty_score += 1000;
120  break;
122  penalty_score += 2000;
123  break;
125  penalty_score += 4000;
126  break;
128  penalty_score += 1004000;
129  break; // temporary: allow integers as double arguments
130  default:
131  return -1;
132  }
133  return 1;
134  case kINT:
135  switch (stype) {
137  penalty_score += 1000;
138  break;
140  penalty_score += 2000;
141  break;
143  penalty_score += 1002000;
144  break; // temporary: allow integers as double arguments
145  default:
146  return -1;
147  }
148  return 1;
149  case kBIGINT:
150  switch (stype) {
152  penalty_score += 1000;
153  break;
155  penalty_score += 1001000;
156  break; // temporary: allow integers as double arguments
157  default:
158  return -1;
159  }
160  return 1;
161  case kFLOAT:
162  switch (stype) {
164  penalty_score += 1000;
165  break;
167  penalty_score += 2000;
168  break; // is it ok to use floats as double arguments?
169  default:
170  return -1;
171  }
172  return 1;
173  case kDOUBLE:
174  if (stype == ExtArgumentType::Double) {
175  penalty_score += 1000;
176  return 1;
177  }
178  break;
179 
180  case kPOINT:
181  case kLINESTRING:
182  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
183  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
184  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
185  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
186  penalty_score += 1000;
187  return 2;
188  } else if (stype == ExtArgumentType::GeoPoint ||
190  penalty_score += 1000;
191  return 1;
192  }
193  break;
194  case kARRAY:
195  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
196  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
197  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
198  stype == ExtArgumentType::PBool) &&
199  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
200  penalty_score += 1000;
201  return 2;
202  } else if (is_ext_arg_type_array(stype)) {
203  // array arguments must match exactly
204  CHECK(arg_type.is_array());
205  const auto stype_ti = ext_arg_type_to_type_info(get_array_arg_elem_type(stype));
206  if (arg_type.get_elem_type() == kBOOLEAN && stype_ti.get_type() == kTINYINT) {
207  /* Boolean array has the same low-level structure as Int8 array. */
208  penalty_score += 1000;
209  return 1;
210  } else if (arg_type.get_elem_type().get_type() == stype_ti.get_type()) {
211  penalty_score += 1000;
212  return 1;
213  } else {
214  return -1;
215  }
216  }
217  break;
218  case kPOLYGON:
219  if (stype == ExtArgumentType::PInt8 && sig_pos + 3 < max_pos &&
220  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
221  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
222  sig_types[sig_pos + 3] == ExtArgumentType::Int64) {
223  penalty_score += 1000;
224  return 4;
225  } else if (stype == ExtArgumentType::GeoPolygon) {
226  penalty_score += 1000;
227  return 1;
228  }
229 
230  break;
231 
232  case kMULTIPOLYGON:
233  if (stype == ExtArgumentType::PInt8 && sig_pos + 5 < max_pos &&
234  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
235  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
236  sig_types[sig_pos + 3] == ExtArgumentType::Int64 &&
237  sig_types[sig_pos + 4] == ExtArgumentType::PInt32 &&
238  sig_types[sig_pos + 5] == ExtArgumentType::Int64) {
239  penalty_score += 1000;
240  return 6;
241  } else if (stype == ExtArgumentType::GeoMultiPolygon) {
242  penalty_score += 1000;
243  return 1;
244  }
245  break;
246  case kDECIMAL:
247  case kNUMERIC:
248  if (stype == ExtArgumentType::Double && arg_type.get_logical_size() == 8) {
249  penalty_score += 1000;
250  return 1;
251  }
252  if (stype == ExtArgumentType::Float && arg_type.get_logical_size() == 4) {
253  penalty_score += 1000;
254  return 1;
255  }
256  break;
257  case kNULLT: // NULL maps to a pointer and size argument
258  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
259  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
260  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble ||
261  stype == ExtArgumentType::PBool) &&
262  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
263  penalty_score += 1000;
264  return 2;
265  }
266  break;
267  /* Not implemented types:
268  kCHAR
269  kVARCHAR
270  kTIME
271  kTIMESTAMP
272  kTEXT
273  kDATE
274  kINTERVAL_DAY_TIME
275  kINTERVAL_YEAR_MONTH
276  kGEOMETRY
277  kGEOGRAPHY
278  kEVAL_CONTEXT_TYPE
279  kVOID
280  kCURSOR
281  */
282  default:
283  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
284  ": support for " + arg_type.get_type_name() +
285  "(type=" + std::to_string(arg_type.get_type()) + ")" +
286  +" not implemented: \n pos=" + std::to_string(sig_pos) +
287  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
288  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
289  }
290  return -1;
291 }
ExtArgumentType get_array_arg_elem_type(const ExtArgumentType ext_arg_array_type)
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
std::string to_string(char const *&&v)
CHECK(cgen_state)
int get_logical_size() const
Definition: sqltypes.h:269
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
std::string get_type_name() const
Definition: sqltypes.h:361
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
Definition: sqltypes.h:46
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:622
bool is_array() const
Definition: sqltypes.h:423
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: