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