OmniSciDB  17c254d2f8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Analyzer.cpp
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 
25 #include "Analyzer.h"
26 #include "../Catalog/Catalog.h"
27 #include "../QueryEngine/DateTimeUtils.h"
28 #include "../Shared/DateConverters.h"
29 #include "../Shared/sql_type_to_string.h"
30 #include "../Shared/sql_window_function_to_string.h"
31 #include "../Shared/sqltypes.h"
32 #include "RangeTableEntry.h"
33 
34 #include <algorithm>
35 #include <cstring>
36 #include <iostream>
37 #include <stdexcept>
38 
39 namespace Analyzer {
40 
42  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
43  delete constval.stringval;
44  }
45 }
46 
48  delete parsetree;
49 }
50 
52  for (auto p : rangetable) {
53  delete p;
54  }
55  delete order_by;
56  delete next_query;
57 }
58 
59 std::shared_ptr<Analyzer::Expr> ColumnVar::deep_copy() const {
60  return makeExpr<ColumnVar>(type_info, table_id, column_id, rte_idx);
61 }
62 
63 void ExpressionTuple::collect_rte_idx(std::set<int>& rte_idx_set) const {
64  for (const auto& column : tuple_) {
65  column->collect_rte_idx(rte_idx_set);
66  }
67 }
68 
69 std::shared_ptr<Analyzer::Expr> ExpressionTuple::deep_copy() const {
70  std::vector<std::shared_ptr<Expr>> tuple_deep_copy;
71  for (const auto& column : tuple_) {
72  const auto column_deep_copy =
73  std::dynamic_pointer_cast<Analyzer::ColumnVar>(column->deep_copy());
74  CHECK(column_deep_copy);
75  tuple_deep_copy.push_back(column_deep_copy);
76  }
77  return makeExpr<ExpressionTuple>(tuple_deep_copy);
78 }
79 
80 std::shared_ptr<Analyzer::Expr> Var::deep_copy() const {
81  return makeExpr<Var>(type_info, table_id, column_id, rte_idx, which_row, varno);
82 }
83 
84 std::shared_ptr<Analyzer::Expr> Constant::deep_copy() const {
85  Datum d = constval;
86  if ((type_info.is_string() || type_info.is_geometry()) && !is_null) {
87  d.stringval = new std::string(*constval.stringval);
88  }
89  if (type_info.get_type() == kARRAY) {
90  return makeExpr<Constant>(type_info, is_null, value_list);
91  }
92  return makeExpr<Constant>(type_info, is_null, d);
93 }
94 
95 std::shared_ptr<Analyzer::Expr> UOper::deep_copy() const {
96  return makeExpr<UOper>(type_info, contains_agg, optype, operand->deep_copy());
97 }
98 
99 std::shared_ptr<Analyzer::Expr> BinOper::deep_copy() const {
100  return makeExpr<BinOper>(type_info,
101  contains_agg,
102  optype,
103  qualifier,
104  left_operand->deep_copy(),
105  right_operand->deep_copy());
106 }
107 
108 std::shared_ptr<Analyzer::Expr> Subquery::deep_copy() const {
109  // not supported yet.
110  CHECK(false);
111  return nullptr;
112 }
113 
114 std::shared_ptr<Analyzer::Expr> InValues::deep_copy() const {
115  std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
116  for (auto p : value_list) {
117  new_value_list.push_back(p->deep_copy());
118  }
119  return makeExpr<InValues>(arg->deep_copy(), new_value_list);
120 }
121 
122 std::shared_ptr<Analyzer::Expr> CharLengthExpr::deep_copy() const {
123  return makeExpr<CharLengthExpr>(arg->deep_copy(), calc_encoded_length);
124 }
125 
126 std::shared_ptr<Analyzer::Expr> KeyForStringExpr::deep_copy() const {
127  return makeExpr<KeyForStringExpr>(arg->deep_copy());
128 }
129 
130 std::shared_ptr<Analyzer::Expr> LowerExpr::deep_copy() const {
131  return makeExpr<LowerExpr>(arg->deep_copy());
132 }
133 
134 std::shared_ptr<Analyzer::Expr> CardinalityExpr::deep_copy() const {
135  return makeExpr<CardinalityExpr>(arg->deep_copy());
136 }
137 
138 std::shared_ptr<Analyzer::Expr> LikeExpr::deep_copy() const {
139  return makeExpr<LikeExpr>(arg->deep_copy(),
140  like_expr->deep_copy(),
141  escape_expr ? escape_expr->deep_copy() : nullptr,
142  is_ilike,
143  is_simple);
144 }
145 
146 std::shared_ptr<Analyzer::Expr> RegexpExpr::deep_copy() const {
147  return makeExpr<RegexpExpr>(arg->deep_copy(),
148  pattern_expr->deep_copy(),
149  escape_expr ? escape_expr->deep_copy() : nullptr);
150 }
151 
152 std::shared_ptr<Analyzer::Expr> LikelihoodExpr::deep_copy() const {
153  return makeExpr<LikelihoodExpr>(arg->deep_copy(), likelihood);
154 }
155 std::shared_ptr<Analyzer::Expr> AggExpr::deep_copy() const {
156  return makeExpr<AggExpr>(type_info,
157  aggtype,
158  arg == nullptr ? nullptr : arg->deep_copy(),
159  is_distinct,
160  error_rate);
161 }
162 
163 std::shared_ptr<Analyzer::Expr> CaseExpr::deep_copy() const {
164  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
165  new_list;
166  for (auto p : expr_pair_list) {
167  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
168  }
169  return makeExpr<CaseExpr>(type_info,
170  contains_agg,
171  new_list,
172  else_expr == nullptr ? nullptr : else_expr->deep_copy());
173 }
174 
175 std::shared_ptr<Analyzer::Expr> ExtractExpr::deep_copy() const {
176  return makeExpr<ExtractExpr>(type_info, contains_agg, field_, from_expr_->deep_copy());
177 }
178 
179 std::shared_ptr<Analyzer::Expr> DateaddExpr::deep_copy() const {
180  return makeExpr<DateaddExpr>(
181  type_info, field_, number_->deep_copy(), datetime_->deep_copy());
182 }
183 
184 std::shared_ptr<Analyzer::Expr> DatediffExpr::deep_copy() const {
185  return makeExpr<DatediffExpr>(
186  type_info, field_, start_->deep_copy(), end_->deep_copy());
187 }
188 
189 std::shared_ptr<Analyzer::Expr> DatetruncExpr::deep_copy() const {
190  return makeExpr<DatetruncExpr>(
191  type_info, contains_agg, field_, from_expr_->deep_copy());
192 }
193 
194 std::shared_ptr<Analyzer::Expr> OffsetInFragment::deep_copy() const {
195  return makeExpr<OffsetInFragment>();
196 }
197 
198 std::shared_ptr<Analyzer::Expr> WindowFunction::deep_copy() const {
199  return makeExpr<WindowFunction>(
201 }
202 
204  return makeExpr<Analyzer::ArrayExpr>(
206 }
207 
208 std::shared_ptr<Analyzer::Expr> GeoExpr::deep_copy() const {
209  return makeExpr<GeoExpr>(type_info, args_);
210 }
211 
213  const SQLTypeInfo& left_type,
214  const SQLTypeInfo& right_type,
215  SQLTypeInfo* new_left_type,
216  SQLTypeInfo* new_right_type) {
217  SQLTypeInfo result_type;
218  SQLTypeInfo common_type;
219  *new_left_type = left_type;
220  *new_right_type = right_type;
221  if (IS_LOGIC(op)) {
222  if (left_type.get_type() != kBOOLEAN || right_type.get_type() != kBOOLEAN) {
223  throw std::runtime_error(
224  "non-boolean operands cannot be used in logic operations.");
225  }
226  result_type = SQLTypeInfo(kBOOLEAN, false);
227  } else if (IS_COMPARISON(op)) {
228  if (left_type != right_type) {
229  if (left_type.is_number() && right_type.is_number()) {
230  common_type = common_numeric_type(left_type, right_type);
231  *new_left_type = common_type;
232  new_left_type->set_notnull(left_type.get_notnull());
233  *new_right_type = common_type;
234  new_right_type->set_notnull(right_type.get_notnull());
235  } else if (left_type.is_time() && right_type.is_time()) {
236  switch (left_type.get_type()) {
237  case kTIMESTAMP:
238  switch (right_type.get_type()) {
239  case kTIME:
240  throw std::runtime_error("Cannont compare between TIMESTAMP and TIME.");
241  break;
242  case kDATE:
243  *new_left_type = SQLTypeInfo(left_type.get_type(),
244  left_type.get_dimension(),
245  0,
246  left_type.get_notnull());
247  *new_right_type = *new_left_type;
248  new_right_type->set_notnull(right_type.get_notnull());
249  break;
250  case kTIMESTAMP:
251  *new_left_type = SQLTypeInfo(
252  kTIMESTAMP,
253  std::max(left_type.get_dimension(), right_type.get_dimension()),
254  0,
255  left_type.get_notnull());
256  *new_right_type = SQLTypeInfo(
257  kTIMESTAMP,
258  std::max(left_type.get_dimension(), right_type.get_dimension()),
259  0,
260  right_type.get_notnull());
261  break;
262  default:
263  CHECK(false);
264  }
265  break;
266  case kTIME:
267  switch (right_type.get_type()) {
268  case kTIMESTAMP:
269  throw std::runtime_error("Cannont compare between TIME and TIMESTAMP.");
270  break;
271  case kDATE:
272  throw std::runtime_error("Cannont compare between TIME and DATE.");
273  break;
274  case kTIME:
275  *new_left_type = SQLTypeInfo(
276  kTIME,
277  std::max(left_type.get_dimension(), right_type.get_dimension()),
278  0,
279  left_type.get_notnull());
280  *new_right_type = SQLTypeInfo(
281  kTIME,
282  std::max(left_type.get_dimension(), right_type.get_dimension()),
283  0,
284  right_type.get_notnull());
285  break;
286  default:
287  CHECK(false);
288  }
289  break;
290  case kDATE:
291  switch (right_type.get_type()) {
292  case kTIMESTAMP:
293  *new_left_type = SQLTypeInfo(right_type.get_type(),
294  right_type.get_dimension(),
295  0,
296  left_type.get_notnull());
297  *new_right_type = *new_left_type;
298  new_right_type->set_notnull(right_type.get_notnull());
299  break;
300  case kDATE:
301  *new_left_type = SQLTypeInfo(left_type.get_type(),
302  left_type.get_dimension(),
303  0,
304  left_type.get_notnull());
305  *new_right_type = *new_left_type;
306  new_right_type->set_notnull(right_type.get_notnull());
307  break;
308  case kTIME:
309  throw std::runtime_error("Cannont compare between DATE and TIME.");
310  break;
311  default:
312  CHECK(false);
313  }
314  break;
315  default:
316  CHECK(false);
317  }
318  } else if (left_type.is_string() && right_type.is_time()) {
319  *new_left_type = right_type;
320  new_left_type->set_notnull(left_type.get_notnull());
321  *new_right_type = right_type;
322  } else if (left_type.is_time() && right_type.is_string()) {
323  *new_left_type = left_type;
324  *new_right_type = left_type;
325  new_right_type->set_notnull(right_type.get_notnull());
326  } else if (left_type.is_string() && right_type.is_string()) {
327  *new_left_type = left_type;
328  *new_right_type = right_type;
329  } else if (left_type.is_boolean() && right_type.is_boolean()) {
330  const bool notnull = left_type.get_notnull() && right_type.get_notnull();
331  common_type = SQLTypeInfo(kBOOLEAN, notnull);
332  *new_left_type = common_type;
333  *new_right_type = common_type;
334  } else {
335  throw std::runtime_error("Cannot compare between " + left_type.get_type_name() +
336  " and " + right_type.get_type_name());
337  }
338  }
339  result_type = SQLTypeInfo(kBOOLEAN, false);
340  } else if (op == kMINUS &&
341  (left_type.get_type() == kDATE || left_type.get_type() == kTIMESTAMP) &&
342  right_type.is_timeinterval()) {
343  *new_left_type = left_type;
344  *new_right_type = right_type;
345  result_type = left_type;
346  } else if (IS_ARITHMETIC(op)) {
347  if (!(left_type.is_number() || left_type.is_timeinterval()) ||
348  !(right_type.is_number() || right_type.is_timeinterval())) {
349  throw std::runtime_error("non-numeric operands in arithmetic operations.");
350  }
351  if (op == kMODULO && (!left_type.is_integer() || !right_type.is_integer())) {
352  throw std::runtime_error("non-integer operands in modulo operation.");
353  }
354  common_type = common_numeric_type(left_type, right_type);
355  if (common_type.is_decimal()) {
356  if (op == kMULTIPLY) {
357  // Decimal multiplication requires common_type adjustment:
358  // dimension and scale of the result should be increased.
359  auto new_dimension = left_type.get_dimension() + right_type.get_dimension();
360  // If new dimension is over 20 digits, the result may overflow, or it may not.
361  // Rely on the runtime overflow detection rather than a static check here.
362  if (common_type.get_dimension() < new_dimension) {
363  common_type.set_dimension(new_dimension);
364  }
365  common_type.set_scale(left_type.get_scale() + right_type.get_scale());
366  } else if (op == kPLUS || op == kMINUS) {
367  // Scale should remain the same but dimension could actually go up
368  common_type.set_dimension(common_type.get_dimension() + 1);
369  }
370  }
371  *new_left_type = common_type;
372  new_left_type->set_notnull(left_type.get_notnull());
373  *new_right_type = common_type;
374  new_right_type->set_notnull(right_type.get_notnull());
375  if (op == kMULTIPLY) {
376  new_left_type->set_scale(left_type.get_scale());
377  new_right_type->set_scale(right_type.get_scale());
378  }
379  result_type = common_type;
380  } else {
381  throw std::runtime_error("invalid binary operator type.");
382  }
383  result_type.set_notnull(left_type.get_notnull() && right_type.get_notnull());
384  return result_type;
385 }
386 
388  const SQLTypeInfo& type2) {
389  SQLTypeInfo common_type;
391  int comp_param = 0;
392  CHECK(type1.is_string() && type2.is_string());
393  // if type1 and type2 have the same DICT encoding then keep it
394  // otherwise, they must be decompressed
395  if (type1.get_compression() == kENCODING_DICT &&
396  type2.get_compression() == kENCODING_DICT) {
397  if (type1.get_comp_param() == type2.get_comp_param() ||
398  type1.get_comp_param() == TRANSIENT_DICT(type2.get_comp_param())) {
399  comp = kENCODING_DICT;
400  comp_param = std::min(type1.get_comp_param(), type2.get_comp_param());
401  }
402  } else if (type1.get_compression() == kENCODING_DICT &&
403  type2.get_compression() == kENCODING_NONE) {
404  comp_param = type1.get_comp_param();
405  } else if (type1.get_compression() == kENCODING_NONE &&
406  type2.get_compression() == kENCODING_DICT) {
407  comp_param = type2.get_comp_param();
408  } else {
409  comp_param = std::max(type1.get_comp_param(),
410  type2.get_comp_param()); // preserve previous comp_param if set
411  }
412  const bool notnull = type1.get_notnull() && type2.get_notnull();
413  if (type1.get_type() == kTEXT || type2.get_type() == kTEXT) {
414  common_type = SQLTypeInfo(kTEXT, 0, 0, notnull, comp, comp_param, kNULLT);
415  return common_type;
416  }
417  common_type = SQLTypeInfo(kVARCHAR,
418  std::max(type1.get_dimension(), type2.get_dimension()),
419  0,
420  notnull,
421  comp,
422  comp_param,
423  kNULLT);
424  return common_type;
425 }
426 
428  const SQLTypeInfo& type2) {
429  SQLTypeInfo common_type;
430  const bool notnull = type1.get_notnull() && type2.get_notnull();
431  if (type1.get_type() == type2.get_type()) {
432  CHECK(((type1.is_number() || type1.is_timeinterval()) &&
433  (type2.is_number() || type2.is_timeinterval())) ||
434  (type1.is_boolean() && type2.is_boolean()));
435  common_type = SQLTypeInfo(type1.get_type(),
436  std::max(type1.get_dimension(), type2.get_dimension()),
437  std::max(type1.get_scale(), type2.get_scale()),
438  notnull);
439  return common_type;
440  }
441  std::string timeinterval_op_error{
442  "Operator type not supported for time interval arithmetic: "};
443  if (type1.is_timeinterval()) {
444  if (!type2.is_integer()) {
445  throw std::runtime_error(timeinterval_op_error + type2.get_type_name());
446  }
447  return type1;
448  }
449  if (type2.is_timeinterval()) {
450  if (!type1.is_integer()) {
451  throw std::runtime_error(timeinterval_op_error + type1.get_type_name());
452  }
453  return type2;
454  }
455  CHECK(type1.is_number() && type2.is_number());
456  switch (type1.get_type()) {
457  case kTINYINT:
458  switch (type2.get_type()) {
459  case kSMALLINT:
460  common_type = SQLTypeInfo(kSMALLINT, notnull);
461  break;
462  case kINT:
463  common_type = SQLTypeInfo(kINT, notnull);
464  break;
465  case kBIGINT:
466  common_type = SQLTypeInfo(kBIGINT, notnull);
467  break;
468  case kFLOAT:
469  common_type = SQLTypeInfo(kFLOAT, notnull);
470  break;
471  case kDOUBLE:
472  common_type = SQLTypeInfo(kDOUBLE, notnull);
473  break;
474  case kNUMERIC:
475  case kDECIMAL:
476  common_type =
478  std::max(5 + type2.get_scale(), type2.get_dimension()),
479  type2.get_scale(),
480  notnull);
481  break;
482  default:
483  CHECK(false);
484  }
485  break;
486  case kSMALLINT:
487  switch (type2.get_type()) {
488  case kTINYINT:
489  common_type = SQLTypeInfo(kSMALLINT, notnull);
490  break;
491  case kINT:
492  common_type = SQLTypeInfo(kINT, notnull);
493  break;
494  case kBIGINT:
495  common_type = SQLTypeInfo(kBIGINT, notnull);
496  break;
497  case kFLOAT:
498  common_type = SQLTypeInfo(kFLOAT, notnull);
499  break;
500  case kDOUBLE:
501  common_type = SQLTypeInfo(kDOUBLE, notnull);
502  break;
503  case kNUMERIC:
504  case kDECIMAL:
505  common_type =
507  std::max(5 + type2.get_scale(), type2.get_dimension()),
508  type2.get_scale(),
509  notnull);
510  break;
511  default:
512  CHECK(false);
513  }
514  break;
515  case kINT:
516  switch (type2.get_type()) {
517  case kTINYINT:
518  common_type = SQLTypeInfo(kINT, notnull);
519  break;
520  case kSMALLINT:
521  common_type = SQLTypeInfo(kINT, notnull);
522  break;
523  case kBIGINT:
524  common_type = SQLTypeInfo(kBIGINT, notnull);
525  break;
526  case kFLOAT:
527  common_type = SQLTypeInfo(kFLOAT, notnull);
528  break;
529  case kDOUBLE:
530  common_type = SQLTypeInfo(kDOUBLE, notnull);
531  break;
532  case kNUMERIC:
533  case kDECIMAL:
534  common_type = SQLTypeInfo(
535  kDECIMAL,
536  std::max(std::min(19, 10 + type2.get_scale()), type2.get_dimension()),
537  type2.get_scale(),
538  notnull);
539  break;
540  default:
541  CHECK(false);
542  }
543  break;
544  case kBIGINT:
545  switch (type2.get_type()) {
546  case kTINYINT:
547  common_type = SQLTypeInfo(kBIGINT, notnull);
548  break;
549  case kSMALLINT:
550  common_type = SQLTypeInfo(kBIGINT, notnull);
551  break;
552  case kINT:
553  common_type = SQLTypeInfo(kBIGINT, notnull);
554  break;
555  case kFLOAT:
556  common_type = SQLTypeInfo(kFLOAT, notnull);
557  break;
558  case kDOUBLE:
559  common_type = SQLTypeInfo(kDOUBLE, notnull);
560  break;
561  case kNUMERIC:
562  case kDECIMAL:
563  common_type = SQLTypeInfo(kDECIMAL, 19, type2.get_scale(), notnull);
564  break;
565  default:
566  CHECK(false);
567  }
568  break;
569  case kFLOAT:
570  switch (type2.get_type()) {
571  case kTINYINT:
572  common_type = SQLTypeInfo(kFLOAT, notnull);
573  break;
574  case kSMALLINT:
575  common_type = SQLTypeInfo(kFLOAT, notnull);
576  break;
577  case kINT:
578  common_type = SQLTypeInfo(kFLOAT, notnull);
579  break;
580  case kBIGINT:
581  common_type = SQLTypeInfo(kFLOAT, notnull);
582  break;
583  case kDOUBLE:
584  common_type = SQLTypeInfo(kDOUBLE, notnull);
585  break;
586  case kNUMERIC:
587  case kDECIMAL:
588  common_type = SQLTypeInfo(kFLOAT, notnull);
589  break;
590  default:
591  CHECK(false);
592  }
593  break;
594  case kDOUBLE:
595  switch (type2.get_type()) {
596  case kTINYINT:
597  case kSMALLINT:
598  case kINT:
599  case kBIGINT:
600  case kFLOAT:
601  case kNUMERIC:
602  case kDECIMAL:
603  common_type = SQLTypeInfo(kDOUBLE, notnull);
604  break;
605  default:
606  CHECK(false);
607  }
608  break;
609  case kNUMERIC:
610  case kDECIMAL:
611  switch (type2.get_type()) {
612  case kTINYINT:
613  common_type =
615  std::max(3 + type1.get_scale(), type1.get_dimension()),
616  type1.get_scale(),
617  notnull);
618  break;
619  case kSMALLINT:
620  common_type =
622  std::max(5 + type1.get_scale(), type1.get_dimension()),
623  type1.get_scale(),
624  notnull);
625  break;
626  case kINT:
627  common_type = SQLTypeInfo(
628  kDECIMAL,
629  std::max(std::min(19, 10 + type1.get_scale()), type2.get_dimension()),
630  type1.get_scale(),
631  notnull);
632  break;
633  case kBIGINT:
634  common_type = SQLTypeInfo(kDECIMAL, 19, type1.get_scale(), notnull);
635  break;
636  case kFLOAT:
637  common_type = SQLTypeInfo(kFLOAT, notnull);
638  break;
639  case kDOUBLE:
640  common_type = SQLTypeInfo(kDOUBLE, notnull);
641  break;
642  case kNUMERIC:
643  case kDECIMAL: {
644  int common_scale = std::max(type1.get_scale(), type2.get_scale());
645  common_type = SQLTypeInfo(kDECIMAL,
646  std::max(type1.get_dimension() - type1.get_scale(),
647  type2.get_dimension() - type2.get_scale()) +
648  common_scale,
649  common_scale,
650  notnull);
651  break;
652  }
653  default:
654  CHECK(false);
655  }
656  break;
657  default:
658  CHECK(false);
659  }
660  common_type.set_fixed_size();
661  return common_type;
662 }
663 
664 std::shared_ptr<Analyzer::Expr> Expr::decompress() {
666  return shared_from_this();
667  }
668  SQLTypeInfo new_type_info(type_info.get_type(),
673  0,
675  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
676 }
677 
678 std::shared_ptr<Analyzer::Expr> Expr::add_cast(const SQLTypeInfo& new_type_info) {
679  if (new_type_info == type_info) {
680  return shared_from_this();
681  }
682  if (new_type_info.is_string() && type_info.is_string() &&
683  new_type_info.get_compression() == kENCODING_DICT &&
685  (new_type_info.get_comp_param() == type_info.get_comp_param() ||
686  new_type_info.get_comp_param() == TRANSIENT_DICT(type_info.get_comp_param()))) {
687  return shared_from_this();
688  }
689  if (!type_info.is_castable(new_type_info)) {
690  throw std::runtime_error("Cannot CAST from " + type_info.get_type_name() + " to " +
691  new_type_info.get_type_name());
692  }
693  // @TODO(wei) temporary restriction until executor can support this.
694  if (typeid(*this) != typeid(Constant) && new_type_info.is_string() &&
695  new_type_info.get_compression() == kENCODING_DICT &&
696  new_type_info.get_comp_param() <= TRANSIENT_DICT_ID) {
698  throw std::runtime_error(
699  "Cannot group by string columns which are not dictionary encoded.");
700  }
701  throw std::runtime_error(
702  "Internal error: Cannot apply transient dictionary encoding to non-literal "
703  "expression "
704  "yet.");
705  }
706  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
707 }
708 
709 namespace {
710 
711 struct IntFracRepr {
712  const int64_t integral;
713  const int64_t fractional;
714  const int64_t scale;
715 };
716 
717 IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo& ti) {
718  if (ti.get_scale() > 18) {
719  auto truncated_ti = ti;
720  truncated_ti.set_scale(18);
721  auto truncated_dec = dec;
722  for (int i = 0; i < ti.get_scale() - 18; ++i) {
723  truncated_dec /= 10;
724  }
725  return decimal_to_int_frac(truncated_dec, truncated_ti);
726  }
727  int64_t integral_part = dec;
728  int64_t scale = 1;
729  for (int i = 0; i < ti.get_scale(); i++) {
730  integral_part /= 10;
731  scale *= 10;
732  }
733  return {integral_part, dec - integral_part * scale, scale};
734 }
735 
736 template <class T>
737 T safe_narrow(const int64_t v) {
738  if (v > std::numeric_limits<T>::max() || v < std::numeric_limits<T>::min()) {
739  throw std::runtime_error("Overflow or underflow");
740  }
741  return static_cast<T>(v);
742 }
743 
744 } // namespace
745 
746 void Constant::cast_number(const SQLTypeInfo& new_type_info) {
747  switch (type_info.get_type()) {
748  case kTINYINT:
749  switch (new_type_info.get_type()) {
750  case kTINYINT:
751  break;
752  case kINT:
753  constval.intval = (int32_t)constval.tinyintval;
754  break;
755  case kSMALLINT:
757  break;
758  case kBIGINT:
760  break;
761  case kDOUBLE:
763  break;
764  case kFLOAT:
766  break;
767  case kNUMERIC:
768  case kDECIMAL:
770  for (int i = 0; i < new_type_info.get_scale(); i++) {
771  constval.bigintval *= 10;
772  }
773  break;
774  default:
775  CHECK(false);
776  }
777  break;
778  case kINT:
779  switch (new_type_info.get_type()) {
780  case kTINYINT:
781  constval.tinyintval = safe_narrow<int8_t>(constval.intval);
782  break;
783  case kINT:
784  break;
785  case kSMALLINT:
786  constval.smallintval = safe_narrow<int16_t>(constval.intval);
787  break;
788  case kBIGINT:
789  constval.bigintval = (int64_t)constval.intval;
790  break;
791  case kDOUBLE:
792  constval.doubleval = (double)constval.intval;
793  break;
794  case kFLOAT:
795  constval.floatval = (float)constval.intval;
796  break;
797  case kNUMERIC:
798  case kDECIMAL:
799  constval.bigintval = (int64_t)constval.intval;
800  for (int i = 0; i < new_type_info.get_scale(); i++) {
801  constval.bigintval *= 10;
802  }
803  break;
804  default:
805  CHECK(false);
806  }
807  break;
808  case kSMALLINT:
809  switch (new_type_info.get_type()) {
810  case kTINYINT:
811  constval.tinyintval = safe_narrow<int8_t>(constval.smallintval);
812  break;
813  case kINT:
814  constval.intval = (int32_t)constval.smallintval;
815  break;
816  case kSMALLINT:
817  break;
818  case kBIGINT:
820  break;
821  case kDOUBLE:
823  break;
824  case kFLOAT:
826  break;
827  case kNUMERIC:
828  case kDECIMAL:
830  for (int i = 0; i < new_type_info.get_scale(); i++) {
831  constval.bigintval *= 10;
832  }
833  break;
834  default:
835  CHECK(false);
836  }
837  break;
838  case kBIGINT:
839  switch (new_type_info.get_type()) {
840  case kTINYINT:
841  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
842  break;
843  case kINT:
844  constval.intval = safe_narrow<int32_t>(constval.bigintval);
845  break;
846  case kSMALLINT:
847  constval.smallintval = safe_narrow<int16_t>(constval.bigintval);
848  break;
849  case kBIGINT:
850  break;
851  case kDOUBLE:
853  break;
854  case kFLOAT:
856  break;
857  case kNUMERIC:
858  case kDECIMAL:
859  for (int i = 0; i < new_type_info.get_scale(); i++) {
860  constval.bigintval *= 10;
861  }
862  break;
863  default:
864  CHECK(false);
865  }
866  break;
867  case kDOUBLE:
868  switch (new_type_info.get_type()) {
869  case kTINYINT:
871  break;
872  case kINT:
873  constval.intval = (int32_t)constval.doubleval;
874  break;
875  case kSMALLINT:
877  break;
878  case kBIGINT:
880  break;
881  case kDOUBLE:
882  break;
883  case kFLOAT:
885  break;
886  case kNUMERIC:
887  case kDECIMAL:
888  for (int i = 0; i < new_type_info.get_scale(); i++) {
889  constval.doubleval *= 10;
890  }
892  break;
893  default:
894  CHECK(false);
895  }
896  break;
897  case kFLOAT:
898  switch (new_type_info.get_type()) {
899  case kTINYINT:
901  break;
902  case kINT:
903  constval.intval = (int32_t)constval.floatval;
904  break;
905  case kSMALLINT:
907  break;
908  case kBIGINT:
909  constval.bigintval = (int64_t)constval.floatval;
910  break;
911  case kDOUBLE:
913  break;
914  case kFLOAT:
915  break;
916  case kNUMERIC:
917  case kDECIMAL:
918  for (int i = 0; i < new_type_info.get_scale(); i++) {
919  constval.floatval *= 10;
920  }
921  constval.bigintval = (int64_t)constval.floatval;
922  break;
923  default:
924  CHECK(false);
925  }
926  break;
927  case kNUMERIC:
928  case kDECIMAL:
929  switch (new_type_info.get_type()) {
930  case kTINYINT:
931  for (int i = 0; i < type_info.get_scale(); i++) {
932  constval.bigintval /= 10;
933  }
934  constval.tinyintval = safe_narrow<int8_t>(constval.bigintval);
935  break;
936  case kINT:
937  for (int i = 0; i < type_info.get_scale(); i++) {
938  constval.bigintval /= 10;
939  }
940  constval.intval = safe_narrow<int32_t>(constval.bigintval);
941  break;
942  case kSMALLINT:
943  for (int i = 0; i < type_info.get_scale(); i++) {
944  constval.bigintval /= 10;
945  }
947  break;
948  case kBIGINT:
949  for (int i = 0; i < type_info.get_scale(); i++) {
950  constval.bigintval /= 10;
951  }
952  break;
953  case kDOUBLE: {
954  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
955  constval.doubleval = int_frac.integral +
956  static_cast<double>(int_frac.fractional) / int_frac.scale;
957  break;
958  }
959  case kFLOAT: {
960  const auto int_frac = decimal_to_int_frac(constval.bigintval, type_info);
961  constval.floatval = int_frac.integral +
962  static_cast<double>(int_frac.fractional) / int_frac.scale;
963  break;
964  }
965  case kNUMERIC:
966  case kDECIMAL:
968  constval.bigintval, type_info, new_type_info);
969  break;
970  default:
971  CHECK(false);
972  }
973  break;
974  case kTIMESTAMP:
975  switch (new_type_info.get_type()) {
976  case kTINYINT:
977  constval.tinyintval = static_cast<int8_t>(constval.bigintval);
978  break;
979  case kINT:
980  constval.intval = static_cast<int32_t>(constval.bigintval);
981  break;
982  case kSMALLINT:
983  constval.smallintval = static_cast<int16_t>(constval.bigintval);
984  break;
985  case kBIGINT:
986  constval.bigintval = static_cast<int64_t>(constval.bigintval);
987  break;
988  case kDOUBLE:
989  constval.doubleval = static_cast<double>(constval.bigintval);
990  break;
991  case kFLOAT:
992  constval.floatval = static_cast<float>(constval.bigintval);
993  break;
994  case kNUMERIC:
995  case kDECIMAL:
996  for (int i = 0; i < new_type_info.get_scale(); i++) {
997  constval.bigintval *= 10;
998  }
999  break;
1000  default:
1001  CHECK(false);
1002  }
1003  break;
1004  case kBOOLEAN:
1005  switch (new_type_info.get_type()) {
1006  case kTINYINT:
1007  constval.tinyintval = constval.boolval ? 1 : 0;
1008  break;
1009  case kINT:
1010  constval.intval = constval.boolval ? 1 : 0;
1011  break;
1012  case kSMALLINT:
1014  break;
1015  case kBIGINT:
1016  constval.bigintval = constval.boolval ? 1 : 0;
1017  break;
1018  case kDOUBLE:
1019  constval.doubleval = constval.boolval ? 1 : 0;
1020  break;
1021  case kFLOAT:
1022  constval.floatval = constval.boolval ? 1 : 0;
1023  break;
1024  case kNUMERIC:
1025  case kDECIMAL:
1026  constval.bigintval = constval.boolval ? 1 : 0;
1027  for (int i = 0; i < new_type_info.get_scale(); i++) {
1028  constval.bigintval *= 10;
1029  }
1030  break;
1031  default:
1032  CHECK(false);
1033  }
1034  break;
1035  default:
1036  CHECK(false);
1037  }
1038  type_info = new_type_info;
1039 }
1040 
1041 void Constant::cast_string(const SQLTypeInfo& new_type_info) {
1042  std::string* s = constval.stringval;
1043  if (s != nullptr && new_type_info.get_type() != kTEXT &&
1044  static_cast<size_t>(new_type_info.get_dimension()) < s->length()) {
1045  // truncate string
1046  constval.stringval = new std::string(s->substr(0, new_type_info.get_dimension()));
1047  delete s;
1048  }
1049  type_info = new_type_info;
1050 }
1051 
1052 void Constant::cast_from_string(const SQLTypeInfo& new_type_info) {
1053  std::string* s = constval.stringval;
1054  SQLTypeInfo ti = new_type_info;
1055  constval = StringToDatum(*s, ti);
1056  delete s;
1057  type_info = new_type_info;
1058 }
1059 
1060 void Constant::cast_to_string(const SQLTypeInfo& str_type_info) {
1061  const auto str_val = DatumToString(constval, type_info);
1062  constval.stringval = new std::string(str_val);
1063  if (str_type_info.get_type() != kTEXT &&
1064  constval.stringval->length() > static_cast<size_t>(str_type_info.get_dimension())) {
1065  // truncate the string
1066  *constval.stringval = constval.stringval->substr(0, str_type_info.get_dimension());
1067  }
1068  type_info = str_type_info;
1069 }
1070 
1071 void Constant::do_cast(const SQLTypeInfo& new_type_info) {
1072  if (type_info == new_type_info) {
1073  return;
1074  }
1075  if (is_null) {
1076  type_info = new_type_info;
1077  set_null_value();
1078  return;
1079  }
1080  if (new_type_info.is_number() &&
1082  type_info.get_type() == kBOOLEAN)) {
1083  cast_number(new_type_info);
1084  } else if (new_type_info.is_geometry() && type_info.is_string()) {
1085  type_info = new_type_info;
1086  } else if (new_type_info.is_geometry() &&
1087  type_info.get_type() == new_type_info.get_type()) {
1088  type_info = new_type_info;
1089  } else if (new_type_info.is_boolean() && type_info.is_boolean()) {
1090  type_info = new_type_info;
1091  } else if (new_type_info.is_string() && type_info.is_string()) {
1092  cast_string(new_type_info);
1093  } else if (type_info.is_string() || type_info.get_type() == kVARCHAR) {
1094  cast_from_string(new_type_info);
1095  } else if (new_type_info.is_string()) {
1096  cast_to_string(new_type_info);
1097  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kDATE) {
1098  type_info = new_type_info;
1099  } else if (new_type_info.get_type() == kDATE && type_info.get_type() == kTIMESTAMP) {
1106  type_info = new_type_info;
1107  } else if ((type_info.get_type() == kTIMESTAMP || type_info.get_type() == kDATE) &&
1108  new_type_info.get_type() == kTIMESTAMP) {
1109  const auto dimen = (type_info.get_type() == kDATE) ? 0 : type_info.get_dimension();
1110  if (dimen != new_type_info.get_dimension()) {
1111  constval.bigintval = dimen < new_type_info.get_dimension()
1115  new_type_info.get_dimension() - dimen)
1119  dimen - new_type_info.get_dimension());
1120  }
1121  type_info = new_type_info;
1122  } else if (new_type_info.is_array() && type_info.is_array()) {
1123  auto new_sub_ti = new_type_info.get_elem_type();
1124  for (auto& v : value_list) {
1125  auto c = std::dynamic_pointer_cast<Analyzer::Constant>(v);
1126  if (!c) {
1127  throw std::runtime_error("Invalid array cast.");
1128  }
1129  c->do_cast(new_sub_ti);
1130  }
1131  type_info = new_type_info;
1132  } else if (get_is_null() && (new_type_info.is_number() || new_type_info.is_time() ||
1133  new_type_info.is_string() || new_type_info.is_boolean())) {
1134  type_info = new_type_info;
1135  set_null_value();
1136  } else {
1137  throw std::runtime_error("Cast from " + type_info.get_type_name() + " to " +
1138  new_type_info.get_type_name() + " not supported");
1139  }
1140 }
1141 
1143  switch (type_info.get_type()) {
1144  case kBOOLEAN:
1146  break;
1147  case kTINYINT:
1149  break;
1150  case kINT:
1152  break;
1153  case kSMALLINT:
1155  break;
1156  case kBIGINT:
1157  case kNUMERIC:
1158  case kDECIMAL:
1160  break;
1161  case kTIME:
1162  case kTIMESTAMP:
1163  case kDATE:
1165  break;
1166  case kVARCHAR:
1167  case kCHAR:
1168  case kTEXT:
1169  constval.stringval = nullptr;
1170  break;
1171  case kPOINT:
1172  case kLINESTRING:
1173  case kPOLYGON:
1174  case kMULTIPOLYGON:
1175  constval.stringval = nullptr;
1176  break;
1177  case kFLOAT:
1179  break;
1180  case kDOUBLE:
1182  break;
1183  case kNULLT:
1184  constval.bigintval = 0;
1185  break;
1186  case kARRAY:
1187  constval.arrayval = nullptr;
1188  break;
1189  default:
1190  CHECK(false);
1191  }
1192 }
1193 
1194 std::shared_ptr<Analyzer::Expr> Constant::add_cast(const SQLTypeInfo& new_type_info) {
1195  if (is_null) {
1196  type_info = new_type_info;
1197  set_null_value();
1198  return shared_from_this();
1199  }
1200  if (new_type_info.get_compression() != type_info.get_compression()) {
1201  if (new_type_info.get_compression() != kENCODING_NONE) {
1202  SQLTypeInfo new_ti = new_type_info;
1203  if (new_ti.get_compression() != kENCODING_DATE_IN_DAYS) {
1205  }
1206  do_cast(new_ti);
1207  }
1208  return Expr::add_cast(new_type_info);
1209  }
1210  const auto is_integral_type =
1211  new_type_info.is_integer() || new_type_info.is_decimal() || new_type_info.is_fp();
1212  if (is_integral_type && (type_info.is_time() || type_info.is_date())) {
1213  // Let the codegen phase deal with casts from date/time to a number.
1214  return makeExpr<UOper>(new_type_info, contains_agg, kCAST, shared_from_this());
1215  }
1216  do_cast(new_type_info);
1217  return shared_from_this();
1218 }
1219 
1220 std::shared_ptr<Analyzer::Expr> UOper::add_cast(const SQLTypeInfo& new_type_info) {
1221  if (optype != kCAST) {
1222  return Expr::add_cast(new_type_info);
1223  }
1224  if (type_info.is_string() && new_type_info.is_string() &&
1225  new_type_info.get_compression() == kENCODING_DICT &&
1227  const SQLTypeInfo oti = operand->get_type_info();
1228  if (oti.is_string() && oti.get_compression() == kENCODING_DICT &&
1229  (oti.get_comp_param() == new_type_info.get_comp_param() ||
1230  oti.get_comp_param() == TRANSIENT_DICT(new_type_info.get_comp_param()))) {
1231  auto result = operand;
1232  operand = nullptr;
1233  return result;
1234  }
1235  }
1236  return Expr::add_cast(new_type_info);
1237 }
1238 
1239 std::shared_ptr<Analyzer::Expr> CaseExpr::add_cast(const SQLTypeInfo& new_type_info) {
1240  SQLTypeInfo ti = new_type_info;
1241  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1242  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1246  }
1247 
1248  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1249  new_expr_pair_list;
1250  for (auto& p : expr_pair_list) {
1251  new_expr_pair_list.emplace_back(
1252  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1253  }
1254 
1255  if (else_expr != nullptr) {
1256  else_expr = else_expr->add_cast(ti);
1257  }
1258  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1259  expr_pair_list = new_expr_pair_list;
1260 
1261  type_info = ti;
1262  return shared_from_this();
1263 }
1264 
1265 std::shared_ptr<Analyzer::Expr> Subquery::add_cast(const SQLTypeInfo& new_type_info) {
1266  // not supported yet.
1267  CHECK(false);
1268  return nullptr;
1269 }
1270 
1271 int Query::get_rte_idx(const std::string& name) const {
1272  int rte_idx = 0;
1273  for (auto rte : rangetable) {
1274  if (rte->get_rangevar() == name) {
1275  return rte_idx;
1276  }
1277  rte_idx++;
1278  }
1279  return -1;
1280 }
1281 
1283  rangetable.push_back(rte);
1284 }
1285 
1287  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
1288  if (!groupby.empty()) {
1289  for (auto e : groupby) {
1290  auto c = std::dynamic_pointer_cast<ColumnVar>(e);
1291  if (c && table_id == c->get_table_id() && column_id == c->get_column_id()) {
1292  return;
1293  }
1294  }
1295  }
1296  throw std::runtime_error(
1297  "expressions in the SELECT or HAVING clause must be an aggregate function or an "
1298  "expression "
1299  "over GROUP BY columns.");
1300 }
1301 
1303  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
1304  if (which_row != kGROUPBY) {
1305  throw std::runtime_error("Internal error: invalid VAR in GROUP BY or HAVING.");
1306  }
1307 }
1308 
1310  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
1311  operand->check_group_by(groupby);
1312 }
1313 
1315  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
1316  left_operand->check_group_by(groupby);
1317  right_operand->check_group_by(groupby);
1318 }
1319 
1320 namespace {
1321 
1322 template <class T>
1323 bool expr_is(const std::shared_ptr<Analyzer::Expr>& expr) {
1324  return std::dynamic_pointer_cast<T>(expr) != nullptr;
1325 }
1326 
1327 } // namespace
1328 
1330  const std::shared_ptr<Analyzer::Expr> cast_operand,
1331  const std::shared_ptr<Analyzer::Expr> const_operand) {
1332  if (expr_is<UOper>(cast_operand) && expr_is<Constant>(const_operand)) {
1333  auto u_expr = std::dynamic_pointer_cast<UOper>(cast_operand);
1334  if (u_expr->get_optype() != kCAST) {
1335  return false;
1336  }
1337  if (!(expr_is<Analyzer::ColumnVar>(u_expr->get_own_operand()) &&
1338  !expr_is<Analyzer::Var>(u_expr->get_own_operand()))) {
1339  return false;
1340  }
1341  const auto& ti = u_expr->get_type_info();
1342  if (ti.is_time() && u_expr->get_operand()->get_type_info().is_time()) {
1343  // Allow casts between time types to pass through
1344  return true;
1345  } else if (ti.is_integer() && u_expr->get_operand()->get_type_info().is_integer()) {
1346  // Allow casts between integer types to pass through
1347  return true;
1348  }
1349  }
1350  return false;
1351 }
1352 
1353 std::shared_ptr<Analyzer::Expr> BinOper::normalize_simple_predicate(int& rte_idx) const {
1354  rte_idx = -1;
1355  if (!IS_COMPARISON(optype) || qualifier != kONE) {
1356  return nullptr;
1357  }
1358  if (expr_is<UOper>(left_operand)) {
1360  auto uo = std::dynamic_pointer_cast<UOper>(left_operand);
1361  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1362  rte_idx = cv->get_rte_idx();
1363  return this->deep_copy();
1364  }
1365  } else if (expr_is<UOper>(right_operand)) {
1367  auto uo = std::dynamic_pointer_cast<UOper>(right_operand);
1368  auto cv = std::dynamic_pointer_cast<ColumnVar>(uo->get_own_operand());
1369  rte_idx = cv->get_rte_idx();
1370  return makeExpr<BinOper>(type_info,
1371  contains_agg,
1373  qualifier,
1374  right_operand->deep_copy(),
1375  left_operand->deep_copy());
1376  }
1377  } else if (expr_is<ColumnVar>(left_operand) && !expr_is<Var>(left_operand) &&
1378  expr_is<Constant>(right_operand)) {
1379  auto cv = std::dynamic_pointer_cast<ColumnVar>(left_operand);
1380  rte_idx = cv->get_rte_idx();
1381  return this->deep_copy();
1382  } else if (expr_is<Constant>(left_operand) && expr_is<ColumnVar>(right_operand) &&
1383  !expr_is<Var>(right_operand)) {
1384  auto cv = std::dynamic_pointer_cast<ColumnVar>(right_operand);
1385  rte_idx = cv->get_rte_idx();
1386  return makeExpr<BinOper>(type_info,
1387  contains_agg,
1389  qualifier,
1390  right_operand->deep_copy(),
1391  left_operand->deep_copy());
1392  }
1393  return nullptr;
1394 }
1395 
1396 void ColumnVar::group_predicates(std::list<const Expr*>& scan_predicates,
1397  std::list<const Expr*>& join_predicates,
1398  std::list<const Expr*>& const_predicates) const {
1399  if (type_info.get_type() == kBOOLEAN) {
1400  scan_predicates.push_back(this);
1401  }
1402 }
1403 
1404 void UOper::group_predicates(std::list<const Expr*>& scan_predicates,
1405  std::list<const Expr*>& join_predicates,
1406  std::list<const Expr*>& const_predicates) const {
1407  std::set<int> rte_idx_set;
1408  operand->collect_rte_idx(rte_idx_set);
1409  if (rte_idx_set.size() > 1) {
1410  join_predicates.push_back(this);
1411  } else if (rte_idx_set.size() == 1) {
1412  scan_predicates.push_back(this);
1413  } else {
1414  const_predicates.push_back(this);
1415  }
1416 }
1417 
1418 void BinOper::group_predicates(std::list<const Expr*>& scan_predicates,
1419  std::list<const Expr*>& join_predicates,
1420  std::list<const Expr*>& const_predicates) const {
1421  if (optype == kAND) {
1422  left_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1423  right_operand->group_predicates(scan_predicates, join_predicates, const_predicates);
1424  return;
1425  }
1426  std::set<int> rte_idx_set;
1427  left_operand->collect_rte_idx(rte_idx_set);
1428  right_operand->collect_rte_idx(rte_idx_set);
1429  if (rte_idx_set.size() > 1) {
1430  join_predicates.push_back(this);
1431  } else if (rte_idx_set.size() == 1) {
1432  scan_predicates.push_back(this);
1433  } else {
1434  const_predicates.push_back(this);
1435  }
1436 }
1437 
1438 namespace {
1439 
1441  const auto const_expr = dynamic_cast<const Analyzer::Constant*>(expr);
1442  if (const_expr) {
1443  return const_expr->get_is_null();
1444  }
1445  const auto& expr_ti = expr->get_type_info();
1446  return !expr_ti.get_notnull();
1447 }
1448 
1449 bool is_in_values_nullable(const std::shared_ptr<Analyzer::Expr>& a,
1450  const std::list<std::shared_ptr<Analyzer::Expr>>& l) {
1451  if (is_expr_nullable(a.get())) {
1452  return true;
1453  }
1454  for (const auto& v : l) {
1455  if (is_expr_nullable(v.get())) {
1456  return true;
1457  }
1458  }
1459  return false;
1460 }
1461 
1462 } // namespace
1463 
1464 InValues::InValues(std::shared_ptr<Analyzer::Expr> a,
1465  const std::list<std::shared_ptr<Analyzer::Expr>>& l)
1466  : Expr(kBOOLEAN, !is_in_values_nullable(a, l)), arg(a), value_list(l) {}
1467 
1468 void InValues::group_predicates(std::list<const Expr*>& scan_predicates,
1469  std::list<const Expr*>& join_predicates,
1470  std::list<const Expr*>& const_predicates) const {
1471  std::set<int> rte_idx_set;
1472  arg->collect_rte_idx(rte_idx_set);
1473  if (rte_idx_set.size() > 1) {
1474  join_predicates.push_back(this);
1475  } else if (rte_idx_set.size() == 1) {
1476  scan_predicates.push_back(this);
1477  } else {
1478  const_predicates.push_back(this);
1479  }
1480 }
1481 
1482 InIntegerSet::InIntegerSet(const std::shared_ptr<const Analyzer::Expr> a,
1483  const std::vector<int64_t>& l,
1484  const bool not_null)
1485  : Expr(kBOOLEAN, not_null), arg(a), value_list(l) {}
1486 
1487 void CharLengthExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1488  std::list<const Expr*>& join_predicates,
1489  std::list<const Expr*>& const_predicates) const {
1490  std::set<int> rte_idx_set;
1491  arg->collect_rte_idx(rte_idx_set);
1492  if (rte_idx_set.size() > 1) {
1493  join_predicates.push_back(this);
1494  } else if (rte_idx_set.size() == 1) {
1495  scan_predicates.push_back(this);
1496  } else {
1497  const_predicates.push_back(this);
1498  }
1499 }
1500 
1501 void KeyForStringExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1502  std::list<const Expr*>& join_predicates,
1503  std::list<const Expr*>& const_predicates) const {
1504  std::set<int> rte_idx_set;
1505  arg->collect_rte_idx(rte_idx_set);
1506  if (rte_idx_set.size() > 1) {
1507  join_predicates.push_back(this);
1508  } else if (rte_idx_set.size() == 1) {
1509  scan_predicates.push_back(this);
1510  } else {
1511  const_predicates.push_back(this);
1512  }
1513 }
1514 
1515 void LowerExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1516  std::list<const Expr*>& join_predicates,
1517  std::list<const Expr*>& const_predicates) const {
1518  std::set<int> rte_idx_set;
1519  arg->collect_rte_idx(rte_idx_set);
1520  if (rte_idx_set.size() > 1) {
1521  join_predicates.push_back(this);
1522  } else if (rte_idx_set.size() == 1) {
1523  scan_predicates.push_back(this);
1524  } else {
1525  const_predicates.push_back(this);
1526  }
1527 }
1528 
1529 void CardinalityExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1530  std::list<const Expr*>& join_predicates,
1531  std::list<const Expr*>& const_predicates) const {
1532  std::set<int> rte_idx_set;
1533  arg->collect_rte_idx(rte_idx_set);
1534  if (rte_idx_set.size() > 1) {
1535  join_predicates.push_back(this);
1536  } else if (rte_idx_set.size() == 1) {
1537  scan_predicates.push_back(this);
1538  } else {
1539  const_predicates.push_back(this);
1540  }
1541 }
1542 
1543 void LikeExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1544  std::list<const Expr*>& join_predicates,
1545  std::list<const Expr*>& const_predicates) const {
1546  std::set<int> rte_idx_set;
1547  arg->collect_rte_idx(rte_idx_set);
1548  if (rte_idx_set.size() > 1) {
1549  join_predicates.push_back(this);
1550  } else if (rte_idx_set.size() == 1) {
1551  scan_predicates.push_back(this);
1552  } else {
1553  const_predicates.push_back(this);
1554  }
1555 }
1556 
1557 void RegexpExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1558  std::list<const Expr*>& join_predicates,
1559  std::list<const Expr*>& const_predicates) const {
1560  std::set<int> rte_idx_set;
1561  arg->collect_rte_idx(rte_idx_set);
1562  if (rte_idx_set.size() > 1) {
1563  join_predicates.push_back(this);
1564  } else if (rte_idx_set.size() == 1) {
1565  scan_predicates.push_back(this);
1566  } else {
1567  const_predicates.push_back(this);
1568  }
1569 }
1570 
1571 void LikelihoodExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1572  std::list<const Expr*>& join_predicates,
1573  std::list<const Expr*>& const_predicates) const {
1574  std::set<int> rte_idx_set;
1575  arg->collect_rte_idx(rte_idx_set);
1576  if (rte_idx_set.size() > 1) {
1577  join_predicates.push_back(this);
1578  } else if (rte_idx_set.size() == 1) {
1579  scan_predicates.push_back(this);
1580  } else {
1581  const_predicates.push_back(this);
1582  }
1583 }
1584 
1585 void AggExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1586  std::list<const Expr*>& join_predicates,
1587  std::list<const Expr*>& const_predicates) const {
1588  std::set<int> rte_idx_set;
1589  arg->collect_rte_idx(rte_idx_set);
1590  if (rte_idx_set.size() > 1) {
1591  join_predicates.push_back(this);
1592  } else if (rte_idx_set.size() == 1) {
1593  scan_predicates.push_back(this);
1594  } else {
1595  const_predicates.push_back(this);
1596  }
1597 }
1598 
1599 void CaseExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1600  std::list<const Expr*>& join_predicates,
1601  std::list<const Expr*>& const_predicates) const {
1602  std::set<int> rte_idx_set;
1603  for (auto p : expr_pair_list) {
1604  p.first->collect_rte_idx(rte_idx_set);
1605  p.second->collect_rte_idx(rte_idx_set);
1606  }
1607  if (else_expr != nullptr) {
1608  else_expr->collect_rte_idx(rte_idx_set);
1609  }
1610  if (rte_idx_set.size() > 1) {
1611  join_predicates.push_back(this);
1612  } else if (rte_idx_set.size() == 1) {
1613  scan_predicates.push_back(this);
1614  } else {
1615  const_predicates.push_back(this);
1616  }
1617 }
1618 
1619 void ExtractExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1620  std::list<const Expr*>& join_predicates,
1621  std::list<const Expr*>& const_predicates) const {
1622  std::set<int> rte_idx_set;
1623  from_expr_->collect_rte_idx(rte_idx_set);
1624  if (rte_idx_set.size() > 1) {
1625  join_predicates.push_back(this);
1626  } else if (rte_idx_set.size() == 1) {
1627  scan_predicates.push_back(this);
1628  } else {
1629  const_predicates.push_back(this);
1630  }
1631 }
1632 
1633 void DateaddExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1634  std::list<const Expr*>& join_predicates,
1635  std::list<const Expr*>& const_predicates) const {
1636  std::set<int> rte_idx_set;
1637  number_->collect_rte_idx(rte_idx_set);
1638  datetime_->collect_rte_idx(rte_idx_set);
1639  if (rte_idx_set.size() > 1) {
1640  join_predicates.push_back(this);
1641  } else if (rte_idx_set.size() == 1) {
1642  scan_predicates.push_back(this);
1643  } else {
1644  const_predicates.push_back(this);
1645  }
1646 }
1647 
1648 void DatediffExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1649  std::list<const Expr*>& join_predicates,
1650  std::list<const Expr*>& const_predicates) const {
1651  std::set<int> rte_idx_set;
1652  start_->collect_rte_idx(rte_idx_set);
1653  end_->collect_rte_idx(rte_idx_set);
1654  if (rte_idx_set.size() > 1) {
1655  join_predicates.push_back(this);
1656  } else if (rte_idx_set.size() == 1) {
1657  scan_predicates.push_back(this);
1658  } else {
1659  const_predicates.push_back(this);
1660  }
1661 }
1662 
1663 void DatetruncExpr::group_predicates(std::list<const Expr*>& scan_predicates,
1664  std::list<const Expr*>& join_predicates,
1665  std::list<const Expr*>& const_predicates) const {
1666  std::set<int> rte_idx_set;
1667  from_expr_->collect_rte_idx(rte_idx_set);
1668  if (rte_idx_set.size() > 1) {
1669  join_predicates.push_back(this);
1670  } else if (rte_idx_set.size() == 1) {
1671  scan_predicates.push_back(this);
1672  } else {
1673  const_predicates.push_back(this);
1674  }
1675 }
1676 
1677 std::shared_ptr<Analyzer::Expr> ColumnVar::rewrite_with_targetlist(
1678  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1679  for (auto tle : tlist) {
1680  const Expr* e = tle->get_expr();
1681  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1682  if (colvar != nullptr) {
1683  if (table_id == colvar->get_table_id() && column_id == colvar->get_column_id()) {
1684  return colvar->deep_copy();
1685  }
1686  }
1687  }
1688  throw std::runtime_error("Internal error: cannot find ColumnVar in targetlist.");
1689 }
1690 
1691 std::shared_ptr<Analyzer::Expr> ColumnVar::rewrite_with_child_targetlist(
1692  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1693  int varno = 1;
1694  for (auto tle : tlist) {
1695  const Expr* e = tle->get_expr();
1696  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1697  if (colvar == nullptr) {
1698  throw std::runtime_error(
1699  "Internal Error: targetlist in rewrite_with_child_targetlist is not all "
1700  "columns.");
1701  }
1702  if (table_id == colvar->get_table_id() && column_id == colvar->get_column_id()) {
1703  return makeExpr<Var>(colvar->get_type_info(),
1704  colvar->get_table_id(),
1705  colvar->get_column_id(),
1706  colvar->get_rte_idx(),
1708  varno);
1709  }
1710  varno++;
1711  }
1712  throw std::runtime_error("Internal error: cannot find ColumnVar in child targetlist.");
1713 }
1714 
1715 std::shared_ptr<Analyzer::Expr> ColumnVar::rewrite_agg_to_var(
1716  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1717  int varno = 1;
1718  for (auto tle : tlist) {
1719  const Expr* e = tle->get_expr();
1720  if (typeid(*e) != typeid(AggExpr)) {
1721  const ColumnVar* colvar = dynamic_cast<const ColumnVar*>(e);
1722  if (colvar == nullptr) {
1723  throw std::runtime_error(
1724  "Internal Error: targetlist in rewrite_agg_to_var is not all columns and "
1725  "aggregates.");
1726  }
1727  if (table_id == colvar->get_table_id() && column_id == colvar->get_column_id()) {
1728  return makeExpr<Var>(colvar->get_type_info(),
1729  colvar->get_table_id(),
1730  colvar->get_column_id(),
1731  colvar->get_rte_idx(),
1733  varno);
1734  }
1735  }
1736  varno++;
1737  }
1738  throw std::runtime_error(
1739  "Internal error: cannot find ColumnVar from having clause in targetlist.");
1740 }
1741 
1742 std::shared_ptr<Analyzer::Expr> Var::rewrite_agg_to_var(
1743  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1744  int varno = 1;
1745  for (auto tle : tlist) {
1746  const Expr* e = tle->get_expr();
1747  if (*e == *this) {
1748  return makeExpr<Var>(e->get_type_info(), Var::kINPUT_OUTER, varno);
1749  }
1750  varno++;
1751  }
1752  throw std::runtime_error(
1753  "Internal error: cannot find Var from having clause in targetlist.");
1754 }
1755 
1756 std::shared_ptr<Analyzer::Expr> InValues::rewrite_with_targetlist(
1757  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1758  std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
1759  for (auto v : value_list) {
1760  new_value_list.push_back(v->deep_copy());
1761  }
1762  return makeExpr<InValues>(arg->rewrite_with_targetlist(tlist), new_value_list);
1763 }
1764 
1765 std::shared_ptr<Analyzer::Expr> InValues::rewrite_with_child_targetlist(
1766  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1767  std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
1768  for (auto v : value_list) {
1769  new_value_list.push_back(v->deep_copy());
1770  }
1771  return makeExpr<InValues>(arg->rewrite_with_child_targetlist(tlist), new_value_list);
1772 }
1773 
1774 std::shared_ptr<Analyzer::Expr> InValues::rewrite_agg_to_var(
1775  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1776  std::list<std::shared_ptr<Analyzer::Expr>> new_value_list;
1777  for (auto v : value_list) {
1778  new_value_list.push_back(v->rewrite_agg_to_var(tlist));
1779  }
1780  return makeExpr<InValues>(arg->rewrite_agg_to_var(tlist), new_value_list);
1781 }
1782 
1783 std::shared_ptr<Analyzer::Expr> AggExpr::rewrite_with_targetlist(
1784  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1785  for (auto tle : tlist) {
1786  const Expr* e = tle->get_expr();
1787  if (typeid(*e) == typeid(AggExpr)) {
1788  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1789  if (*this == *agg) {
1790  return agg->deep_copy();
1791  }
1792  }
1793  }
1794  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1795 }
1796 
1797 std::shared_ptr<Analyzer::Expr> AggExpr::rewrite_with_child_targetlist(
1798  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1799  return makeExpr<AggExpr>(type_info,
1800  aggtype,
1801  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1802  is_distinct,
1803  error_rate);
1804 }
1805 
1806 std::shared_ptr<Analyzer::Expr> AggExpr::rewrite_agg_to_var(
1807  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1808  int varno = 1;
1809  for (auto tle : tlist) {
1810  const Expr* e = tle->get_expr();
1811  if (typeid(*e) == typeid(AggExpr)) {
1812  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1813  if (*this == *agg_expr) {
1814  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1815  }
1816  }
1817  varno++;
1818  }
1819  throw std::runtime_error(
1820  "Internal error: cannot find AggExpr from having clause in targetlist.");
1821 }
1822 
1823 std::shared_ptr<Analyzer::Expr> CaseExpr::rewrite_with_targetlist(
1824  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1825  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1826  epair_list;
1827  for (auto p : expr_pair_list) {
1828  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1829  p.second->rewrite_with_targetlist(tlist));
1830  }
1831  return makeExpr<CaseExpr>(
1832  type_info,
1833  contains_agg,
1834  epair_list,
1835  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1836 }
1837 
1838 std::shared_ptr<Analyzer::Expr> ExtractExpr::rewrite_with_targetlist(
1839  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1840  return makeExpr<ExtractExpr>(
1841  type_info, contains_agg, field_, from_expr_->rewrite_with_targetlist(tlist));
1842 }
1843 
1844 std::shared_ptr<Analyzer::Expr> DateaddExpr::rewrite_with_targetlist(
1845  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1846  return makeExpr<DateaddExpr>(type_info,
1847  field_,
1848  number_->rewrite_with_targetlist(tlist),
1849  datetime_->rewrite_with_targetlist(tlist));
1850 }
1851 
1852 std::shared_ptr<Analyzer::Expr> DatediffExpr::rewrite_with_targetlist(
1853  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1854  return makeExpr<DatediffExpr>(type_info,
1855  field_,
1856  start_->rewrite_with_targetlist(tlist),
1857  end_->rewrite_with_targetlist(tlist));
1858 }
1859 
1860 std::shared_ptr<Analyzer::Expr> DatetruncExpr::rewrite_with_targetlist(
1861  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1862  return makeExpr<DatetruncExpr>(
1863  type_info, contains_agg, field_, from_expr_->rewrite_with_targetlist(tlist));
1864 }
1865 
1866 std::shared_ptr<Analyzer::Expr> CaseExpr::rewrite_with_child_targetlist(
1867  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1868  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1869  epair_list;
1870  for (auto p : expr_pair_list) {
1871  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
1872  p.second->rewrite_with_child_targetlist(tlist));
1873  }
1874  return makeExpr<CaseExpr>(
1875  type_info,
1876  contains_agg,
1877  epair_list,
1878  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
1879 }
1880 
1881 std::shared_ptr<Analyzer::Expr> ExtractExpr::rewrite_with_child_targetlist(
1882  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1883  return makeExpr<ExtractExpr>(
1884  type_info, contains_agg, field_, from_expr_->rewrite_with_child_targetlist(tlist));
1885 }
1886 
1887 std::shared_ptr<Analyzer::Expr> DateaddExpr::rewrite_with_child_targetlist(
1888  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1889  return makeExpr<DateaddExpr>(type_info,
1890  field_,
1891  number_->rewrite_with_child_targetlist(tlist),
1892  datetime_->rewrite_with_child_targetlist(tlist));
1893 }
1894 
1895 std::shared_ptr<Analyzer::Expr> DatediffExpr::rewrite_with_child_targetlist(
1896  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1897  return makeExpr<DatediffExpr>(type_info,
1898  field_,
1899  start_->rewrite_with_child_targetlist(tlist),
1900  end_->rewrite_with_child_targetlist(tlist));
1901 }
1902 
1903 std::shared_ptr<Analyzer::Expr> DatetruncExpr::rewrite_with_child_targetlist(
1904  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1905  return makeExpr<DatetruncExpr>(
1906  type_info, contains_agg, field_, from_expr_->rewrite_with_child_targetlist(tlist));
1907 }
1908 
1909 std::shared_ptr<Analyzer::Expr> CaseExpr::rewrite_agg_to_var(
1910  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1911  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1912  epair_list;
1913  for (auto p : expr_pair_list) {
1914  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
1915  p.second->rewrite_agg_to_var(tlist));
1916  }
1917  return makeExpr<CaseExpr>(type_info,
1918  contains_agg,
1919  epair_list,
1920  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
1921 }
1922 
1923 std::shared_ptr<Analyzer::Expr> ExtractExpr::rewrite_agg_to_var(
1924  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1925  return makeExpr<ExtractExpr>(
1926  type_info, contains_agg, field_, from_expr_->rewrite_agg_to_var(tlist));
1927 }
1928 
1929 std::shared_ptr<Analyzer::Expr> DateaddExpr::rewrite_agg_to_var(
1930  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1931  return makeExpr<DateaddExpr>(type_info,
1932  field_,
1933  number_->rewrite_agg_to_var(tlist),
1934  datetime_->rewrite_agg_to_var(tlist));
1935 }
1936 
1937 std::shared_ptr<Analyzer::Expr> DatediffExpr::rewrite_agg_to_var(
1938  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1939  return makeExpr<DatediffExpr>(type_info,
1940  field_,
1941  start_->rewrite_agg_to_var(tlist),
1942  end_->rewrite_agg_to_var(tlist));
1943 }
1944 
1945 std::shared_ptr<Analyzer::Expr> DatetruncExpr::rewrite_agg_to_var(
1946  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
1947  return makeExpr<DatetruncExpr>(
1948  type_info, contains_agg, field_, from_expr_->rewrite_agg_to_var(tlist));
1949 }
1950 
1951 bool ColumnVar::operator==(const Expr& rhs) const {
1952  if (typeid(rhs) != typeid(ColumnVar) && typeid(rhs) != typeid(Var)) {
1953  return false;
1954  }
1955  const ColumnVar& rhs_cv = dynamic_cast<const ColumnVar&>(rhs);
1956  if (rte_idx != -1) {
1957  return (table_id == rhs_cv.get_table_id()) && (column_id == rhs_cv.get_column_id()) &&
1958  (rte_idx == rhs_cv.get_rte_idx());
1959  }
1960  const Var* v = dynamic_cast<const Var*>(this);
1961  if (v == nullptr) {
1962  return false;
1963  }
1964  const Var* rv = dynamic_cast<const Var*>(&rhs);
1965  if (rv == nullptr) {
1966  return false;
1967  }
1968  return (v->get_which_row() == rv->get_which_row()) &&
1969  (v->get_varno() == rv->get_varno());
1970 }
1971 
1972 bool ExpressionTuple::operator==(const Expr& rhs) const {
1973  const auto rhs_tuple = dynamic_cast<const ExpressionTuple*>(&rhs);
1974  if (!rhs_tuple) {
1975  return false;
1976  }
1977  const auto& rhs_tuple_cols = rhs_tuple->getTuple();
1978  return expr_list_match(tuple_, rhs_tuple_cols);
1979 }
1980 
1981 bool Datum_equal(const SQLTypeInfo& ti, Datum val1, Datum val2) {
1982  switch (ti.get_type()) {
1983  case kBOOLEAN:
1984  return val1.boolval == val2.boolval;
1985  case kCHAR:
1986  case kVARCHAR:
1987  case kTEXT:
1988  return *val1.stringval == *val2.stringval;
1989  case kNUMERIC:
1990  case kDECIMAL:
1991  case kBIGINT:
1992  return val1.bigintval == val2.bigintval;
1993  case kINT:
1994  return val1.intval == val2.intval;
1995  case kSMALLINT:
1996  return val1.smallintval == val2.smallintval;
1997  case kTINYINT:
1998  return val1.tinyintval == val2.tinyintval;
1999  case kFLOAT:
2000  return val1.floatval == val2.floatval;
2001  case kDOUBLE:
2002  return val1.doubleval == val2.doubleval;
2003  case kTIME:
2004  case kTIMESTAMP:
2005  case kDATE:
2006  case kINTERVAL_DAY_TIME:
2007  case kINTERVAL_YEAR_MONTH:
2008  return val1.bigintval == val2.bigintval;
2009  case kPOINT:
2010  case kLINESTRING:
2011  case kPOLYGON:
2012  case kMULTIPOLYGON:
2013  return *val1.stringval == *val2.stringval;
2014  default:
2015  throw std::runtime_error("Unrecognized type for Constant Datum equality: " +
2016  ti.get_type_name());
2017  }
2018  UNREACHABLE();
2019  return false;
2020 }
2021 
2022 bool Constant::operator==(const Expr& rhs) const {
2023  if (typeid(rhs) != typeid(Constant)) {
2024  return false;
2025  }
2026  const Constant& rhs_c = dynamic_cast<const Constant&>(rhs);
2027  if (type_info != rhs_c.get_type_info() || is_null != rhs_c.get_is_null()) {
2028  return false;
2029  }
2030  if (is_null && rhs_c.get_is_null()) {
2031  return true;
2032  }
2033  if (type_info.is_array()) {
2034  return false;
2035  }
2036  return Datum_equal(type_info, constval, rhs_c.get_constval());
2037 }
2038 
2039 bool UOper::operator==(const Expr& rhs) const {
2040  if (typeid(rhs) != typeid(UOper)) {
2041  return false;
2042  }
2043  const UOper& rhs_uo = dynamic_cast<const UOper&>(rhs);
2044  return optype == rhs_uo.get_optype() && *operand == *rhs_uo.get_operand();
2045 }
2046 
2047 bool BinOper::operator==(const Expr& rhs) const {
2048  if (typeid(rhs) != typeid(BinOper)) {
2049  return false;
2050  }
2051  const BinOper& rhs_bo = dynamic_cast<const BinOper&>(rhs);
2052  return optype == rhs_bo.get_optype() && *left_operand == *rhs_bo.get_left_operand() &&
2053  *right_operand == *rhs_bo.get_right_operand();
2054 }
2055 
2056 bool CharLengthExpr::operator==(const Expr& rhs) const {
2057  if (typeid(rhs) != typeid(CharLengthExpr)) {
2058  return false;
2059  }
2060  const CharLengthExpr& rhs_cl = dynamic_cast<const CharLengthExpr&>(rhs);
2061  if (!(*arg == *rhs_cl.get_arg()) ||
2063  return false;
2064  }
2065  return true;
2066 }
2067 
2068 bool KeyForStringExpr::operator==(const Expr& rhs) const {
2069  if (typeid(rhs) != typeid(KeyForStringExpr)) {
2070  return false;
2071  }
2072  const KeyForStringExpr& rhs_cl = dynamic_cast<const KeyForStringExpr&>(rhs);
2073  if (!(*arg == *rhs_cl.get_arg())) {
2074  return false;
2075  }
2076  return true;
2077 }
2078 
2079 bool LowerExpr::operator==(const Expr& rhs) const {
2080  if (typeid(rhs) != typeid(LowerExpr)) {
2081  return false;
2082  }
2083 
2084  return *arg == *dynamic_cast<const LowerExpr&>(rhs).get_arg();
2085 }
2086 
2087 bool CardinalityExpr::operator==(const Expr& rhs) const {
2088  if (typeid(rhs) != typeid(CardinalityExpr)) {
2089  return false;
2090  }
2091  const CardinalityExpr& rhs_ca = dynamic_cast<const CardinalityExpr&>(rhs);
2092  if (!(*arg == *rhs_ca.get_arg())) {
2093  return false;
2094  }
2095  return true;
2096 }
2097 
2098 bool LikeExpr::operator==(const Expr& rhs) const {
2099  if (typeid(rhs) != typeid(LikeExpr)) {
2100  return false;
2101  }
2102  const LikeExpr& rhs_lk = dynamic_cast<const LikeExpr&>(rhs);
2103  if (!(*arg == *rhs_lk.get_arg()) || !(*like_expr == *rhs_lk.get_like_expr()) ||
2104  is_ilike != rhs_lk.get_is_ilike()) {
2105  return false;
2106  }
2107  if (escape_expr.get() == rhs_lk.get_escape_expr()) {
2108  return true;
2109  }
2110  if (escape_expr != nullptr && rhs_lk.get_escape_expr() != nullptr &&
2111  *escape_expr == *rhs_lk.get_escape_expr()) {
2112  return true;
2113  }
2114  return false;
2115 }
2116 
2117 bool RegexpExpr::operator==(const Expr& rhs) const {
2118  if (typeid(rhs) != typeid(RegexpExpr)) {
2119  return false;
2120  }
2121  const RegexpExpr& rhs_re = dynamic_cast<const RegexpExpr&>(rhs);
2122  if (!(*arg == *rhs_re.get_arg()) || !(*pattern_expr == *rhs_re.get_pattern_expr())) {
2123  return false;
2124  }
2125  if (escape_expr.get() == rhs_re.get_escape_expr()) {
2126  return true;
2127  }
2128  if (escape_expr != nullptr && rhs_re.get_escape_expr() != nullptr &&
2129  *escape_expr == *rhs_re.get_escape_expr()) {
2130  return true;
2131  }
2132  return false;
2133 }
2134 
2135 bool LikelihoodExpr::operator==(const Expr& rhs) const {
2136  if (typeid(rhs) != typeid(LikelihoodExpr)) {
2137  return false;
2138  }
2139  const LikelihoodExpr& rhs_l = dynamic_cast<const LikelihoodExpr&>(rhs);
2140  if (!(*arg == *rhs_l.get_arg())) {
2141  return false;
2142  }
2143  if (likelihood != rhs_l.get_likelihood()) {
2144  return false;
2145  }
2146  return true;
2147 }
2148 
2149 bool InValues::operator==(const Expr& rhs) const {
2150  if (typeid(rhs) != typeid(InValues)) {
2151  return false;
2152  }
2153  const InValues& rhs_iv = dynamic_cast<const InValues&>(rhs);
2154  if (!(*arg == *rhs_iv.get_arg())) {
2155  return false;
2156  }
2157  if (value_list.size() != rhs_iv.get_value_list().size()) {
2158  return false;
2159  }
2160  auto q = rhs_iv.get_value_list().begin();
2161  for (auto p : value_list) {
2162  if (!(*p == **q)) {
2163  return false;
2164  }
2165  q++;
2166  }
2167  return true;
2168 }
2169 
2170 bool AggExpr::operator==(const Expr& rhs) const {
2171  if (typeid(rhs) != typeid(AggExpr)) {
2172  return false;
2173  }
2174  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2175  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2176  return false;
2177  }
2178  if (arg.get() == rhs_ae.get_arg()) {
2179  return true;
2180  }
2181  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2182  return false;
2183  }
2184  return *arg == *rhs_ae.get_arg();
2185 }
2186 
2187 bool CaseExpr::operator==(const Expr& rhs) const {
2188  if (typeid(rhs) != typeid(CaseExpr)) {
2189  return false;
2190  }
2191  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2192  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2193  return false;
2194  }
2195  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2196  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2197  return false;
2198  }
2199  auto it = rhs_ce.get_expr_pair_list().cbegin();
2200  for (auto p : expr_pair_list) {
2201  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2202  return false;
2203  }
2204  ++it;
2205  }
2206  return else_expr == nullptr ||
2207  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2208 }
2209 
2210 bool ExtractExpr::operator==(const Expr& rhs) const {
2211  if (typeid(rhs) != typeid(ExtractExpr)) {
2212  return false;
2213  }
2214  const ExtractExpr& rhs_ee = dynamic_cast<const ExtractExpr&>(rhs);
2215  return field_ == rhs_ee.get_field() && *from_expr_ == *rhs_ee.get_from_expr();
2216 }
2217 
2218 bool DateaddExpr::operator==(const Expr& rhs) const {
2219  if (typeid(rhs) != typeid(DateaddExpr)) {
2220  return false;
2221  }
2222  const DateaddExpr& rhs_ee = dynamic_cast<const DateaddExpr&>(rhs);
2223  return field_ == rhs_ee.get_field() && *number_ == *rhs_ee.get_number_expr() &&
2224  *datetime_ == *rhs_ee.get_datetime_expr();
2225 }
2226 
2227 bool DatediffExpr::operator==(const Expr& rhs) const {
2228  if (typeid(rhs) != typeid(DatediffExpr)) {
2229  return false;
2230  }
2231  const DatediffExpr& rhs_ee = dynamic_cast<const DatediffExpr&>(rhs);
2232  return field_ == rhs_ee.get_field() && *start_ == *rhs_ee.get_start_expr() &&
2233  *end_ == *rhs_ee.get_end_expr();
2234 }
2235 
2236 bool DatetruncExpr::operator==(const Expr& rhs) const {
2237  if (typeid(rhs) != typeid(DatetruncExpr)) {
2238  return false;
2239  }
2240  const DatetruncExpr& rhs_ee = dynamic_cast<const DatetruncExpr&>(rhs);
2241  return field_ == rhs_ee.get_field() && *from_expr_ == *rhs_ee.get_from_expr();
2242 }
2243 
2244 bool OffsetInFragment::operator==(const Expr& rhs) const {
2245  return typeid(rhs) == typeid(OffsetInFragment);
2246 }
2247 
2248 bool WindowFunction::operator==(const Expr& rhs) const {
2249  const auto rhs_window = dynamic_cast<const WindowFunction*>(&rhs);
2250  if (!rhs_window) {
2251  return false;
2252  }
2253  if (kind_ != rhs_window->kind_ || args_.size() != rhs_window->args_.size() ||
2254  partition_keys_.size() != rhs_window->partition_keys_.size() ||
2255  order_keys_.size() != rhs_window->order_keys_.size()) {
2256  return false;
2257  }
2258  return expr_list_match(args_, rhs_window->args_) &&
2259  expr_list_match(partition_keys_, rhs_window->partition_keys_) &&
2260  expr_list_match(order_keys_, rhs_window->order_keys_);
2261 }
2262 
2263 bool ArrayExpr::operator==(Expr const& rhs) const {
2264  if (typeid(rhs) != typeid(ArrayExpr)) {
2265  return false;
2266  }
2267  ArrayExpr const& casted_rhs = static_cast<ArrayExpr const&>(rhs);
2268  for (unsigned i = 0; i < contained_expressions_.size(); i++) {
2269  auto& lhs_expr = contained_expressions_[i];
2270  auto& rhs_expr = casted_rhs.contained_expressions_[i];
2271  if (!(lhs_expr == rhs_expr)) {
2272  return false;
2273  }
2274  }
2275  if (isNull() != casted_rhs.isNull()) {
2276  return false;
2277  }
2278 
2279  return true;
2280  ;
2281 }
2282 
2283 bool GeoExpr::operator==(const Expr& rhs) const {
2284  const auto rhs_geo = dynamic_cast<const GeoExpr*>(&rhs);
2285  if (!rhs_geo) {
2286  return false;
2287  }
2288  if (args_.size() != rhs_geo->args_.size()) {
2289  return false;
2290  }
2291  return expr_list_match(args_, rhs_geo->args_);
2292 }
2293 
2294 std::string ColumnVar::toString() const {
2295  return "(ColumnVar table: " + std::to_string(table_id) +
2296  " column: " + std::to_string(column_id) + " rte: " + std::to_string(rte_idx) +
2297  " " + get_type_info().get_type_name() + ") ";
2298 }
2299 
2300 std::string ExpressionTuple::toString() const {
2301  std::string str{"< "};
2302  for (const auto& column : tuple_) {
2303  str += column->toString();
2304  }
2305  str += "> ";
2306  return str;
2307 }
2308 
2309 std::string Var::toString() const {
2310  return "(Var table: " + std::to_string(table_id) +
2311  " column: " + std::to_string(column_id) + " rte: " + std::to_string(rte_idx) +
2312  " which_row: " + std::to_string(which_row) + " varno: " + std::to_string(varno) +
2313  ") ";
2314 }
2315 
2316 std::string Constant::toString() const {
2317  std::string str{"(Const "};
2318  if (is_null) {
2319  str += "NULL";
2320  } else if (type_info.is_array()) {
2321  const auto& elem_ti = type_info.get_elem_type();
2322  str += sql_type_to_str(type_info.get_type()) + ": " +
2323  sql_type_to_str(elem_ti.get_type());
2324  } else {
2325  str += DatumToString(constval, type_info);
2326  }
2327  str += ") ";
2328  return str;
2329 }
2330 
2331 std::string UOper::toString() const {
2332  std::string op;
2333  switch (optype) {
2334  case kNOT:
2335  op = "NOT ";
2336  break;
2337  case kUMINUS:
2338  op = "- ";
2339  break;
2340  case kISNULL:
2341  op = "IS NULL ";
2342  break;
2343  case kEXISTS:
2344  op = "EXISTS ";
2345  break;
2346  case kCAST:
2347  op = "CAST " + type_info.get_type_name() + "(" +
2349  std::to_string(type_info.get_scale()) + ") " +
2352  break;
2353  case kUNNEST:
2354  op = "UNNEST ";
2355  break;
2356  default:
2357  break;
2358  }
2359  return "(" + op + operand->toString() + ") ";
2360 }
2361 
2362 std::string BinOper::toString() const {
2363  std::string op;
2364  switch (optype) {
2365  case kEQ:
2366  op = "= ";
2367  break;
2368  case kNE:
2369  op = "<> ";
2370  break;
2371  case kLT:
2372  op = "< ";
2373  break;
2374  case kLE:
2375  op = "<= ";
2376  break;
2377  case kGT:
2378  op = "> ";
2379  break;
2380  case kGE:
2381  op = ">= ";
2382  break;
2383  case kAND:
2384  op = "AND ";
2385  break;
2386  case kOR:
2387  op = "OR ";
2388  break;
2389  case kMINUS:
2390  op = "- ";
2391  break;
2392  case kPLUS:
2393  op = "+ ";
2394  break;
2395  case kMULTIPLY:
2396  op = "* ";
2397  break;
2398  case kDIVIDE:
2399  op = "/ ";
2400  break;
2401  case kMODULO:
2402  op = "% ";
2403  break;
2404  case kARRAY_AT:
2405  op = "[] ";
2406  break;
2407  case kOVERLAPS:
2408  op = "OVERLAPS ";
2409  break;
2410  default:
2411  break;
2412  }
2413  std::string str{"("};
2414  str += op;
2415  if (qualifier == kANY) {
2416  str += "ANY ";
2417  } else if (qualifier == kALL) {
2418  str += "ALL ";
2419  }
2420  str += left_operand->toString();
2421  str += right_operand->toString();
2422  str += ") ";
2423  return str;
2424 }
2425 
2426 std::string Subquery::toString() const {
2427  return "(Subquery ) ";
2428 }
2429 
2430 std::string InValues::toString() const {
2431  std::string str{"(IN "};
2432  str += arg->toString();
2433  str += "(";
2434  for (auto e : value_list) {
2435  str += e->toString();
2436  }
2437  str += ") ";
2438  return str;
2439 }
2440 
2441 std::shared_ptr<Analyzer::Expr> InIntegerSet::deep_copy() const {
2442  return std::make_shared<InIntegerSet>(arg, value_list, get_type_info().get_notnull());
2443 }
2444 
2445 bool InIntegerSet::operator==(const Expr& rhs) const {
2446  if (!dynamic_cast<const InIntegerSet*>(&rhs)) {
2447  return false;
2448  }
2449  const auto& rhs_in_integer_set = static_cast<const InIntegerSet&>(rhs);
2450  return *arg == *rhs_in_integer_set.arg && value_list == rhs_in_integer_set.value_list;
2451 }
2452 
2453 std::string InIntegerSet::toString() const {
2454  std::string str{"(IN_INTEGER_SET "};
2455  str += arg->toString();
2456  str += "( ";
2457  for (const auto e : value_list) {
2458  str += std::to_string(e) + " ";
2459  }
2460  str += ") ";
2461  return str;
2462 }
2463 
2464 std::string CharLengthExpr::toString() const {
2465  std::string str;
2466  if (calc_encoded_length) {
2467  str += "CHAR_LENGTH(";
2468  } else {
2469  str += "LENGTH(";
2470  }
2471  str += arg->toString();
2472  str += ") ";
2473  return str;
2474 }
2475 
2476 std::string KeyForStringExpr::toString() const {
2477  std::string str{"KEY_FOR_STRING("};
2478  str += arg->toString();
2479  str += ") ";
2480  return str;
2481 }
2482 
2483 std::string LowerExpr::toString() const {
2484  return "LOWER(" + arg->toString() + ") ";
2485 }
2486 
2487 std::string CardinalityExpr::toString() const {
2488  std::string str{"CARDINALITY("};
2489  str += arg->toString();
2490  str += ") ";
2491  return str;
2492 }
2493 
2494 std::string LikeExpr::toString() const {
2495  std::string str{"(LIKE "};
2496  str += arg->toString();
2497  str += like_expr->toString();
2498  if (escape_expr) {
2499  str += escape_expr->toString();
2500  }
2501  str += ") ";
2502  return str;
2503 }
2504 
2505 std::string RegexpExpr::toString() const {
2506  std::string str{"(REGEXP "};
2507  str += arg->toString();
2508  str += pattern_expr->toString();
2509  if (escape_expr) {
2510  str += escape_expr->toString();
2511  }
2512  str += ") ";
2513  return str;
2514 }
2515 
2516 std::string LikelihoodExpr::toString() const {
2517  std::string str{"(LIKELIHOOD "};
2518  str += arg->toString();
2519  return str + " " + std::to_string(likelihood) + ") ";
2520 }
2521 
2522 std::string AggExpr::toString() const {
2523  std::string agg;
2524  switch (aggtype) {
2525  case kAVG:
2526  agg = "AVG ";
2527  break;
2528  case kMIN:
2529  agg = "MIN ";
2530  break;
2531  case kMAX:
2532  agg = "MAX ";
2533  break;
2534  case kSUM:
2535  agg = "SUM ";
2536  break;
2537  case kCOUNT:
2538  agg = "COUNT ";
2539  break;
2541  agg = "APPROX_COUNT_DISTINCT";
2542  break;
2543  case kSINGLE_VALUE:
2544  agg = "SINGLE_VALUE";
2545  break;
2546  case kSAMPLE:
2547  agg = "SAMPLE";
2548  break;
2549  }
2550  std::string str{"(" + agg};
2551  if (is_distinct) {
2552  str += "DISTINCT ";
2553  }
2554  if (arg) {
2555  str += arg->toString();
2556  } else {
2557  str += "*";
2558  }
2559  return str + ") ";
2560 }
2561 
2562 std::string CaseExpr::toString() const {
2563  std::string str{"CASE "};
2564  for (auto p : expr_pair_list) {
2565  str += "(";
2566  str += p.first->toString();
2567  str += ", ";
2568  str += p.second->toString();
2569  str += ") ";
2570  }
2571  if (else_expr) {
2572  str += "ELSE ";
2573  str += else_expr->toString();
2574  }
2575  str += " END ";
2576  return str;
2577 }
2578 
2579 std::string ExtractExpr::toString() const {
2580  return "EXTRACT(" + std::to_string(field_) + " FROM " + from_expr_->toString() + ") ";
2581 }
2582 
2583 std::string DateaddExpr::toString() const {
2584  return "DATEADD(" + std::to_string(field_) + " NUMBER " + number_->toString() +
2585  " DATETIME " + datetime_->toString() + ") ";
2586 }
2587 
2588 std::string DatediffExpr::toString() const {
2589  return "DATEDIFF(" + std::to_string(field_) + " START " + start_->toString() + " END " +
2590  end_->toString() + ") ";
2591 }
2592 
2593 std::string DatetruncExpr::toString() const {
2594  return "DATE_TRUNC(" + std::to_string(field_) + " , " + from_expr_->toString() + ") ";
2595 }
2596 
2597 std::string OffsetInFragment::toString() const {
2598  return "(OffsetInFragment) ";
2599 }
2600 
2601 std::string WindowFunction::toString() const {
2602  std::string result = "WindowFunction(" + sql_window_function_to_str(kind_);
2603  for (const auto& arg : args_) {
2604  result += " " + arg->toString();
2605  }
2606  return result + ") ";
2607 }
2608 
2609 std::string ArrayExpr::toString() const {
2610  std::string str{"ARRAY["};
2611 
2612  auto iter(contained_expressions_.begin());
2613  while (iter != contained_expressions_.end()) {
2614  str += (*iter)->toString();
2615  if (iter + 1 != contained_expressions_.end()) {
2616  str += ", ";
2617  }
2618  iter++;
2619  }
2620  str += "]";
2621  return str;
2622 }
2623 
2624 std::string GeoExpr::toString() const {
2625  // TODO: generate ST_GeomFromText(wkt)
2626  std::string result = "Geo(";
2627  for (const auto& arg : args_) {
2628  result += " " + arg->toString();
2629  }
2630  return result + ") ";
2631 }
2632 
2633 std::string TargetEntry::toString() const {
2634  std::string str{"(" + resname + " "};
2635  str += expr->toString();
2636  if (unnest) {
2637  str += " UNNEST";
2638  }
2639  str += ") ";
2640  return str;
2641 }
2642 
2643 std::string OrderEntry::toString() const {
2644  std::string str{std::to_string(tle_no)};
2645  if (is_desc) {
2646  str += " desc";
2647  }
2648  if (nulls_first) {
2649  str += " nulls first";
2650  }
2651  str += " ";
2652  return str;
2653 }
2654 
2655 void Expr::add_unique(std::list<const Expr*>& expr_list) const {
2656  // only add unique instances to the list
2657  for (auto e : expr_list) {
2658  if (*e == *this) {
2659  return;
2660  }
2661  }
2662  expr_list.push_back(this);
2663 }
2664 
2665 void BinOper::find_expr(bool (*f)(const Expr*), std::list<const Expr*>& expr_list) const {
2666  if (f(this)) {
2667  add_unique(expr_list);
2668  return;
2669  }
2670  left_operand->find_expr(f, expr_list);
2671  right_operand->find_expr(f, expr_list);
2672 }
2673 
2674 void UOper::find_expr(bool (*f)(const Expr*), std::list<const Expr*>& expr_list) const {
2675  if (f(this)) {
2676  add_unique(expr_list);
2677  return;
2678  }
2679  operand->find_expr(f, expr_list);
2680 }
2681 
2682 void InValues::find_expr(bool (*f)(const Expr*),
2683  std::list<const Expr*>& expr_list) const {
2684  if (f(this)) {
2685  add_unique(expr_list);
2686  return;
2687  }
2688  arg->find_expr(f, expr_list);
2689  for (auto e : value_list) {
2690  e->find_expr(f, expr_list);
2691  }
2692 }
2693 
2694 void CharLengthExpr::find_expr(bool (*f)(const Expr*),
2695  std::list<const Expr*>& expr_list) const {
2696  if (f(this)) {
2697  add_unique(expr_list);
2698  return;
2699  }
2700  arg->find_expr(f, expr_list);
2701 }
2702 
2703 void KeyForStringExpr::find_expr(bool (*f)(const Expr*),
2704  std::list<const Expr*>& expr_list) const {
2705  if (f(this)) {
2706  add_unique(expr_list);
2707  return;
2708  }
2709  arg->find_expr(f, expr_list);
2710 }
2711 
2712 void LowerExpr::find_expr(bool (*f)(const Expr*),
2713  std::list<const Expr*>& expr_list) const {
2714  if (f(this)) {
2715  add_unique(expr_list);
2716  } else {
2717  arg->find_expr(f, expr_list);
2718  }
2719 }
2720 
2721 void CardinalityExpr::find_expr(bool (*f)(const Expr*),
2722  std::list<const Expr*>& expr_list) const {
2723  if (f(this)) {
2724  add_unique(expr_list);
2725  return;
2726  }
2727  arg->find_expr(f, expr_list);
2728 }
2729 
2730 void LikeExpr::find_expr(bool (*f)(const Expr*),
2731  std::list<const Expr*>& expr_list) const {
2732  if (f(this)) {
2733  add_unique(expr_list);
2734  return;
2735  }
2736  arg->find_expr(f, expr_list);
2737  like_expr->find_expr(f, expr_list);
2738  if (escape_expr != nullptr) {
2739  escape_expr->find_expr(f, expr_list);
2740  }
2741 }
2742 
2743 void RegexpExpr::find_expr(bool (*f)(const Expr*),
2744  std::list<const Expr*>& expr_list) const {
2745  if (f(this)) {
2746  add_unique(expr_list);
2747  return;
2748  }
2749  arg->find_expr(f, expr_list);
2750  pattern_expr->find_expr(f, expr_list);
2751  if (escape_expr != nullptr) {
2752  escape_expr->find_expr(f, expr_list);
2753  }
2754 }
2755 
2756 void LikelihoodExpr::find_expr(bool (*f)(const Expr*),
2757  std::list<const Expr*>& expr_list) const {
2758  if (f(this)) {
2759  add_unique(expr_list);
2760  return;
2761  }
2762  arg->find_expr(f, expr_list);
2763 }
2764 
2765 void AggExpr::find_expr(bool (*f)(const Expr*), std::list<const Expr*>& expr_list) const {
2766  if (f(this)) {
2767  add_unique(expr_list);
2768  return;
2769  }
2770  if (arg != nullptr) {
2771  arg->find_expr(f, expr_list);
2772  }
2773 }
2774 
2775 void CaseExpr::find_expr(bool (*f)(const Expr*),
2776  std::list<const Expr*>& expr_list) const {
2777  if (f(this)) {
2778  add_unique(expr_list);
2779  return;
2780  }
2781  for (auto p : expr_pair_list) {
2782  p.first->find_expr(f, expr_list);
2783  p.second->find_expr(f, expr_list);
2784  }
2785  if (else_expr != nullptr) {
2786  else_expr->find_expr(f, expr_list);
2787  }
2788 }
2789 
2790 void ExtractExpr::find_expr(bool (*f)(const Expr*),
2791  std::list<const Expr*>& expr_list) const {
2792  if (f(this)) {
2793  add_unique(expr_list);
2794  return;
2795  }
2796  from_expr_->find_expr(f, expr_list);
2797 }
2798 
2799 void DateaddExpr::find_expr(bool (*f)(const Expr*),
2800  std::list<const Expr*>& expr_list) const {
2801  if (f(this)) {
2802  add_unique(expr_list);
2803  return;
2804  }
2805  number_->find_expr(f, expr_list);
2806  datetime_->find_expr(f, expr_list);
2807 }
2808 
2809 void DatediffExpr::find_expr(bool (*f)(const Expr*),
2810  std::list<const Expr*>& expr_list) const {
2811  if (f(this)) {
2812  add_unique(expr_list);
2813  return;
2814  }
2815  start_->find_expr(f, expr_list);
2816  end_->find_expr(f, expr_list);
2817 }
2818 
2819 void DatetruncExpr::find_expr(bool (*f)(const Expr*),
2820  std::list<const Expr*>& expr_list) const {
2821  if (f(this)) {
2822  add_unique(expr_list);
2823  return;
2824  }
2825  from_expr_->find_expr(f, expr_list);
2826 }
2827 
2828 void CaseExpr::collect_rte_idx(std::set<int>& rte_idx_set) const {
2829  for (auto p : expr_pair_list) {
2830  p.first->collect_rte_idx(rte_idx_set);
2831  p.second->collect_rte_idx(rte_idx_set);
2832  }
2833  if (else_expr != nullptr) {
2834  else_expr->collect_rte_idx(rte_idx_set);
2835  }
2836 }
2837 
2838 void ExtractExpr::collect_rte_idx(std::set<int>& rte_idx_set) const {
2839  from_expr_->collect_rte_idx(rte_idx_set);
2840 }
2841 
2842 void DateaddExpr::collect_rte_idx(std::set<int>& rte_idx_set) const {
2843  number_->collect_rte_idx(rte_idx_set);
2844  datetime_->collect_rte_idx(rte_idx_set);
2845 }
2846 
2847 void DatediffExpr::collect_rte_idx(std::set<int>& rte_idx_set) const {
2848  start_->collect_rte_idx(rte_idx_set);
2849  end_->collect_rte_idx(rte_idx_set);
2850 }
2851 
2852 void DatetruncExpr::collect_rte_idx(std::set<int>& rte_idx_set) const {
2853  from_expr_->collect_rte_idx(rte_idx_set);
2854 }
2855 
2857  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>& colvar_set,
2858  bool include_agg) const {
2859  for (auto p : expr_pair_list) {
2860  p.first->collect_column_var(colvar_set, include_agg);
2861  p.second->collect_column_var(colvar_set, include_agg);
2862  }
2863  if (else_expr != nullptr) {
2864  else_expr->collect_column_var(colvar_set, include_agg);
2865  }
2866 }
2867 
2869  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>& colvar_set,
2870  bool include_agg) const {
2871  from_expr_->collect_column_var(colvar_set, include_agg);
2872 }
2873 
2875  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>& colvar_set,
2876  bool include_agg) const {
2877  number_->collect_column_var(colvar_set, include_agg);
2878  datetime_->collect_column_var(colvar_set, include_agg);
2879 }
2880 
2882  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>& colvar_set,
2883  bool include_agg) const {
2884  start_->collect_column_var(colvar_set, include_agg);
2885  end_->collect_column_var(colvar_set, include_agg);
2886 }
2887 
2889  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>& colvar_set,
2890  bool include_agg) const {
2891  from_expr_->collect_column_var(colvar_set, include_agg);
2892 }
2893 
2895  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
2896  for (auto p : expr_pair_list) {
2897  p.first->check_group_by(groupby);
2898  p.second->check_group_by(groupby);
2899  }
2900  if (else_expr != nullptr) {
2901  else_expr->check_group_by(groupby);
2902  }
2903 }
2904 
2906  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
2907  from_expr_->check_group_by(groupby);
2908 }
2909 
2911  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
2912  number_->check_group_by(groupby);
2913  datetime_->check_group_by(groupby);
2914 }
2915 
2917  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
2918  start_->check_group_by(groupby);
2919  end_->check_group_by(groupby);
2920 }
2921 
2923  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {
2924  from_expr_->check_group_by(groupby);
2925 }
2926 
2927 void CaseExpr::get_domain(DomainSet& domain_set) const {
2928  for (const auto& p : expr_pair_list) {
2929  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
2930  if (c != nullptr) {
2931  c->add_unique(domain_set);
2932  } else {
2933  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2934  if (v != nullptr) {
2935  v->add_unique(domain_set);
2936  } else {
2937  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
2938  if (cast != nullptr && cast->get_optype() == kCAST) {
2939  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2940  if (c != nullptr) {
2941  cast->add_unique(domain_set);
2942  continue;
2943  } else {
2944  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2945  if (v != nullptr) {
2946  v->add_unique(domain_set);
2947  continue;
2948  }
2949  }
2950  }
2951  p.second->get_domain(domain_set);
2952  if (domain_set.empty()) {
2953  return;
2954  }
2955  }
2956  }
2957  }
2958  if (else_expr != nullptr) {
2959  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
2960  if (c != nullptr) {
2961  c->add_unique(domain_set);
2962  } else {
2963  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2964  if (v != nullptr) {
2965  v->add_unique(domain_set);
2966  } else {
2967  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
2968  if (cast != nullptr && cast->get_optype() == kCAST) {
2969  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2970  if (c != nullptr) {
2971  c->add_unique(domain_set);
2972  } else {
2973  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2974  if (v != nullptr) {
2975  v->add_unique(domain_set);
2976  }
2977  }
2978  } else {
2979  else_expr->get_domain(domain_set);
2980  }
2981  }
2982  }
2983  }
2984 }
2985 
2986 std::shared_ptr<Analyzer::Expr> FunctionOper::deep_copy() const {
2987  std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
2988  for (size_t i = 0; i < getArity(); ++i) {
2989  args_copy.push_back(getArg(i)->deep_copy());
2990  }
2991  return makeExpr<Analyzer::FunctionOper>(type_info, getName(), args_copy);
2992 }
2993 
2994 bool FunctionOper::operator==(const Expr& rhs) const {
2995  if (type_info != rhs.get_type_info()) {
2996  return false;
2997  }
2998  const auto rhs_func_oper = dynamic_cast<const FunctionOper*>(&rhs);
2999  if (!rhs_func_oper) {
3000  return false;
3001  }
3002  if (getName() != rhs_func_oper->getName()) {
3003  return false;
3004  }
3005  if (getArity() != rhs_func_oper->getArity()) {
3006  return false;
3007  }
3008  for (size_t i = 0; i < getArity(); ++i) {
3009  if (!(*getArg(i) == *(rhs_func_oper->getArg(i)))) {
3010  return false;
3011  }
3012  }
3013  return true;
3014 }
3015 
3016 std::string FunctionOper::toString() const {
3017  std::string str{"(" + name_ + " "};
3018  for (const auto& arg : args_) {
3019  str += arg->toString();
3020  }
3021  str += ")";
3022  return str;
3023 }
3024 
3025 std::shared_ptr<Analyzer::Expr> FunctionOperWithCustomTypeHandling::deep_copy() const {
3026  std::vector<std::shared_ptr<Analyzer::Expr>> args_copy;
3027  for (size_t i = 0; i < getArity(); ++i) {
3028  args_copy.push_back(getArg(i)->deep_copy());
3029  }
3030  return makeExpr<Analyzer::FunctionOperWithCustomTypeHandling>(
3031  type_info, getName(), args_copy);
3032 }
3033 
3035  if (type_info != rhs.get_type_info()) {
3036  return false;
3037  }
3038  const auto rhs_func_oper =
3039  dynamic_cast<const FunctionOperWithCustomTypeHandling*>(&rhs);
3040  if (!rhs_func_oper) {
3041  return false;
3042  }
3043  if (getName() != rhs_func_oper->getName()) {
3044  return false;
3045  }
3046  if (getArity() != rhs_func_oper->getArity()) {
3047  return false;
3048  }
3049  for (size_t i = 0; i < getArity(); ++i) {
3050  if (!(*getArg(i) == *(rhs_func_oper->getArg(i)))) {
3051  return false;
3052  }
3053  }
3054  return true;
3055 }
3056 
3057 } // namespace Analyzer
3058 
3059 bool expr_list_match(const std::vector<std::shared_ptr<Analyzer::Expr>>& lhs,
3060  const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs) {
3061  if (lhs.size() != rhs.size()) {
3062  return false;
3063  }
3064  for (size_t i = 0; i < lhs.size(); ++i) {
3065  if (!(*lhs[i] == *rhs[i])) {
3066  return false;
3067  }
3068  }
3069  return true;
3070 }
3071 
3072 std::shared_ptr<Analyzer::Expr> remove_cast(const std::shared_ptr<Analyzer::Expr>& expr) {
3073  const auto uoper = dynamic_cast<const Analyzer::UOper*>(expr.get());
3074  if (!uoper || uoper->get_optype() != kCAST) {
3075  return expr;
3076  }
3077  return uoper->get_own_operand();
3078 }
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2790
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1017
int8_t tinyintval
Definition: sqltypes.h:133
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3025
int get_table_id() const
Definition: Analyzer.h:194
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:967
Query * next_query
Definition: Analyzer.h:1567
Defines data structures for the semantic analysis phase of query processing.
InIntegerSet(const std::shared_ptr< const Analyzer::Expr > a, const std::vector< int64_t > &values, const bool not_null)
Definition: Analyzer.cpp:1482
Definition: sqldefs.h:69
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1774
NEVER_INLINE DEVICE int64_t DateTruncate(DatetruncField field, const int64_t timeval)
HOST DEVICE SQLTypes get_subtype() const
Definition: sqltypes.h:259
void set_compression(EncodingType c)
Definition: sqltypes.h:358
Query * parsetree
Definition: Analyzer.h:566
float get_likelihood() const
Definition: Analyzer.h:984
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1923
std::shared_ptr< Analyzer::Expr > expr
Definition: Analyzer.h:1492
std::string toString() const override
Definition: Analyzer.cpp:2453
bool unnest
Definition: Analyzer.h:1493
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1468
InValues(std::shared_ptr< Analyzer::Expr > a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.cpp:1464
const Expr * get_from_expr() const
Definition: Analyzer.h:1146
static bool simple_predicate_has_simple_cast(const std::shared_ptr< Analyzer::Expr > cast_operand, const std::shared_ptr< Analyzer::Expr > const_operand)
Definition: Analyzer.cpp:1329
#define IS_LOGIC(X)
Definition: sqldefs.h:60
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2227
#define NULL_DOUBLE
Definition: sqltypes.h:185
std::string toString() const override
Definition: Analyzer.cpp:2300
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2765
void get_domain(DomainSet &domain_set) const override
Definition: Analyzer.cpp:2927
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1945
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2047
const Expr * get_else_expr() const
Definition: Analyzer.h:1101
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2994
bool Datum_equal(const SQLTypeInfo &ti, Datum val1, Datum val2)
Definition: Analyzer.cpp:1981
std::string DatumToString(Datum d, const SQLTypeInfo &ti)
Definition: Datum.cpp:227
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2682
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2039
const Expr * get_escape_expr() const
Definition: Analyzer.h:857
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:732
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1852
std::shared_ptr< Analyzer::Expr > decompress()
Definition: Analyzer.cpp:664
size_t getArity() const
Definition: Analyzer.h:1309
Definition: sqltypes.h:50
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:3072
void add_rte(RangeTableEntry *rte)
Definition: Analyzer.cpp:1282
std::shared_ptr< Analyzer::Expr > operand
Definition: Analyzer.h:405
EncodingType
Definition: encodetypes.h:22
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:686
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1619
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1909
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2244
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1895
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2087
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1404
#define NULL_BIGINT
Definition: sqltypes.h:183
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2712
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2655
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:511
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:971
bool boolval
Definition: sqltypes.h:132
bool operator==(Expr const &rhs) const override
Definition: Analyzer.cpp:2263
ExtractField get_field() const
Definition: Analyzer.h:1145
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:208
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1742
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1501
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:130
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:126
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:95
bool is_fp() const
Definition: sqltypes.h:413
const Expr * get_escape_expr() const
Definition: Analyzer.h:929
HOST DEVICE int get_scale() const
Definition: sqltypes.h:263
const Expr * get_right_operand() const
Definition: Analyzer.h:437
SQLOps
Definition: sqldefs.h:29
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1585
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:2842
Definition: sqldefs.h:35
std::string get_compression_name() const
Definition: sqltypes.h:386
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:608
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:80
Definition: sqldefs.h:36
std::shared_ptr< Analyzer::Expr > like_expr
Definition: Analyzer.h:904
bool get_is_null() const
Definition: Analyzer.h:328
Definition: sqldefs.h:38
std::string toString() const override
Definition: Analyzer.cpp:3016
VarlenDatum * arrayval
Definition: sqltypes.h:139
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:2881
int tle_no
Definition: Analyzer.h:1367
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:134
const std::shared_ptr< const Analyzer::Expr > arg
Definition: Analyzer.h:637
#define UNREACHABLE()
Definition: Logger.h:241
const std::shared_ptr< Analyzer::Expr > get_own_operand() const
Definition: Analyzer.h:366
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:194
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:198
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1052
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:2922
Definition: sqldefs.h:49
Definition: sqldefs.h:30
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1239
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:180
const Expr * get_arg() const
Definition: Analyzer.h:926
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1887
Expr * get_arg() const
Definition: Analyzer.h:1045
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2170
DatetruncField get_field() const
Definition: Analyzer.h:1270
Definition: sqldefs.h:41
const Expr * get_arg() const
Definition: Analyzer.h:982
bool is_expr_nullable(const Analyzer::Expr *expr)
Definition: Analyzer.cpp:1440
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1220
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3034
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:59
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1328
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:1413
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2149
HOST DEVICE SQLTypes get_type() const
Definition: sqltypes.h:258
~Constant() override
Definition: Analyzer.cpp:41
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2079
SQLQualifier qualifier
Definition: Analyzer.h:508
bool isNull() const
Definition: Analyzer.h:1439
std::string toString() const override
Definition: Analyzer.cpp:2583
bool is_number() const
Definition: sqltypes.h:414
constexpr int64_t get_datetime_scaled_epoch(const ScalingType direction, const int64_t epoch, const int32_t dimen)
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1515
std::string toString() const override
Definition: Analyzer.cpp:2362
SQLTypeInfo type_info
Definition: Analyzer.h:176
std::list< const Expr * > DomainSet
Definition: Analyzer.h:61
int32_t intval
Definition: sqltypes.h:135
const Expr * get_arg() const
Definition: Analyzer.h:854
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2743
bool is_time() const
Definition: sqltypes.h:415
std::string toString() const override
Definition: Analyzer.cpp:2309
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1314
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1881
std::string to_string(char const *&&v)
~Subquery() override
Definition: Analyzer.cpp:47
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2187
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1271
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1041
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1412
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:2905
std::string toString() const override
Definition: Analyzer.cpp:2331
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:69
std::string toString() const override
Definition: Analyzer.cpp:2430
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2665
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2068
std::string toString() const override
Definition: Analyzer.cpp:2494
std::string toString() const override
Definition: Analyzer.cpp:2516
std::string toString() const override
Definition: Analyzer.cpp:2464
Definition: sqldefs.h:73
bool get_calc_encoded_length() const
Definition: Analyzer.h:652
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1765
DatetruncField field_
Definition: Analyzer.h:1296
std::string toString() const override
Definition: Analyzer.cpp:2601
SQLOps get_optype() const
Definition: Analyzer.h:433
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:510
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2248
float floatval
Definition: sqltypes.h:137
std::string toString() const
Definition: Analyzer.cpp:2633
std::shared_ptr< Analyzer::Expr > normalize_simple_predicate(int &rte_idx) const override
Definition: Analyzer.cpp:1353
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:610
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:152
static SQLTypeInfo common_string_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:387
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1396
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:163
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1806
const DatetruncField field_
Definition: Analyzer.h:1254
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1529
CHECK(cgen_state)
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
Definition: Analyzer.h:244
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:2847
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1929
bool is_castable(const SQLTypeInfo &new_type_info) const
Definition: sqltypes.h:482
void set_fixed_size()
Definition: sqltypes.h:357
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:2838
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2730
bool is_integer() const
Definition: sqltypes.h:411
std::string toString() const override
Definition: Analyzer.cpp:2476
#define NULL_TINYINT
Definition: sqltypes.h:180
const DateaddField field_
Definition: Analyzer.h:1212
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:108
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1297
bool expr_list_match(const std::vector< std::shared_ptr< Analyzer::Expr >> &lhs, const std::vector< std::shared_ptr< Analyzer::Expr >> &rhs)
Definition: Analyzer.cpp:3059
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:788
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2445
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:179
std::string toString() const override
Definition: Analyzer.cpp:2294
void set_scale(int s)
Definition: sqltypes.h:353
int64_t bigintval
Definition: sqltypes.h:136
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1302
const std::shared_ptr< Analyzer::Expr > end_
Definition: Analyzer.h:1256
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2210
std::string toString() const override
Definition: Analyzer.cpp:2505
WhichRow get_which_row() const
Definition: Analyzer.h:273
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:2910
#define NULL_FLOAT
Definition: sqltypes.h:184
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2135
const std::shared_ptr< Analyzer::Expr > number_
Definition: Analyzer.h:1213
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:342
bool is_timeinterval() const
Definition: sqltypes.h:420
std::string resname
Definition: Analyzer.h:1491
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:2441
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2218
std::string toString() const override
Definition: Analyzer.cpp:2593
std::string sql_window_function_to_str(const SqlWindowFunctionKind kind)
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2283
static SQLTypeInfo common_numeric_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:427
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:2852
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1783
Definition: sqldefs.h:37
Definition: sqldefs.h:75
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1543
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:1951
Definition: sqldefs.h:69
int16_t smallintval
Definition: sqltypes.h:134
const std::shared_ptr< Analyzer::Expr > start_
Definition: Analyzer.h:1255
int get_varno() const
Definition: Analyzer.h:275
std::string toString() const
Definition: Analyzer.cpp:2643
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1557
bool nulls_first
Definition: Analyzer.h:1369
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:2856
Datum StringToDatum(std::string_view s, SQLTypeInfo &ti)
Definition: Datum.cpp:122
bool get_is_distinct() const
Definition: Analyzer.h:1047
#define NULL_INT
Definition: sqltypes.h:182
bool is_boolean() const
Definition: sqltypes.h:416
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2056
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:1415
const Expr * get_start_expr() const
Definition: Analyzer.h:1229
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1071
std::string toString() const override
Definition: Analyzer.cpp:2316
IntFracRepr decimal_to_int_frac(const int64_t dec, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:717
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1663
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2809
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:78
WhichRow which_row
Definition: Analyzer.h:296
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1823
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:2888
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1633
int get_precision() const
Definition: sqltypes.h:261
std::string * stringval
Definition: sqltypes.h:141
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:2986
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:903
const std::vector< std::shared_ptr< Analyzer::Expr > > tuple_
Definition: Analyzer.h:254
Definition: sqldefs.h:34
void set_comp_param(int p)
Definition: sqltypes.h:359
const std::vector< int64_t > value_list
Definition: Analyzer.h:638
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:2828
const Expr * get_pattern_expr() const
Definition: Analyzer.h:928
Definition: sqltypes.h:53
Definition: sqltypes.h:54
Definition: sqldefs.h:40
ExpressionPtrVector contained_expressions_
Definition: Analyzer.h:1447
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1797
Definition: sqldefs.h:69
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1599
const Expr * get_from_expr() const
Definition: Analyzer.h:1271
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2819
virtual ~Query()
Definition: Analyzer.cpp:51
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:197
DEVICE int64_t DateTruncateHighPrecisionToDate(const int64_t timeval, const int64_t scale)
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2721
bool is_in_values_nullable(const std::shared_ptr< Analyzer::Expr > &a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.cpp:1449
const Expr * get_datetime_expr() const
Definition: Analyzer.h:1188
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:266
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:175
std::string toString() const override
Definition: Analyzer.cpp:2579
const Expr * get_like_expr() const
Definition: Analyzer.h:856
int64_t convert_decimal_value_to_scale(const int64_t decimal_value, const SQLTypeInfo &type_info, const SQLTypeInfo &new_type_info)
Definition: Datum.cpp:318
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2674
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1677
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1311
#define IS_ARITHMETIC(X)
Definition: sqldefs.h:61
void set_dimension(int d)
Definition: sqltypes.h:350
std::string toString() const override
Definition: Analyzer.cpp:2597
int get_rte_idx() const
Definition: Analyzer.h:196
const Expr * get_operand() const
Definition: Analyzer.h:365
Analyzer::ExpressionPtr deep_copy() const override
Definition: Analyzer.cpp:203
Datum get_constval() const
Definition: Analyzer.h:329
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2694
Definition: sqldefs.h:32
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:1972
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1571
Definition: sqldefs.h:76
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1194
const Expr * get_arg() const
Definition: Analyzer.h:650
HOST DEVICE int get_dimension() const
Definition: sqltypes.h:260
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:580
std::string toString() const override
Definition: Analyzer.cpp:2588
std::vector< RangeTableEntry * > rangetable
Definition: Analyzer.h:1560
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1172
std::string get_type_name() const
Definition: sqltypes.h:361
std::string toString() const override
Definition: Analyzer.cpp:2522
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1937
Expression class for the LOWER (lowercase) string function. The &quot;arg&quot; constructor parameter must be a...
Definition: Analyzer.h:740
Definition: sqltypes.h:42
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:678
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1309
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:746
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:63
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:267
DateaddField get_field() const
Definition: Analyzer.h:1186
SQLAgg get_aggtype() const
Definition: Analyzer.h:1044
std::string toString() const override
Definition: Analyzer.cpp:2609
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:146
const std::shared_ptr< Analyzer::Expr > datetime_
Definition: Analyzer.h:1214
const Expr * get_arg() const
Definition: Analyzer.h:699
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2799
#define NULL_SMALLINT
Definition: sqltypes.h:181
std::string sql_type_to_str(const SQLTypes &type)
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:833
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1756
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2775
void set_notnull(bool n)
Definition: sqltypes.h:355
const Expr * get_end_expr() const
Definition: Analyzer.h:1230
bool is_geometry() const
Definition: sqltypes.h:421
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2098
ExtractField field_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1903
bool is_desc
Definition: Analyzer.h:1368
std::string toString() const override
Definition: Analyzer.cpp:2483
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1265
constexpr int64_t get_timestamp_precision_scale(const int32_t dimen)
Definition: DateTimeUtils.h:51
bool is_high_precision_timestamp() const
Definition: sqltypes.h:637
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1060
#define COMMUTE_COMPARISON(X)
Definition: sqldefs.h:63
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:122
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1418
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:114
Definition: sqldefs.h:33
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:906
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1487
const Expr * get_left_operand() const
Definition: Analyzer.h:436
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1469
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:189
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:99
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:2868
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2756
Definition: sqltypes.h:46
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1866
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:1411
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1286
std::string toString() const override
Definition: Analyzer.cpp:2624
int get_column_id() const
Definition: Analyzer.h:195
std::string toString() const override
Definition: Analyzer.cpp:2426
bool is_string() const
Definition: sqltypes.h:409
std::string getName() const
Definition: Analyzer.h:1307
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2236
bool expr_is(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:1323
HOST DEVICE bool get_notnull() const
Definition: sqltypes.h:265
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2022
std::string toString() const override
Definition: Analyzer.cpp:2487
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1648
Definition: sqldefs.h:74
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:138
bool contains_agg
Definition: Analyzer.h:177
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:617
bool is_decimal() const
Definition: sqltypes.h:412
const Expr * get_arg() const
Definition: Analyzer.h:800
DatetruncField get_field() const
Definition: Analyzer.h:1228
Definition: sqldefs.h:72
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:2703
std::list< OrderEntry > * order_by
Definition: Analyzer.h:1566
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:84
std::shared_ptr< Analyzer::Expr > pattern_expr
Definition: Analyzer.h:969
Definition: sqldefs.h:39
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:198
std::string toString() const override
Definition: Analyzer.cpp:2562
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:2916
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
const Expr * get_arg() const
Definition: Analyzer.h:578
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:155
static SQLTypeInfo analyze_type_info(SQLOps op, const SQLTypeInfo &left_type, const SQLTypeInfo &right_type, SQLTypeInfo *new_left_type, SQLTypeInfo *new_right_type)
Definition: Analyzer.cpp:212
#define NULL_BOOLEAN
Definition: sqltypes.h:179
SQLOps get_optype() const
Definition: Analyzer.h:364
bool is_date() const
Definition: sqltypes.h:635
bool is_array() const
Definition: sqltypes.h:417
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const
Definition: Analyzer.h:1098
const Expr * get_arg() const
Definition: Analyzer.h:744
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:2874
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:2894
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1860
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:184
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2117
#define IS_COMPARISON(X)
Definition: sqldefs.h:57
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1715
double doubleval
Definition: sqltypes.h:138
SQLOps optype
Definition: Analyzer.h:404
const Expr * get_number_expr() const
Definition: Analyzer.h:1187
const std::string name_
Definition: Analyzer.h:1327
bool get_is_ilike() const
Definition: Analyzer.h:858
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1838
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1691
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1844