OmniSciDB  ca0c39ec8f
 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  JSON_VALUE,
111  INVALID
112 };
113 
115  // set MIN's enum val as one, and we use window function kind's enum vals
116  // to classify a behavior of our runtime code for window framing
117  // i.e., aggregate_##value_type##_values functions
118  // todo (yoonmin): support FIRST_EXPR, LAST_EXPR, AND NTH_EXPR with framing
119  MIN = 1,
120  MAX,
121  AVG,
122  SUM,
123  COUNT,
124  FIRST_EXPR,
125  LAST_EXPR,
126  NTH_EXPR,
127  ROW_NUMBER,
128  RANK,
129  DENSE_RANK,
130  PERCENT_RANK,
131  CUME_DIST,
132  NTILE,
133  LAG,
134  LAG_IN_FRAME,
135  LEAD,
137  FIRST_VALUE,
138  LAST_VALUE,
139  SUM_INTERNAL // For deserialization from Calcite only. Gets rewritten to a regular SUM.
140 };
141 
145  CURRENT_ROW,
148  UNKNOWN
149 };
150 
152 
153 enum StorageOption { kDISK = 0, kGPU = 1, kCPU = 2 };
154 
155 enum ViewRefreshOption { kMANUAL = 0, kAUTO = 1, kIMMEDIATE = 2 };
156 
157 enum class JoinType { INNER, LEFT, SEMI, ANTI, INVALID };
158 
159 #if !(defined(__CUDACC__) || defined(NO_BOOST))
160 
161 #include <sstream>
162 #include <string>
163 #include "Logger/Logger.h"
164 
165 inline std::string toString(const JoinType& join_type) {
166  switch (join_type) {
167  case JoinType::INNER:
168  return "INNER";
169  case JoinType::LEFT:
170  return "LEFT";
171  case JoinType::SEMI:
172  return "SEMI";
173  case JoinType::ANTI:
174  return "ANTI";
175  default:
176  return "INVALID";
177  }
178 }
179 
180 inline std::string toString(const SQLQualifier& qualifier) {
181  switch (qualifier) {
182  case kONE:
183  return "ONE";
184  case kANY:
185  return "ANY";
186  case kALL:
187  return "ALL";
188  }
189  LOG(FATAL) << "Invalid SQLQualifier: " << qualifier;
190  return "";
191 }
192 
193 inline std::string toString(const SQLAgg& kind) {
194  switch (kind) {
195  case kAVG:
196  return "AVG";
197  case kMIN:
198  return "MIN";
199  case kMAX:
200  return "MAX";
201  case kSUM:
202  return "SUM";
203  case kCOUNT:
204  return "COUNT";
206  return "APPROX_COUNT_DISTINCT";
207  case kAPPROX_QUANTILE:
208  return "APPROX_PERCENTILE";
209  case kSAMPLE:
210  return "SAMPLE";
211  case kSINGLE_VALUE:
212  return "SINGLE_VALUE";
213  }
214  LOG(FATAL) << "Invalid aggregate kind: " << kind;
215  return "";
216 }
217 
218 inline std::string toString(const SQLOps& op) {
219  switch (op) {
220  case kEQ:
221  return "EQ";
222  case kBW_EQ:
223  return "BW_EQ";
224  case kNE:
225  return "NE";
226  case kLT:
227  return "LT";
228  case kGT:
229  return "GT";
230  case kLE:
231  return "LE";
232  case kGE:
233  return "GE";
234  case kAND:
235  return "AND";
236  case kOR:
237  return "OR";
238  case kNOT:
239  return "NOT";
240  case kMINUS:
241  return "MINUS";
242  case kPLUS:
243  return "PLUS";
244  case kMULTIPLY:
245  return "MULTIPLY";
246  case kDIVIDE:
247  return "DIVIDE";
248  case kMODULO:
249  return "MODULO";
250  case kUMINUS:
251  return "UMINUS";
252  case kISNULL:
253  return "ISNULL";
254  case kISNOTNULL:
255  return "ISNOTNULL";
256  case kEXISTS:
257  return "EXISTS";
258  case kCAST:
259  return "CAST";
260  case kARRAY_AT:
261  return "ARRAY_AT";
262  case kUNNEST:
263  return "UNNEST";
264  case kFUNCTION:
265  return "FUNCTION";
266  case kIN:
267  return "IN";
268  case kOVERLAPS:
269  return "OVERLAPS";
270  case kENCODE_TEXT:
271  return "ENCODE_TEXT";
272  }
273  LOG(FATAL) << "Invalid operation kind: " << op;
274  return "";
275 }
276 
277 inline std::ostream& operator<<(std::ostream& os, const SqlStringOpKind kind) {
278  switch (kind) {
280  return os << "LOWER";
282  return os << "UPPER";
284  return os << "INITCAP";
286  return os << "REVERSE";
288  return os << "REPEAT";
290  return os << "CONCAT";
292  return os << "RCONCAT";
294  return os << "LPAD";
296  return os << "RPAD";
298  return os << "TRIM";
300  return os << "LTRIM";
302  return os << "RTRIM";
304  return os << "SUBSTRING";
306  return os << "OVERLAY";
308  return os << "REPLACE";
310  return os << "SPLIT_PART";
312  return os << "REGEXP_REPLACE";
314  return os << "REGEXP_SUBSTR";
316  return os << "JSON_VALUE";
318  return os << "BASE64_ENCODE";
320  return os << "BASE64_DECODE";
322  return os << "TRY_STRING_CAST";
324  return os << "INVALID";
325  }
326  LOG(FATAL) << "Invalid string operation";
327  // Make compiler happy
328  return os << "INVALID";
329 }
330 
331 inline SqlStringOpKind name_to_string_op_kind(const std::string& func_name) {
332  if (func_name == "LOWER") {
333  return SqlStringOpKind::LOWER;
334  }
335  if (func_name == "UPPER") {
336  return SqlStringOpKind::UPPER;
337  }
338  if (func_name == "INITCAP") {
340  }
341  if (func_name == "REVERSE") {
343  }
344  if (func_name == "REPEAT") {
346  }
347  if (func_name == "||") {
349  }
350  if (func_name == "LPAD") {
351  return SqlStringOpKind::LPAD;
352  }
353  if (func_name == "RPAD") {
354  return SqlStringOpKind::RPAD;
355  }
356  if (func_name == "TRIM") {
357  return SqlStringOpKind::TRIM;
358  }
359  if (func_name == "LTRIM") {
360  return SqlStringOpKind::LTRIM;
361  }
362  if (func_name == "RTRIM") {
363  return SqlStringOpKind::RTRIM;
364  }
365  if (func_name == "SUBSTRING") {
367  }
368  if (func_name == "OVERLAY") {
370  }
371  if (func_name == "REPLACE") {
373  }
374  if (func_name == "SPLIT_PART") {
376  }
377  if (func_name == "REGEXP_REPLACE") {
379  }
380  if (func_name == "REGEXP_SUBSTR") {
382  }
383  if (func_name == "REGEXP_MATCH") {
385  }
386  if (func_name == "JSON_VALUE") {
388  }
389  if (func_name == "BASE64_ENCODE") {
391  }
392  if (func_name == "BASE64_DECODE") {
394  }
395  if (func_name == "TRY_CAST") {
397  }
398  LOG(FATAL) << "Invalid string function " << func_name << ".";
400 }
401 
402 inline std::string toString(const SqlWindowFunctionKind& kind) {
403  switch (kind) {
405  return "ROW_NUMBER";
407  return "RANK";
409  return "DENSE_RANK";
411  return "PERCENT_RANK";
413  return "CUME_DIST";
415  return "NTILE";
417  return "LAG";
419  return "LEAD";
421  return "FIRST_VALUE";
423  return "LAST_VALUE";
425  return "AVG";
427  return "MIN";
429  return "MAX";
431  return "SUM";
433  return "COUNT";
435  return "SUM_INTERNAL";
437  return "FIRST_EXPR";
439  return "LAST_EXPR";
441  return "NTH_EXPR";
443  return "LEAD_IN_FRAME";
445  return "LAG_IN_FRAME";
446  }
447  LOG(FATAL) << "Invalid window function kind.";
448  return "";
449 }
450 
451 inline std::string toString(const SqlWindowFrameBoundType& kind) {
452  switch (kind) {
454  return "UNBOUNDED_PRECEDING";
456  return "EXPR_PRECEDING";
458  return "CURRENT_ROW";
460  return "EXPR_FOLLOWING";
462  return "UNBOUNDED_FOLLOWING";
464  return "UNKNOWN";
465  }
466  LOG(FATAL) << "Invalid window function bound type.";
467  return "";
468 }
469 
470 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
471 
472 #endif // SQLDEFS_H
Definition: sqldefs.h:70
SqlWindowFrameBoundType
Definition: sqldefs.h:142
SQLAgg
Definition: sqldefs.h:72
ViewRefreshOption
Definition: sqldefs.h:155
SqlStringOpKind name_to_string_op_kind(const std::string &func_name)
Definition: sqldefs.h:331
Definition: sqldefs.h:153
JoinType
Definition: sqldefs.h:157
SQLQualifier
Definition: sqldefs.h:70
#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
SqlStringOpKind
Definition: sqldefs.h:84
Definition: sqldefs.h:48
Definition: sqldefs.h:29
Definition: sqldefs.h:40
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
Definition: sqldefs.h:74
Definition: sqldefs.h:36
Definition: sqldefs.h:76
Definition: sqldefs.h:70
StorageOption
Definition: sqldefs.h:153
SQLStmtType
Definition: sqldefs.h:151
Definition: sqldefs.h:33
Definition: sqldefs.h:39
Definition: sqldefs.h:70
Definition: sqldefs.h:153
Definition: sqldefs.h:31
Definition: sqldefs.h:77
Definition: sqldefs.h:155
SqlWindowFunctionKind
Definition: sqldefs.h:114
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:153