OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sqldefs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #ifndef SQLDEFS_H
24 #define SQLDEFS_H
25 
26 // must not change the order without keeping the array in OperExpr::to_string
27 // in sync.
28 enum SQLOps {
29  kEQ = 0,
31  kNE,
32  kLT,
33  kGT,
34  kLE,
35  kGE,
37  kOR,
52  kIN,
55 };
56 
57 #define IS_COMPARISON(X) \
58  ((X) == kEQ || (X) == kBW_EQ || (X) == kOVERLAPS || (X) == kNE || (X) == kLT || \
59  (X) == kGT || (X) == kLE || (X) == kGE)
60 #define IS_LOGIC(X) ((X) == kAND || (X) == kOR)
61 #define IS_ARITHMETIC(X) \
62  ((X) == kMINUS || (X) == kPLUS || (X) == kMULTIPLY || (X) == kDIVIDE || (X) == kMODULO)
63 #define COMMUTE_COMPARISON(X) \
64  ((X) == kLT ? kGT : (X) == kLE ? kGE : (X) == kGT ? kLT : (X) == kGE ? kLE : (X))
65 #define IS_UNARY(X) \
66  ((X) == kNOT || (X) == kUMINUS || (X) == kISNULL || (X) == kEXISTS || (X) == kCAST || \
67  (X) == kENCODE_TEXT)
68 #define IS_EQUIVALENCE(X) ((X) == kEQ || (X) == kBW_EQ || (X) == kOVERLAPS)
69 
71 
72 enum SQLAgg {
82 };
83 
84 enum class SqlStringOpKind {
85  /* Unary */
86  LOWER = 1,
87  UPPER,
88  INITCAP,
89  REVERSE,
90  /* Binary */
91  REPEAT,
92  CONCAT,
93  RCONCAT,
94  /* Ternary */
95  LPAD,
96  RPAD,
97  TRIM,
98  LTRIM,
99  RTRIM,
100  SUBSTRING,
101  OVERLAY,
102  REPLACE,
103  SPLIT_PART,
104  /* 6 args */
107  INVALID
108 };
109 
111  // set MIN's enum val as one, and we use window function kind's enum vals
112  // to classify a behavior of our runtime code for window framing
113  // i.e., aggregate_##value_type##_values functions
114  // todo (yoonmin): support FIRST_EXPR, LAST_EXPR, AND NTH_EXPR with framing
115  MIN = 1,
116  MAX,
117  AVG,
118  SUM,
119  COUNT,
120  FIRST_EXPR,
121  LAST_EXPR,
122  NTH_EXPR,
123  ROW_NUMBER,
124  RANK,
125  DENSE_RANK,
126  PERCENT_RANK,
127  CUME_DIST,
128  NTILE,
129  LAG,
130  LEAD,
131  FIRST_VALUE,
132  LAST_VALUE,
133  SUM_INTERNAL // For deserialization from Calcite only. Gets rewritten to a regular SUM.
134 };
135 
139  CURRENT_ROW,
142  UNKNOWN
143 };
144 
146 
147 enum StorageOption { kDISK = 0, kGPU = 1, kCPU = 2 };
148 
149 enum ViewRefreshOption { kMANUAL = 0, kAUTO = 1, kIMMEDIATE = 2 };
150 
151 enum class JoinType { INNER, LEFT, SEMI, ANTI, INVALID };
152 
153 #if !(defined(__CUDACC__) || defined(NO_BOOST))
154 
155 #include <string>
156 #include "Logger/Logger.h"
157 
158 inline std::string toString(const JoinType& join_type) {
159  switch (join_type) {
160  case JoinType::INNER:
161  return "INNER";
162  case JoinType::LEFT:
163  return "LEFT";
164  case JoinType::SEMI:
165  return "SEMI";
166  case JoinType::ANTI:
167  return "ANTI";
168  default:
169  return "INVALID";
170  }
171 }
172 
173 inline std::string toString(const SQLQualifier& qualifier) {
174  switch (qualifier) {
175  case kONE:
176  return "ONE";
177  case kANY:
178  return "ANY";
179  case kALL:
180  return "ALL";
181  }
182  LOG(FATAL) << "Invalid SQLQualifier: " << qualifier;
183  return "";
184 }
185 
186 inline std::string toString(const SQLAgg& kind) {
187  switch (kind) {
188  case kAVG:
189  return "AVG";
190  case kMIN:
191  return "MIN";
192  case kMAX:
193  return "MAX";
194  case kSUM:
195  return "SUM";
196  case kCOUNT:
197  return "COUNT";
199  return "APPROX_COUNT_DISTINCT";
200  case kAPPROX_QUANTILE:
201  return "APPROX_PERCENTILE";
202  case kSAMPLE:
203  return "SAMPLE";
204  case kSINGLE_VALUE:
205  return "SINGLE_VALUE";
206  }
207  LOG(FATAL) << "Invalid aggregate kind: " << kind;
208  return "";
209 }
210 
211 inline std::string toString(const SQLOps& op) {
212  switch (op) {
213  case kEQ:
214  return "EQ";
215  case kBW_EQ:
216  return "BW_EQ";
217  case kNE:
218  return "NE";
219  case kLT:
220  return "LT";
221  case kGT:
222  return "GT";
223  case kLE:
224  return "LE";
225  case kGE:
226  return "GE";
227  case kAND:
228  return "AND";
229  case kOR:
230  return "OR";
231  case kNOT:
232  return "NOT";
233  case kMINUS:
234  return "MINUS";
235  case kPLUS:
236  return "PLUS";
237  case kMULTIPLY:
238  return "MULTIPLY";
239  case kDIVIDE:
240  return "DIVIDE";
241  case kMODULO:
242  return "MODULO";
243  case kUMINUS:
244  return "UMINUS";
245  case kISNULL:
246  return "ISNULL";
247  case kISNOTNULL:
248  return "ISNOTNULL";
249  case kEXISTS:
250  return "EXISTS";
251  case kCAST:
252  return "CAST";
253  case kARRAY_AT:
254  return "ARRAY_AT";
255  case kUNNEST:
256  return "UNNEST";
257  case kFUNCTION:
258  return "FUNCTION";
259  case kIN:
260  return "IN";
261  case kOVERLAPS:
262  return "OVERLAPS";
263  case kENCODE_TEXT:
264  return "ENCODE_TEXT";
265  }
266  LOG(FATAL) << "Invalid operation kind: " << op;
267  return "";
268 }
269 
270 inline SqlStringOpKind name_to_string_op_kind(const std::string& func_name) {
271  if (func_name == "LOWER") {
272  return SqlStringOpKind::LOWER;
273  }
274  if (func_name == "UPPER") {
275  return SqlStringOpKind::UPPER;
276  }
277  if (func_name == "INITCAP") {
279  }
280  if (func_name == "REVERSE") {
282  }
283  if (func_name == "REPEAT") {
285  }
286  if (func_name == "||") {
288  }
289  if (func_name == "LPAD") {
290  return SqlStringOpKind::LPAD;
291  }
292  if (func_name == "RPAD") {
293  return SqlStringOpKind::RPAD;
294  }
295  if (func_name == "TRIM") {
296  return SqlStringOpKind::TRIM;
297  }
298  if (func_name == "LTRIM") {
299  return SqlStringOpKind::LTRIM;
300  }
301  if (func_name == "RTRIM") {
302  return SqlStringOpKind::RTRIM;
303  }
304  if (func_name == "SUBSTRING") {
306  }
307  if (func_name == "OVERLAY") {
309  }
310  if (func_name == "REPLACE") {
312  }
313  if (func_name == "SPLIT_PART") {
315  }
316  if (func_name == "REGEXP_REPLACE") {
318  }
319  if (func_name == "REGEXP_SUBSTR") {
321  }
322  if (func_name == "REGEXP_MATCH") {
324  }
325  LOG(FATAL) << "Invalid string function " << func_name << ".";
327 }
328 
329 inline std::string toString(const SqlStringOpKind& kind) {
330  switch (kind) {
332  return "LOWER";
334  return "UPPER";
336  return "INITCAP";
338  return "REVERSE";
340  return "REPEAT";
343  return "||";
345  return "LPAD";
347  return "RPAD";
349  return "TRIM";
351  return "LTRIM";
353  return "RTRIM";
355  return "SUBSTRING";
357  return "OVERLAY";
359  return "REPLACE";
361  return "SPLIT_PART";
363  return "REGEXP_REPLACE";
365  return "REGEXP_SUBSTR";
366  default:
367  LOG(FATAL) << "Invalid string operation";
368  }
369  return "";
370 }
371 
372 inline std::string toString(const SqlWindowFunctionKind& kind) {
373  switch (kind) {
375  return "ROW_NUMBER";
377  return "RANK";
379  return "DENSE_RANK";
381  return "PERCENT_RANK";
383  return "CUME_DIST";
385  return "NTILE";
387  return "LAG";
389  return "LEAD";
391  return "FIRST_VALUE";
393  return "LAST_VALUE";
395  return "AVG";
397  return "MIN";
399  return "MAX";
401  return "SUM";
403  return "COUNT";
405  return "SUM_INTERNAL";
407  return "FIRST_EXPR";
409  return "LAST_EXPR";
411  return "NTH_EXPR";
412  }
413  LOG(FATAL) << "Invalid window function kind.";
414  return "";
415 }
416 
417 inline std::string toString(const SqlWindowFrameBoundType& kind) {
418  switch (kind) {
420  return "UNBOUNDED_PRECEDING";
422  return "EXPR_PRECEDING";
424  return "CURRENT_ROW";
426  return "EXPR_FOLLOWING";
428  return "UNBOUNDED_FOLLOWING";
430  return "UNKNOWN";
431  }
432  LOG(FATAL) << "Invalid window function bound type.";
433  return "";
434 }
435 
436 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
437 
438 #endif // SQLDEFS_H
Definition: sqldefs.h:70
SqlWindowFrameBoundType
Definition: sqldefs.h:136
SQLAgg
Definition: sqldefs.h:72
ViewRefreshOption
Definition: sqldefs.h:149
SqlStringOpKind name_to_string_op_kind(const std::string &func_name)
Definition: sqldefs.h:270
Definition: sqldefs.h:147
JoinType
Definition: sqldefs.h:151
SQLQualifier
Definition: sqldefs.h:70
#define LOG(tag)
Definition: Logger.h:216
SQLOps
Definition: sqldefs.h:28
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:37
SqlStringOpKind
Definition: sqldefs.h:84
Definition: sqldefs.h:48
Definition: sqldefs.h:29
Definition: sqldefs.h:40
Definition: sqldefs.h:74
Definition: sqldefs.h:36
Definition: sqldefs.h:76
Definition: sqldefs.h:70
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448
StorageOption
Definition: sqldefs.h:147
SQLStmtType
Definition: sqldefs.h:145
Definition: sqldefs.h:33
Definition: sqldefs.h:39
Definition: sqldefs.h:70
Definition: sqldefs.h:147
Definition: sqldefs.h:31
Definition: sqldefs.h:77
Definition: sqldefs.h:149
SqlWindowFunctionKind
Definition: sqldefs.h:110
Definition: sqldefs.h:52
Definition: sqldefs.h:30
Definition: sqldefs.h:32
Definition: sqldefs.h:75
Definition: sqldefs.h:73
Definition: sqldefs.h:38
Definition: sqldefs.h:147