OmniSciDB  5ade3759e0
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

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

References Bool, Double, Float, SQLTypeInfoCore< TYPE_FACET_PACK >::get_logical_size(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_type_name(), Int16, Int32, Int64, Int8, 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  case kLINESTRING:
155  case kPOINT:
156  case kARRAY:
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  }
164  break;
165  case kPOLYGON:
166  if (stype == ExtArgumentType::PInt8 && sig_pos + 3 < max_pos &&
167  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
168  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
169  sig_types[sig_pos + 3] == ExtArgumentType::Int64) {
170  penalty_score += 1000;
171  return 4;
172  }
173  break;
174  case kMULTIPOLYGON:
175  if (stype == ExtArgumentType::PInt8 && sig_pos + 5 < max_pos &&
176  sig_types[sig_pos + 1] == ExtArgumentType::Int64 &&
177  sig_types[sig_pos + 2] == ExtArgumentType::PInt32 &&
178  sig_types[sig_pos + 3] == ExtArgumentType::Int64 &&
179  sig_types[sig_pos + 4] == ExtArgumentType::PInt32 &&
180  sig_types[sig_pos + 5] == ExtArgumentType::Int64) {
181  penalty_score += 1000;
182  return 6;
183  }
184  break;
185  case kDECIMAL:
186  case kNUMERIC:
187  if (stype == ExtArgumentType::Double && arg_type.get_logical_size() == 8) {
188  penalty_score += 1000;
189  return 1;
190  }
191  if (stype == ExtArgumentType::Float && arg_type.get_logical_size() == 4) {
192  penalty_score += 1000;
193  return 1;
194  }
195  break;
196  case kNULLT: // NULL maps to a pointer and size argument
197  if ((stype == ExtArgumentType::PInt8 || stype == ExtArgumentType::PInt16 ||
198  stype == ExtArgumentType::PInt32 || stype == ExtArgumentType::PInt64 ||
199  stype == ExtArgumentType::PFloat || stype == ExtArgumentType::PDouble) &&
200  sig_pos < max_pos && sig_types[sig_pos + 1] == ExtArgumentType::Int64) {
201  penalty_score += 1000;
202  return 2;
203  }
204  break;
205  /* Not implemented types:
206  kCHAR
207  kVARCHAR
208  kTIME
209  kTIMESTAMP
210  kTEXT
211  kDATE
212  kINTERVAL_DAY_TIME
213  kINTERVAL_YEAR_MONTH
214  kGEOMETRY
215  kGEOGRAPHY
216  kEVAL_CONTEXT_TYPE
217  */
218  default:
219  throw std::runtime_error(std::string(__FILE__) + "#" + std::to_string(__LINE__) +
220  ": support for " + arg_type.get_type_name() +
221  "(type=" + std::to_string(arg_type.get_type()) + ")" +
222  +" not implemented: \n pos=" + std::to_string(sig_pos) +
223  " max_pos=" + std::to_string(max_pos) + "\n sig_types=(" +
224  ExtensionFunctionsWhitelist::toString(sig_types) + ")");
225  }
226  return -1;
227 }
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:323
std::string to_string(char const *&&v)
std::string get_type_name() const
Definition: sqltypes.h:426
int get_logical_size() const
Definition: sqltypes.h:334
static std::string toString(const std::vector< ExtensionFunction > &ext_funcs, std::string tab="")
Definition: sqltypes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function: