OmniSciDB  085a039ca4
 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 2017 MapD Technologies, 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 
24 #ifndef SQLDEFS_H
25 #define SQLDEFS_H
26 
27 // must not change the order without keeping the array in OperExpr::to_string
28 // in sync.
29 enum SQLOps {
30  kEQ = 0,
32  kNE,
33  kLT,
34  kGT,
35  kLE,
36  kGE,
38  kOR,
53  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 {
83 };
84 
85 enum class SqlStringOpKind {
86  /* Unary */
87  LOWER = 1,
88  UPPER,
89  INITCAP,
90  REVERSE,
91  /* Binary */
92  REPEAT,
93  CONCAT,
94  RCONCAT,
95  /* Ternary */
96  LPAD,
97  RPAD,
98  TRIM,
99  LTRIM,
100  RTRIM,
101  SUBSTRING,
102  OVERLAY,
103  REPLACE,
104  SPLIT_PART,
105  /* 6 args */
108  INVALID
109 };
110 
112  ROW_NUMBER,
113  RANK,
114  DENSE_RANK,
115  PERCENT_RANK,
116  CUME_DIST,
117  NTILE,
118  LAG,
119  LEAD,
120  FIRST_VALUE,
121  LAST_VALUE,
122  AVG,
123  MIN,
124  MAX,
125  SUM,
126  COUNT,
127  SUM_INTERNAL // For deserialization from Calcite only. Gets rewritten to a regular SUM.
128 };
129 
131 
132 enum StorageOption { kDISK = 0, kGPU = 1, kCPU = 2 };
133 
134 enum ViewRefreshOption { kMANUAL = 0, kAUTO = 1, kIMMEDIATE = 2 };
135 
136 enum class JoinType { INNER, LEFT, SEMI, ANTI, INVALID };
137 
138 #if !(defined(__CUDACC__) || defined(NO_BOOST))
139 
140 #include <string>
141 #include "Logger/Logger.h"
142 
143 inline std::string toString(const JoinType& join_type) {
144  switch (join_type) {
145  case JoinType::INNER:
146  return "INNER";
147  case JoinType::LEFT:
148  return "LEFT";
149  case JoinType::SEMI:
150  return "SEMI";
151  case JoinType::ANTI:
152  return "ANTI";
153  default:
154  return "INVALID";
155  }
156 }
157 
158 inline std::string toString(const SQLQualifier& qualifier) {
159  switch (qualifier) {
160  case kONE:
161  return "ONE";
162  case kANY:
163  return "ANY";
164  case kALL:
165  return "ALL";
166  }
167  LOG(FATAL) << "Invalid SQLQualifier: " << qualifier;
168  return "";
169 }
170 
171 inline std::string toString(const SQLAgg& kind) {
172  switch (kind) {
173  case kAVG:
174  return "AVG";
175  case kMIN:
176  return "MIN";
177  case kMAX:
178  return "MAX";
179  case kSUM:
180  return "SUM";
181  case kCOUNT:
182  return "COUNT";
184  return "APPROX_COUNT_DISTINCT";
185  case kAPPROX_QUANTILE:
186  return "APPROX_PERCENTILE";
187  case kSAMPLE:
188  return "SAMPLE";
189  case kSINGLE_VALUE:
190  return "SINGLE_VALUE";
191  }
192  LOG(FATAL) << "Invalid aggregate kind: " << kind;
193  return "";
194 }
195 
196 inline std::string toString(const SQLOps& op) {
197  switch (op) {
198  case kEQ:
199  return "EQ";
200  case kBW_EQ:
201  return "BW_EQ";
202  case kNE:
203  return "NE";
204  case kLT:
205  return "LT";
206  case kGT:
207  return "GT";
208  case kLE:
209  return "LE";
210  case kGE:
211  return "GE";
212  case kAND:
213  return "AND";
214  case kOR:
215  return "OR";
216  case kNOT:
217  return "NOT";
218  case kMINUS:
219  return "MINUS";
220  case kPLUS:
221  return "PLUS";
222  case kMULTIPLY:
223  return "MULTIPLY";
224  case kDIVIDE:
225  return "DIVIDE";
226  case kMODULO:
227  return "MODULO";
228  case kUMINUS:
229  return "UMINUS";
230  case kISNULL:
231  return "ISNULL";
232  case kISNOTNULL:
233  return "ISNOTNULL";
234  case kEXISTS:
235  return "EXISTS";
236  case kCAST:
237  return "CAST";
238  case kARRAY_AT:
239  return "ARRAY_AT";
240  case kUNNEST:
241  return "UNNEST";
242  case kFUNCTION:
243  return "FUNCTION";
244  case kIN:
245  return "IN";
246  case kOVERLAPS:
247  return "OVERLAPS";
248  case kENCODE_TEXT:
249  return "ENCODE_TEXT";
250  }
251  LOG(FATAL) << "Invalid operation kind: " << op;
252  return "";
253 }
254 
255 inline SqlStringOpKind name_to_string_op_kind(const std::string& func_name) {
256  if (func_name == "LOWER") {
257  return SqlStringOpKind::LOWER;
258  }
259  if (func_name == "UPPER") {
260  return SqlStringOpKind::UPPER;
261  }
262  if (func_name == "INITCAP") {
264  }
265  if (func_name == "REVERSE") {
267  }
268  if (func_name == "REPEAT") {
270  }
271  if (func_name == "||") {
273  }
274  if (func_name == "LPAD") {
275  return SqlStringOpKind::LPAD;
276  }
277  if (func_name == "RPAD") {
278  return SqlStringOpKind::RPAD;
279  }
280  if (func_name == "TRIM") {
281  return SqlStringOpKind::TRIM;
282  }
283  if (func_name == "LTRIM") {
284  return SqlStringOpKind::LTRIM;
285  }
286  if (func_name == "RTRIM") {
287  return SqlStringOpKind::RTRIM;
288  }
289  if (func_name == "SUBSTRING") {
291  }
292  if (func_name == "OVERLAY") {
294  }
295  if (func_name == "REPLACE") {
297  }
298  if (func_name == "SPLIT_PART") {
300  }
301  if (func_name == "REGEXP_REPLACE") {
303  }
304  if (func_name == "REGEXP_SUBSTR") {
306  }
307  if (func_name == "REGEXP_MATCH") {
309  }
310  LOG(FATAL) << "Invalid string function " << func_name << ".";
312 }
313 
314 inline std::string toString(const SqlStringOpKind& kind) {
315  switch (kind) {
317  return "LOWER";
319  return "UPPER";
321  return "INITCAP";
323  return "REVERSE";
325  return "REPEAT";
328  return "||";
330  return "LPAD";
332  return "RPAD";
334  return "TRIM";
336  return "LTRIM";
338  return "RTRIM";
340  return "SUBSTRING";
342  return "OVERLAY";
344  return "REPLACE";
346  return "SPLIT_PART";
348  return "REGEXP_REPLACE";
350  return "REGEXP_SUBSTR";
351  default:
352  LOG(FATAL) << "Invalid string operation";
353  }
354  return "";
355 }
356 
357 inline std::string toString(const SqlWindowFunctionKind& kind) {
358  switch (kind) {
360  return "ROW_NUMBER";
362  return "RANK";
364  return "DENSE_RANK";
366  return "PERCENT_RANK";
368  return "CUME_DIST";
370  return "NTILE";
372  return "LAG";
374  return "LEAD";
376  return "FIRST_VALUE";
378  return "LAST_VALUE";
380  return "AVG";
382  return "MIN";
384  return "MAX";
386  return "SUM";
388  return "COUNT";
390  return "SUM_INTERNAL";
391  }
392  LOG(FATAL) << "Invalid window function kind.";
393  return "";
394 }
395 
396 #endif // #if !(defined(__CUDACC__) || defined(NO_BOOST))
397 
398 #endif // SQLDEFS_H
Definition: sqldefs.h:71
SQLAgg
Definition: sqldefs.h:73
ViewRefreshOption
Definition: sqldefs.h:134
SqlStringOpKind name_to_string_op_kind(const std::string &func_name)
Definition: sqldefs.h:255
Definition: sqldefs.h:132
JoinType
Definition: sqldefs.h:136
SQLQualifier
Definition: sqldefs.h:71
#define LOG(tag)
Definition: Logger.h:217
SQLOps
Definition: sqldefs.h:29
Definition: sqldefs.h:35
Definition: sqldefs.h:36
Definition: sqldefs.h:38
SqlStringOpKind
Definition: sqldefs.h:85
Definition: sqldefs.h:49
Definition: sqldefs.h:30
Definition: sqldefs.h:41
Definition: sqldefs.h:75
Definition: sqldefs.h:37
Definition: sqldefs.h:77
Definition: sqldefs.h:71
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1453
StorageOption
Definition: sqldefs.h:132
SQLStmtType
Definition: sqldefs.h:130
Definition: sqldefs.h:34
Definition: sqldefs.h:40
Definition: sqldefs.h:71
Definition: sqldefs.h:132
Definition: sqldefs.h:32
Definition: sqldefs.h:78
Definition: sqldefs.h:134
SqlWindowFunctionKind
Definition: sqldefs.h:111
Definition: sqldefs.h:53
Definition: sqldefs.h:31
Definition: sqldefs.h:33
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:39
Definition: sqldefs.h:132