OmniSciDB  b28c0d5765
 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,
56 };
57 
58 #define IS_COMPARISON(X) \
59  ((X) == kEQ || (X) == kBW_EQ || (X) == kOVERLAPS || (X) == kNE || (X) == kLT || \
60  (X) == kGT || (X) == kLE || (X) == kGE)
61 #define IS_LOGIC(X) ((X) == kAND || (X) == kOR)
62 #define IS_ARITHMETIC(X) \
63  ((X) == kMINUS || (X) == kPLUS || (X) == kMULTIPLY || (X) == kDIVIDE || (X) == kMODULO)
64 #define COMMUTE_COMPARISON(X) \
65  ((X) == kLT ? kGT : (X) == kLE ? kGE : (X) == kGT ? kLT : (X) == kGE ? kLE : (X))
66 #define IS_UNARY(X) \
67  ((X) == kNOT || (X) == kUMINUS || (X) == kISNULL || (X) == kEXISTS || (X) == kCAST || \
68  (X) == kENCODE_TEXT)
69 #define IS_EQUIVALENCE(X) ((X) == kEQ || (X) == kBW_EQ || (X) == kOVERLAPS)
70 
72 
73 enum SQLAgg {
86 };
87 
88 enum class SqlStringOpKind {
89  /* Unary */
90  LOWER = 1,
91  UPPER,
92  INITCAP,
93  REVERSE,
94  /* Binary */
95  REPEAT,
96  CONCAT,
97  RCONCAT,
98  /* Ternary */
99  LPAD,
100  RPAD,
101  TRIM,
102  LTRIM,
103  RTRIM,
104  SUBSTRING,
105  OVERLAY,
106  REPLACE,
107  SPLIT_PART,
108  /* 6 args */
111  JSON_VALUE,
114  TRY_STRING_CAST, // string-to-numeric
115  POSITION, // string-to-numeric
116  INVALID
117 };
118 
120  // set MIN's enum val as one, and we use window function kind's enum vals
121  // to classify a behavior of our runtime code for window framing
122  // i.e., aggregate_##value_type##_values functions
123  MIN = 1,
124  MAX,
125  AVG,
126  SUM,
127  COUNT,
128  FIRST_EXPR,
129  LAST_EXPR,
130  NTH_EXPR,
131  ROW_NUMBER,
132  RANK,
133  DENSE_RANK,
134  PERCENT_RANK,
135  CUME_DIST,
136  NTILE,
137  LAG,
138  LAG_IN_FRAME,
139  LEAD,
141  FIRST_VALUE,
142  LAST_VALUE,
143  COUNT_IF,
144  SUM_INTERNAL, // For deserialization from Calcite only. Gets rewritten to a regular
145  // SUM.
146  INVALID
147 };
148 
152  CURRENT_ROW,
155  UNKNOWN
156 };
157 
159 
160 enum StorageOption { kDISK = 0, kGPU = 1, kCPU = 2 };
161 
162 enum ViewRefreshOption { kMANUAL = 0, kAUTO = 1, kIMMEDIATE = 2 };
163 
164 enum class JoinType { INNER, LEFT, SEMI, ANTI, INVALID };
165 
166 #if !(defined(__CUDACC__) || defined(NO_BOOST))
167 
168 #include <sstream>
169 #include <string>
170 #include "Logger/Logger.h"
171 
172 inline std::string toString(const JoinType& join_type) {
173  switch (join_type) {
174  case JoinType::INNER:
175  return "INNER";
176  case JoinType::LEFT:
177  return "LEFT";
178  case JoinType::SEMI:
179  return "SEMI";
180  case JoinType::ANTI:
181  return "ANTI";
182  default:
183  return "INVALID";
184  }
185 }
186 
187 inline std::string toString(const SQLQualifier& qualifier) {
188  switch (qualifier) {
189  case kONE:
190  return "ONE";
191  case kANY:
192  return "ANY";
193  case kALL:
194  return "ALL";
195  }
196  LOG(FATAL) << "Invalid SQLQualifier: " << qualifier;
197  return "";
198 }
199 
200 inline std::string toString(const SQLAgg& kind) {
201  switch (kind) {
202  case kAVG:
203  return "AVG";
204  case kMIN:
205  return "MIN";
206  case kMAX:
207  return "MAX";
208  case kSUM:
209  return "SUM";
210  case kCOUNT:
211  return "COUNT";
213  return "APPROX_COUNT_DISTINCT";
214  case kAPPROX_QUANTILE:
215  return "APPROX_PERCENTILE";
216  case kSAMPLE:
217  return "SAMPLE";
218  case kSINGLE_VALUE:
219  return "SINGLE_VALUE";
220  case kMODE:
221  return "MODE";
222  case kCOUNT_IF:
223  return "COUNT_IF";
224  case kINVALID_AGG:
225  return "INVALID";
226  default:
227  UNREACHABLE() << "Invalid aggregate kind: " << kind;
228  return {};
229  }
230 }
231 
232 inline std::string toString(const SQLOps& op) {
233  switch (op) {
234  case kEQ:
235  return "EQ";
236  case kBW_EQ:
237  return "BW_EQ";
238  case kNE:
239  return "NE";
240  case kLT:
241  return "LT";
242  case kGT:
243  return "GT";
244  case kLE:
245  return "LE";
246  case kGE:
247  return "GE";
248  case kAND:
249  return "AND";
250  case kOR:
251  return "OR";
252  case kNOT:
253  return "NOT";
254  case kMINUS:
255  return "MINUS";
256  case kPLUS:
257  return "PLUS";
258  case kMULTIPLY:
259  return "MULTIPLY";
260  case kDIVIDE:
261  return "DIVIDE";
262  case kMODULO:
263  return "MODULO";
264  case kUMINUS:
265  return "UMINUS";
266  case kISNULL:
267  return "ISNULL";
268  case kISNOTNULL:
269  return "ISNOTNULL";
270  case kEXISTS:
271  return "EXISTS";
272  case kCAST:
273  return "CAST";
274  case kARRAY_AT:
275  return "ARRAY_AT";
276  case kUNNEST:
277  return "UNNEST";
278  case kFUNCTION:
279  return "FUNCTION";
280  case kIN:
281  return "IN";
282  case kOVERLAPS:
283  return "OVERLAPS";
284  case kENCODE_TEXT:
285  return "ENCODE_TEXT";
286  case kINVALID_OP:
287  return "INVALID_OP";
288  }
289  LOG(FATAL) << "Invalid operation kind: " << op;
290  return "";
291 }
292 
293 inline std::ostream& operator<<(std::ostream& os, const SqlStringOpKind kind) {
294  switch (kind) {
296  return os << "LOWER";
298  return os << "UPPER";
300  return os << "INITCAP";
302  return os << "REVERSE";
304  return os << "REPEAT";
306  return os << "CONCAT";
308  return os << "RCONCAT";
310  return os << "LPAD";
312  return os << "RPAD";
314  return os << "TRIM";
316  return os << "LTRIM";
318  return os << "RTRIM";
320  return os << "SUBSTRING";
322  return os << "OVERLAY";
324  return os << "REPLACE";
326  return os << "SPLIT_PART";
328  return os << "REGEXP_REPLACE";
330  return os << "REGEXP_SUBSTR";
332  return os << "JSON_VALUE";
334  return os << "BASE64_ENCODE";
336  return os << "BASE64_DECODE";
338  return os << "TRY_STRING_CAST";
340  return os << "POSITION";
342  return os << "INVALID";
343  }
344  LOG(FATAL) << "Invalid string operation";
345  // Make compiler happy
346  return os << "INVALID";
347 }
348 
349 inline SqlStringOpKind name_to_string_op_kind(const std::string& func_name) {
350  if (func_name == "LOWER") {
351  return SqlStringOpKind::LOWER;
352  }
353  if (func_name == "UPPER") {
354  return SqlStringOpKind::UPPER;
355  }
356  if (func_name == "INITCAP") {
358  }
359  if (func_name == "REVERSE") {
361  }
362  if (func_name == "REPEAT") {
364  }
365  if (func_name == "||") {
367  }
368  if (func_name == "LPAD") {
369  return SqlStringOpKind::LPAD;
370  }
371  if (func_name == "RPAD") {
372  return SqlStringOpKind::RPAD;
373  }
374  if (func_name == "TRIM") {
375  return SqlStringOpKind::TRIM;
376  }
377  if (func_name == "LTRIM") {
378  return SqlStringOpKind::LTRIM;
379  }
380  if (func_name == "RTRIM") {
381  return SqlStringOpKind::RTRIM;
382  }
383  if (func_name == "SUBSTRING") {
385  }
386  if (func_name == "OVERLAY") {
388  }
389  if (func_name == "REPLACE") {
391  }
392  if (func_name == "SPLIT_PART") {
394  }
395  if (func_name == "REGEXP_REPLACE") {
397  }
398  if (func_name == "REGEXP_SUBSTR") {
400  }
401  if (func_name == "REGEXP_MATCH") {
403  }
404  if (func_name == "JSON_VALUE") {
406  }
407  if (func_name == "BASE64_ENCODE") {
409  }
410  if (func_name == "BASE64_DECODE") {
412  }
413  if (func_name == "TRY_CAST") {
415  }
416  if (func_name == "POSITION") {
418  }
419  LOG(FATAL) << "Invalid string function " << func_name << ".";
421 }
422 
423 inline bool string_op_returns_string(const SqlStringOpKind kind) {
424  switch (kind) {
427  return false;
428  default:
429  return true;
430  }
431 }
432 
433 inline std::string toString(const SqlWindowFunctionKind& kind) {
434  switch (kind) {
436  return "ROW_NUMBER";
438  return "RANK";
440  return "DENSE_RANK";
442  return "PERCENT_RANK";
444  return "CUME_DIST";
446  return "NTILE";
448  return "LAG";
450  return "LEAD";
452  return "FIRST_VALUE";
454  return "LAST_VALUE";
456  return "AVG";
458  return "MIN";
460  return "MAX";
462  return "SUM";
464  return "COUNT";
466  return "SUM_INTERNAL";
468  return "FIRST_EXPR";
470  return "LAST_EXPR";
472  return "NTH_EXPR";
474  return "LEAD_IN_FRAME";
476  return "LAG_IN_FRAME";
478  return "COUNT_IF";
480  return "INVALID";
481  }
482  LOG(FATAL) << "Invalid window function kind.";
483  return "";
484 }
485 
486 inline std::string toString(const SqlWindowFrameBoundType& kind) {
487  switch (kind) {
489  return "UNBOUNDED_PRECEDING";
491  return "EXPR_PRECEDING";
493  return "CURRENT_ROW";
495  return "EXPR_FOLLOWING";
497  return "UNBOUNDED_FOLLOWING";
499  return "UNKNOWN";
500  }
501  LOG(FATAL) << "Invalid window function bound type.";
502  return "";
503 }
504 
505 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
506 
507 #endif // SQLDEFS_H
Definition: sqldefs.h:71
SqlWindowFrameBoundType
Definition: sqldefs.h:149
SQLAgg
Definition: sqldefs.h:73
ViewRefreshOption
Definition: sqldefs.h:162
SqlStringOpKind name_to_string_op_kind(const std::string &func_name)
Definition: sqldefs.h:349
Definition: sqldefs.h:160
JoinType
Definition: sqldefs.h:164
SQLQualifier
Definition: sqldefs.h:71
#define LOG(tag)
Definition: Logger.h:216
std::ostream & operator<<(std::ostream &os, const SessionInfo &session_info)
Definition: SessionInfo.cpp:57
SQLOps
Definition: sqldefs.h:28
Definition: sqldefs.h:34
Definition: sqldefs.h:35
Definition: sqldefs.h:37
#define UNREACHABLE()
Definition: Logger.h:266
SqlStringOpKind
Definition: sqldefs.h:88
Definition: sqldefs.h:48
Definition: sqldefs.h:29
Definition: sqldefs.h:40
Definition: sqldefs.h:75
Definition: sqldefs.h:36
Definition: sqldefs.h:77
Definition: sqldefs.h:71
std::string toString(const ExecutorDeviceType &device_type)
StorageOption
Definition: sqldefs.h:160
SQLStmtType
Definition: sqldefs.h:158
Definition: sqldefs.h:33
Definition: sqldefs.h:39
bool string_op_returns_string(const SqlStringOpKind kind)
Definition: sqldefs.h:423
Definition: sqldefs.h:71
Definition: sqldefs.h:160
Definition: sqldefs.h:31
Definition: sqldefs.h:78
Definition: sqldefs.h:162
SqlWindowFunctionKind
Definition: sqldefs.h:119
Definition: sqldefs.h:52
Definition: sqldefs.h:30
Definition: sqldefs.h:32
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:38
Definition: sqldefs.h:83
Definition: sqldefs.h:160