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