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