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

Functions

static int match_arguments (const SQLTypeInfo &arg_type, int sig_pos, const std::vector< ExtArgumentType > &sig_types, int &penalty_score)
 

Function Documentation

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

References Bool, Double, Float, GeoLineString, GeoPoint, GeoPolygon, SQLTypeInfoCore< TYPE_FACET_PACK >::get_logical_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), Int16, Int32, Int64, Int8, is_ext_arg_type_array(), kARRAY, kBIGINT, kBOOLEAN, kDECIMAL, kDOUBLE, kFLOAT, kINT, kLINESTRING, kMULTIPOLYGON, kNULLT, kNUMERIC, kPOINT, kPOLYGON, kSMALLINT, kTINYINT, PDouble, PFloat, PInt16, PInt32, PInt64, PInt8, to_string(), and ExtensionFunctionsWhitelist::toString().

Referenced by bind_function().

38  {
39  /*
40  Returns non-negative integer `offset` if `arg_type` and
41  `sig_types[sig_pos:sig_pos + offset]` match.
42 
43  The `offset` value can be interpreted as the number of extension
44  function arguments that is consumed by the given `arg_type`. For
45  instance, for scalar types the offset is always 1, for array
46  types the offset is 2: one argument for array pointer value and
47  one argument for the array size value, etc.
48 
49  Returns -1 when the types of an argument and the corresponding
50  extension function argument(s) mismatch, or when downcasting would
51  be effective.
52 
53  In case of non-negative `offset` result, the function updates
54  penalty_score argument as follows:
55 
56  add 1000 if arg_type is non-scalar, otherwise:
57  add 1000 * sizeof(sig_type) / sizeof(arg_type)
58  add 1000000 if type kinds differ (integer vs double, for instance)
59 
60  */
61  auto stype = sig_types[sig_pos];
62  int max_pos = sig_types.size() - 1;
63  switch (arg_type.get_type()) {
64  case kBOOLEAN:
65  if (stype == ExtArgumentType::Bool) {
66  penalty_score += 1000;
67  return 1;
68  }
69  break;
70  case kTINYINT:
71  switch (stype) {
73  penalty_score += 1000;
74  break;
76  penalty_score += 2000;
77  break;
79  penalty_score += 4000;
80  break;
82  penalty_score += 8000;
83  break;
85  penalty_score += 1008000;
86  break; // temporary: allow integers as double arguments
87  default:
88  return -1;
89  }
90  return 1;
91  case kSMALLINT:
92  switch (stype) {
94  penalty_score += 1000;
95  break;
97  penalty_score += 2000;
98  break;
100  penalty_score += 4000;
101  break;
103  penalty_score += 1004000;
104  break; // temporary: allow integers as double arguments
105  default:
106  return -1;
107  }
108  return 1;
109  case kINT:
110  switch (stype) {
112  penalty_score += 1000;
113  break;
115  penalty_score += 2000;
116  break;
118  penalty_score += 1002000;
119  break; // temporary: allow integers as double arguments
120  default:
121  return -1;
122  }
123  return 1;
124  case kBIGINT:
125  switch (stype) {
127  penalty_score += 1000;
128  break;
130  penalty_score += 1001000;
131  break; // temporary: allow integers as double arguments
132  default:
133  return -1;
134  }
135  return 1;
136  case kFLOAT:
137  switch (stype) {
139  penalty_score += 1000;
140  break;
142  penalty_score += 2000;
143  break; // is it ok to use floats as double arguments?
144  default:
145  return -1;
146  }
147  return 1;
148  case kDOUBLE:
149  if (stype == ExtArgumentType::Double) {
150  penalty_score += 1000;
151  return 1;
152  }
153  break;
154 
155  case kPOINT:
156  case kLINESTRING:
157  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
158  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
159  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
160  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
161  penalty_score += 1000;
162  return 2;
163  } else if (stype == ExtArgumentType::GeoPoint ||
165  penalty_score += 1000;
166  return 1;
167  }
168  break;
169  case kARRAY:
170  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
171  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
172  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
173  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
174  penalty_score += 1000;
175  return 2;
176  } else if (is_ext_arg_type_array(stype)) {
177  penalty_score += 1000;
178  return 1;
179  }
180  break;
181  case kPOLYGON:
182  if (stype == ExtArgumentType::PInt8 && sig_pos + 3 < max_pos &&
183  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
184  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
185  sig_types[sig_pos + 3] == ExtArgumentType::Int64) {
186  penalty_score += 1000;
187  return 4;
188  } else if (stype == ExtArgumentType::GeoPolygon) {
189  penalty_score += 1000;
190  return 1;
191  }
192 
193  break;
194 
195  case kMULTIPOLYGON:
196  if (stype == ExtArgumentType::PInt8 && sig_pos + 5 < max_pos &&
197  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
198  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
199  sig_types[sig_pos + 3] == ExtArgumentType::Int64 &&
200  sig_types[sig_pos + 4] == ExtArgumentType::PInt32 &&
201  sig_types[sig_pos + 5] == ExtArgumentType::Int64) {
202  penalty_score += 1000;
203  return 6;
204  }
205  break;
206  case kDECIMAL:
207  case kNUMERIC:
208  if (stype == ExtArgumentType::Double && arg_type.get_logical_size() == 8) {
209  penalty_score += 1000;
210  return 1;
211  }
212  if (stype == ExtArgumentType::Float && arg_type.get_logical_size() == 4) {
213  penalty_score += 1000;
214  return 1;
215  }
216  break;
217  case kNULLT: // NULL maps to a pointer and size argument
218  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
219  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
220  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
221  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
222  penalty_score += 1000;
223  return 2;
224  }
225  break;
226  /* Not implemented types:
227  kCHAR
228  kVARCHAR
229  kTIME
230  kTIMESTAMP
231  kTEXT
232  kDATE
233  kINTERVAL_DAY_TIME
234  kINTERVAL_YEAR_MONTH
235  kGEOMETRY
236  kGEOGRAPHY
237  kEVAL_CONTEXT_TYPE
238  kVOID
239  kCURSOR
240  */
241  default:
242  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
243  ": support for " + arg_type.get_type_name() +
244  "(type=" + std::to_string(arg_type.get_type()) + ")" +
245  +" not implemented: \n pos=" + std::to_string(sig_pos) +
246  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
247  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
248  }
249  return -1;
250 }
std::string to_string(char const *&&v)
std::string get_type_name() const
Definition: sqltypes.h:429
int get_logical_size() const
Definition: sqltypes.h:337
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:326
bool is_ext_arg_type_array(const ExtArgumentType ext_arg_type)
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
Definition: sqltypes.h:48

+ Here is the call graph for this function:

+ Here is the caller graph for this function: