OmniSciDB  21ac014ffc
 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,
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 #define IS_EQUIVALENCE(X) ((X) == kEQ || (X) == kBW_EQ || (X) == kOVERLAPS)
68 
70 
71 enum SQLAgg {
81 };
82 
84  ROW_NUMBER,
85  RANK,
86  DENSE_RANK,
88  CUME_DIST,
89  NTILE,
90  LAG,
91  LEAD,
93  LAST_VALUE,
94  AVG,
95  MIN,
96  MAX,
97  SUM,
98  COUNT,
99  SUM_INTERNAL // For deserialization from Calcite only. Gets rewritten to a regular SUM.
100 };
101 
103 
104 enum StorageOption { kDISK = 0, kGPU = 1, kCPU = 2 };
105 
106 enum ViewRefreshOption { kMANUAL = 0, kAUTO = 1, kIMMEDIATE = 2 };
107 
108 enum class JoinType { INNER, LEFT, SEMI, ANTI, INVALID };
109 
110 #ifndef __CUDACC__
111 
112 #include <string>
113 #include "Logger/Logger.h"
114 
115 inline std::string toString(const SQLQualifier& qualifier) {
116  switch (qualifier) {
117  case kONE:
118  return "ONE";
119  case kANY:
120  return "ANY";
121  case kALL:
122  return "ALL";
123  }
124  LOG(FATAL) << "Invalid SQLQualifier: " << qualifier;
125  return "";
126 }
127 
128 inline std::string toString(const SQLAgg& kind) {
129  switch (kind) {
130  case kAVG:
131  return "AVG";
132  case kMIN:
133  return "MIN";
134  case kMAX:
135  return "MAX";
136  case kSUM:
137  return "SUM";
138  case kCOUNT:
139  return "COUNT";
141  return "APPROX_COUNT_DISTINCT";
142  case kAPPROX_QUANTILE:
143  return "APPROX_QUANTILE";
144  case kSAMPLE:
145  return "SAMPLE";
146  case kSINGLE_VALUE:
147  return "SINGLE_VALUE";
148  }
149  LOG(FATAL) << "Invalid aggregate kind: " << kind;
150  return "";
151 }
152 
153 inline std::string toString(const SQLOps& op) {
154  switch (op) {
155  case kEQ:
156  return "EQ";
157  case kBW_EQ:
158  return "BW_EQ";
159  case kNE:
160  return "NE";
161  case kLT:
162  return "LT";
163  case kGT:
164  return "GT";
165  case kLE:
166  return "LE";
167  case kGE:
168  return "GE";
169  case kAND:
170  return "AND";
171  case kOR:
172  return "OR";
173  case kNOT:
174  return "NOT";
175  case kMINUS:
176  return "MINUS";
177  case kPLUS:
178  return "PLUS";
179  case kMULTIPLY:
180  return "MULTIPLY";
181  case kDIVIDE:
182  return "DIVIDE";
183  case kMODULO:
184  return "MODULO";
185  case kUMINUS:
186  return "UMINUS";
187  case kISNULL:
188  return "ISNULL";
189  case kISNOTNULL:
190  return "ISNOTNULL";
191  case kEXISTS:
192  return "EXISTS";
193  case kCAST:
194  return "CAST";
195  case kARRAY_AT:
196  return "ARRAY_AT";
197  case kUNNEST:
198  return "UNNEST";
199  case kFUNCTION:
200  return "FUNCTION";
201  case kIN:
202  return "IN";
203  case kOVERLAPS:
204  return "OVERLAPS";
205  }
206  LOG(FATAL) << "Invalid operation kind: " << op;
207  return "";
208 }
209 
210 inline std::string toString(const SqlWindowFunctionKind& kind) {
211  switch (kind) {
213  return "ROW_NUMBER";
215  return "RANK";
217  return "DENSE_RANK";
219  return "PERCENT_RANK";
221  return "CUME_DIST";
223  return "NTILE";
225  return "LAG";
227  return "LEAD";
229  return "FIRST_VALUE";
231  return "LAST_VALUE";
233  return "AVG";
235  return "MIN";
237  return "MAX";
239  return "SUM";
241  return "COUNT";
243  return "SUM_INTERNAL";
244  }
245  LOG(FATAL) << "Invalid window function kind.";
246  return "";
247 }
248 
249 #endif
250 
251 #endif // SQLDEFS_H
Definition: sqldefs.h:69
SQLAgg
Definition: sqldefs.h:71
ViewRefreshOption
Definition: sqldefs.h:106
Definition: sqldefs.h:104
JoinType
Definition: sqldefs.h:108
std::string toString(const ExtArgumentType &sig_type)
SQLQualifier
Definition: sqldefs.h:69
#define LOG(tag)
Definition: Logger.h:200
SQLOps
Definition: sqldefs.h:29
Definition: sqldefs.h:35
Definition: sqldefs.h:36
Definition: sqldefs.h:38
Definition: sqldefs.h:49
Definition: sqldefs.h:30
Definition: sqldefs.h:41
Definition: sqldefs.h:73
Definition: sqldefs.h:37
Definition: sqldefs.h:75
Definition: sqldefs.h:69
StorageOption
Definition: sqldefs.h:104
SQLStmtType
Definition: sqldefs.h:102
Definition: sqldefs.h:34
Definition: sqldefs.h:40
Definition: sqldefs.h:69
Definition: sqldefs.h:104
Definition: sqldefs.h:32
Definition: sqldefs.h:76
Definition: sqldefs.h:106
SqlWindowFunctionKind
Definition: sqldefs.h:83
Definition: sqldefs.h:53
Definition: sqldefs.h:31
Definition: sqldefs.h:33
Definition: sqldefs.h:74
Definition: sqldefs.h:72
Definition: sqldefs.h:39
Definition: sqldefs.h:104