1 | #include "duckdb/common/enums/expression_type.hpp" |
---|---|
2 | |
3 | #include "duckdb/common/exception.hpp" |
4 | |
5 | using namespace std; |
6 | |
7 | namespace duckdb { |
8 | |
9 | string ExpressionTypeToString(ExpressionType type) { |
10 | switch (type) { |
11 | case ExpressionType::OPERATOR_CAST: |
12 | return "CAST"; |
13 | case ExpressionType::OPERATOR_NOT: |
14 | return "NOT"; |
15 | case ExpressionType::OPERATOR_IS_NULL: |
16 | return "IS_NULL"; |
17 | case ExpressionType::OPERATOR_IS_NOT_NULL: |
18 | return "IS_NOT_NULL"; |
19 | case ExpressionType::COMPARE_EQUAL: |
20 | return "EQUAL"; |
21 | case ExpressionType::COMPARE_NOTEQUAL: |
22 | return "NOTEQUAL"; |
23 | case ExpressionType::COMPARE_LESSTHAN: |
24 | return "LESSTHAN"; |
25 | case ExpressionType::COMPARE_GREATERTHAN: |
26 | return "GREATERTHAN"; |
27 | case ExpressionType::COMPARE_LESSTHANOREQUALTO: |
28 | return "LESSTHANOREQUALTO"; |
29 | case ExpressionType::COMPARE_GREATERTHANOREQUALTO: |
30 | return "GREATERTHANOREQUALTO"; |
31 | case ExpressionType::COMPARE_IN: |
32 | return "IN"; |
33 | case ExpressionType::COMPARE_DISTINCT_FROM: |
34 | return "DISTINCT_FROM"; |
35 | case ExpressionType::CONJUNCTION_AND: |
36 | return "AND"; |
37 | case ExpressionType::CONJUNCTION_OR: |
38 | return "OR"; |
39 | case ExpressionType::VALUE_CONSTANT: |
40 | return "CONSTANT"; |
41 | case ExpressionType::VALUE_PARAMETER: |
42 | return "PARAMETER"; |
43 | case ExpressionType::VALUE_TUPLE: |
44 | return "TUPLE"; |
45 | case ExpressionType::VALUE_TUPLE_ADDRESS: |
46 | return "TUPLE_ADDRESS"; |
47 | case ExpressionType::VALUE_NULL: |
48 | return "NULL"; |
49 | case ExpressionType::VALUE_VECTOR: |
50 | return "VECTOR"; |
51 | case ExpressionType::VALUE_SCALAR: |
52 | return "SCALAR"; |
53 | case ExpressionType::AGGREGATE: |
54 | return "AGGREGATE"; |
55 | case ExpressionType::WINDOW_AGGREGATE: |
56 | return "WINDOW_AGGREGATE"; |
57 | case ExpressionType::WINDOW_RANK: |
58 | return "RANK"; |
59 | case ExpressionType::WINDOW_RANK_DENSE: |
60 | return "RANK_DENSE"; |
61 | case ExpressionType::WINDOW_PERCENT_RANK: |
62 | return "PERCENT_RANK"; |
63 | case ExpressionType::WINDOW_ROW_NUMBER: |
64 | return "ROW_NUMBER"; |
65 | case ExpressionType::WINDOW_FIRST_VALUE: |
66 | return "FIRST_VALUE"; |
67 | case ExpressionType::WINDOW_LAST_VALUE: |
68 | return "LAST_VALUE"; |
69 | case ExpressionType::WINDOW_CUME_DIST: |
70 | return "CUME_DIST"; |
71 | case ExpressionType::WINDOW_LEAD: |
72 | return "LEAD"; |
73 | case ExpressionType::WINDOW_LAG: |
74 | return "LAG"; |
75 | case ExpressionType::WINDOW_NTILE: |
76 | return "NTILE"; |
77 | case ExpressionType::FUNCTION: |
78 | return "FUNCTION"; |
79 | case ExpressionType::CASE_EXPR: |
80 | return "CASE"; |
81 | case ExpressionType::OPERATOR_NULLIF: |
82 | return "NULLIF"; |
83 | case ExpressionType::OPERATOR_COALESCE: |
84 | return "COALESCE"; |
85 | case ExpressionType::SUBQUERY: |
86 | return "SUBQUERY"; |
87 | case ExpressionType::STAR: |
88 | return "STAR"; |
89 | case ExpressionType::PLACEHOLDER: |
90 | return "PLACEHOLDER"; |
91 | case ExpressionType::COLUMN_REF: |
92 | return "COLUMN_REF"; |
93 | case ExpressionType::FUNCTION_REF: |
94 | return "FUNCTION_REF"; |
95 | case ExpressionType::TABLE_REF: |
96 | return "TABLE_REF"; |
97 | case ExpressionType::CAST: |
98 | return "CAST"; |
99 | case ExpressionType::COMPARE_NOT_IN: |
100 | return "COMPARE_NOT_IN"; |
101 | case ExpressionType::COMPARE_BETWEEN: |
102 | return "COMPARE_BETWEEN"; |
103 | case ExpressionType::COMPARE_NOT_BETWEEN: |
104 | return "COMPARE_NOT_BETWEEN"; |
105 | case ExpressionType::VALUE_DEFAULT: |
106 | return "VALUE_DEFAULT"; |
107 | case ExpressionType::COMMON_SUBEXPRESSION: |
108 | return "COMMON_SUBEXPRESSION"; |
109 | case ExpressionType::BOUND_REF: |
110 | return "BOUND_REF"; |
111 | case ExpressionType::BOUND_COLUMN_REF: |
112 | return "BOUND_COLUMN_REF"; |
113 | case ExpressionType::BOUND_FUNCTION: |
114 | return "BOUND_FUNCTION"; |
115 | case ExpressionType::BOUND_AGGREGATE: |
116 | return "BOUND_AGGREGATE"; |
117 | case ExpressionType::INVALID: |
118 | default: |
119 | return "INVALID"; |
120 | } |
121 | } |
122 | |
123 | string ExpressionTypeToOperator(ExpressionType type) { |
124 | switch (type) { |
125 | case ExpressionType::OPERATOR_NOT: |
126 | return "!"; |
127 | case ExpressionType::COMPARE_EQUAL: |
128 | return "="; |
129 | case ExpressionType::COMPARE_NOTEQUAL: |
130 | return "!="; |
131 | case ExpressionType::COMPARE_LESSTHAN: |
132 | return "<"; |
133 | case ExpressionType::COMPARE_GREATERTHAN: |
134 | return ">"; |
135 | case ExpressionType::COMPARE_LESSTHANOREQUALTO: |
136 | return "<="; |
137 | case ExpressionType::COMPARE_GREATERTHANOREQUALTO: |
138 | return ">="; |
139 | case ExpressionType::CONJUNCTION_AND: |
140 | return "AND"; |
141 | case ExpressionType::CONJUNCTION_OR: |
142 | return "OR"; |
143 | case ExpressionType::STAR: |
144 | return "*"; |
145 | default: |
146 | return ""; |
147 | } |
148 | } |
149 | |
150 | ExpressionType NegateComparisionExpression(ExpressionType type) { |
151 | ExpressionType negated_type = ExpressionType::INVALID; |
152 | switch (type) { |
153 | case ExpressionType::COMPARE_EQUAL: |
154 | negated_type = ExpressionType::COMPARE_NOTEQUAL; |
155 | break; |
156 | case ExpressionType::COMPARE_NOTEQUAL: |
157 | negated_type = ExpressionType::COMPARE_EQUAL; |
158 | break; |
159 | case ExpressionType::COMPARE_LESSTHAN: |
160 | negated_type = ExpressionType::COMPARE_GREATERTHANOREQUALTO; |
161 | break; |
162 | case ExpressionType::COMPARE_GREATERTHAN: |
163 | negated_type = ExpressionType::COMPARE_LESSTHANOREQUALTO; |
164 | break; |
165 | case ExpressionType::COMPARE_LESSTHANOREQUALTO: |
166 | negated_type = ExpressionType::COMPARE_GREATERTHAN; |
167 | break; |
168 | case ExpressionType::COMPARE_GREATERTHANOREQUALTO: |
169 | negated_type = ExpressionType::COMPARE_LESSTHAN; |
170 | break; |
171 | |
172 | default: |
173 | throw Exception("Unsupported comparison type in negation"); |
174 | } |
175 | return negated_type; |
176 | } |
177 | |
178 | ExpressionType FlipComparisionExpression(ExpressionType type) { |
179 | ExpressionType flipped_type = ExpressionType::INVALID; |
180 | switch (type) { |
181 | case ExpressionType::COMPARE_NOTEQUAL: |
182 | case ExpressionType::COMPARE_EQUAL: |
183 | flipped_type = type; |
184 | break; |
185 | case ExpressionType::COMPARE_LESSTHAN: |
186 | flipped_type = ExpressionType::COMPARE_GREATERTHAN; |
187 | break; |
188 | case ExpressionType::COMPARE_GREATERTHAN: |
189 | flipped_type = ExpressionType::COMPARE_LESSTHAN; |
190 | break; |
191 | case ExpressionType::COMPARE_LESSTHANOREQUALTO: |
192 | flipped_type = ExpressionType::COMPARE_GREATERTHANOREQUALTO; |
193 | break; |
194 | case ExpressionType::COMPARE_GREATERTHANOREQUALTO: |
195 | flipped_type = ExpressionType::COMPARE_LESSTHANOREQUALTO; |
196 | break; |
197 | |
198 | default: |
199 | throw Exception("Unsupported comparison type in flip"); |
200 | } |
201 | return flipped_type; |
202 | } |
203 | |
204 | } // namespace duckdb |
205 |