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