OmniSciDB  8a228a1076
Analyzer.h
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 
24 #ifndef ANALYZER_H
25 #define ANALYZER_H
26 
27 #include "../Logger/Logger.h"
28 
29 #include <cstdint>
30 #include <iostream>
31 #include <list>
32 #include <set>
33 #include <string>
34 #include <type_traits>
35 #include <utility>
36 #include <vector>
37 
38 #include "../Shared/geo_types.h"
39 #include "../Shared/sqldefs.h"
40 #include "../Shared/sqltypes.h"
41 
42 namespace Analyzer {
43 class Expr;
44 }
45 
46 namespace Catalog_Namespace {
47 class Catalog;
48 }
49 
50 template <typename Tp, typename... Args>
51 inline typename std::enable_if<std::is_base_of<Analyzer::Expr, Tp>::value,
52  std::shared_ptr<Tp>>::type
53 makeExpr(Args&&... args) {
54  return std::make_shared<Tp>(std::forward<Args>(args)...);
55 }
56 
57 namespace Analyzer {
58 
59 class ColumnVar;
60 class TargetEntry;
61 class Expr;
62 using DomainSet = std::list<const Expr*>;
63 
64 /*
65  * @type Expr
66  * @brief super class for all expressions in parse trees and in query plans
67  */
68 class Expr : public std::enable_shared_from_this<Expr> {
69  public:
70  Expr(SQLTypes t, bool notnull) : type_info(t, notnull), contains_agg(false) {}
71  Expr(SQLTypes t, int d, bool notnull)
72  : type_info(t, d, 0, notnull), contains_agg(false) {}
73  Expr(SQLTypes t, int d, int s, bool notnull)
74  : type_info(t, d, s, notnull), contains_agg(false) {}
75  Expr(const SQLTypeInfo& ti, bool has_agg = false)
76  : type_info(ti), contains_agg(has_agg) {}
77  virtual ~Expr() {}
78  std::shared_ptr<Analyzer::Expr> get_shared_ptr() { return shared_from_this(); }
79  const SQLTypeInfo& get_type_info() const { return type_info; }
80  void set_type_info(const SQLTypeInfo& ti) { type_info = ti; }
81  bool get_contains_agg() const { return contains_agg; }
82  void set_contains_agg(bool a) { contains_agg = a; }
83  virtual std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info);
84  virtual void check_group_by(
85  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {};
86  virtual std::shared_ptr<Analyzer::Expr> deep_copy()
87  const = 0; // make a deep copy of self
88  /*
89  * @brief normalize_simple_predicate only applies to boolean expressions.
90  * it checks if it is an expression comparing a column
91  * with a constant. if so, it returns a normalized copy of the predicate with ColumnVar
92  * always as the left operand with rte_idx set to the rte_idx of the ColumnVar.
93  * it returns nullptr with rte_idx set to -1 otherwise.
94  */
95  virtual std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const {
96  rte_idx = -1;
97  return nullptr;
98  }
99  /*
100  * @brief seperate conjunctive predicates into scan predicates, join predicates and
101  * constant predicates.
102  */
103  virtual void group_predicates(std::list<const Expr*>& scan_predicates,
104  std::list<const Expr*>& join_predicates,
105  std::list<const Expr*>& const_predicates) const {}
106  /*
107  * @brief collect_rte_idx collects the indices of all the range table
108  * entries involved in an expression
109  */
110  virtual void collect_rte_idx(std::set<int>& rte_idx_set) const {}
111  /*
112  * @brief collect_column_var collects all unique ColumnVar nodes in an expression
113  * If include_agg = false, it does not include to ColumnVar nodes inside
114  * the argument to AggExpr's. Otherwise, they are included.
115  * It does not make copies of the ColumnVar
116  */
117  virtual void collect_column_var(
118  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
119  colvar_set,
120  bool include_agg) const {}
121  /*
122  * @brief rewrite_with_targetlist rewrite ColumnVar's in expression with entries in a
123  * targetlist. targetlist expressions are expected to be only Var's or AggExpr's.
124  * returns a new expression copy
125  */
126  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
127  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
128  return deep_copy();
129  };
130  /*
131  * @brief rewrite_with_child_targetlist rewrite ColumnVar's in expression with entries
132  * in a child plan's targetlist. targetlist expressions are expected to be only Var's or
133  * ColumnVar's returns a new expression copy
134  */
135  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
136  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
137  return deep_copy();
138  };
139  /*
140  * @brief rewrite_agg_to_var rewrite ColumnVar's in expression with entries in an
141  * AggPlan's targetlist. targetlist expressions are expected to be only Var's or
142  * ColumnVar's or AggExpr's All AggExpr's are written into Var's. returns a new
143  * expression copy
144  */
145  virtual std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
146  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
147  return deep_copy();
148  }
149  virtual bool operator==(const Expr& rhs) const = 0;
150  virtual std::string toString() const = 0;
151  virtual void print() const { std::cout << toString(); }
152 
153  virtual void add_unique(std::list<const Expr*>& expr_list) const;
154  /*
155  * @brief find_expr traverse Expr hierarchy and adds the node pointer to
156  * the expr_list if the function f returns true.
157  * Duplicate Expr's are not added the list.
158  * Cannot use std::set because we don't have an ordering function.
159  */
160  virtual void find_expr(bool (*f)(const Expr*),
161  std::list<const Expr*>& expr_list) const {
162  if (f(this)) {
163  add_unique(expr_list);
164  }
165  }
166  /*
167  * @brief decompress adds cast operator to decompress encoded result
168  */
169  std::shared_ptr<Analyzer::Expr> decompress();
170  /*
171  * @brief perform domain analysis on Expr and fill in domain
172  * information in domain_set. Empty domain_set means no information.
173  */
174  virtual void get_domain(DomainSet& domain_set) const { domain_set.clear(); }
175 
176  protected:
177  SQLTypeInfo type_info; // SQLTypeInfo of the return result of this expression
179 };
180 
181 using ExpressionPtr = std::shared_ptr<Analyzer::Expr>;
182 using ExpressionPtrList = std::list<ExpressionPtr>;
183 using ExpressionPtrVector = std::vector<ExpressionPtr>;
184 
185 /*
186  * @type ColumnVar
187  * @brief expression that evaluates to the value of a column in a given row from a base
188  * table. It is used in parse trees and is only used in Scan nodes in a query plan for
189  * scanning a table while Var nodes are used for all other plans.
190  */
191 class ColumnVar : public Expr {
192  public:
193  ColumnVar(const SQLTypeInfo& ti, int r, int c, int i)
194  : Expr(ti), table_id(r), column_id(c), rte_idx(i) {}
195  int get_table_id() const { return table_id; }
196  int get_column_id() const { return column_id; }
197  int get_rte_idx() const { return rte_idx; }
198  EncodingType get_compression() const { return type_info.get_compression(); }
199  int get_comp_param() const { return type_info.get_comp_param(); }
200  void check_group_by(
201  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
202  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
203  void group_predicates(std::list<const Expr*>& scan_predicates,
204  std::list<const Expr*>& join_predicates,
205  std::list<const Expr*>& const_predicates) const override;
206  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
207  rte_idx_set.insert(rte_idx);
208  }
209  static bool colvar_comp(const ColumnVar* l, const ColumnVar* r) {
210  return l->get_table_id() < r->get_table_id() ||
211  (l->get_table_id() == r->get_table_id() &&
212  l->get_column_id() < r->get_column_id());
213  }
215  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
216  colvar_set,
217  bool include_agg) const override {
218  colvar_set.insert(this);
219  }
220  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
221  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
222  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
223  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
224  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
225  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
226  bool operator==(const Expr& rhs) const override;
227  std::string toString() const override;
228 
229  protected:
230  int table_id; // the global table id
231  int column_id; // the column id
232  int rte_idx; // 0-based range table index, used for table ordering in multi-joins
233 };
234 
235 /*
236  * @type ExpressionTuple
237  * @brief A tuple of expressions on the side of an equi-join on multiple columns.
238  * Not to be used in any other context.
239  */
240 class ExpressionTuple : public Expr {
241  public:
242  ExpressionTuple(const std::vector<std::shared_ptr<Analyzer::Expr>>& tuple)
243  : Expr(SQLTypeInfo()), tuple_(tuple){};
244 
245  const std::vector<std::shared_ptr<Analyzer::Expr>>& getTuple() const { return tuple_; }
246 
247  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
248 
249  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
250 
251  bool operator==(const Expr& rhs) const override;
252  std::string toString() const override;
253 
254  private:
255  const std::vector<std::shared_ptr<Analyzer::Expr>> tuple_;
256 };
257 
258 /*
259  * @type Var
260  * @brief expression that evaluates to the value of a column in a given row generated
261  * from a query plan node. It is only used in plan nodes above Scan nodes.
262  * The row can be produced by either the inner or the outer plan in case of a join.
263  * It inherits from ColumnVar to keep track of the lineage through the plan nodes.
264  * The table_id will be set to 0 if the Var does not correspond to an original column
265  * value.
266  */
267 class Var : public ColumnVar {
268  public:
269  enum WhichRow { kINPUT_OUTER, kINPUT_INNER, kOUTPUT, kGROUPBY };
270  Var(const SQLTypeInfo& ti, int r, int c, int i, WhichRow o, int v)
271  : ColumnVar(ti, r, c, i), which_row(o), varno(v) {}
272  Var(const SQLTypeInfo& ti, WhichRow o, int v)
273  : ColumnVar(ti, 0, 0, -1), which_row(o), varno(v) {}
274  WhichRow get_which_row() const { return which_row; }
275  void set_which_row(WhichRow r) { which_row = r; }
276  int get_varno() const { return varno; }
277  void set_varno(int n) { varno = n; }
278  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
279  std::string toString() const override;
280  void check_group_by(
281  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
282  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
283  rte_idx_set.insert(-1);
284  }
285  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
286  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
287  return deep_copy();
288  }
289  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
290  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
291  return deep_copy();
292  }
293  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
294  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
295 
296  private:
297  WhichRow which_row; // indicate which row this Var should project from. It can be from
298  // the outer input plan or the inner input plan (for joins) or the
299  // output row in the current plan.
300  int varno; // the column number in the row. 1-based
301 };
302 
303 /*
304  * @type Constant
305  * @brief expression for a constant value
306  */
307 class Constant : public Expr {
308  public:
309  Constant(SQLTypes t, bool n) : Expr(t, !n), is_null(n) {
310  if (n) {
311  set_null_value();
312  } else {
313  type_info.set_notnull(true);
314  }
315  }
316  Constant(SQLTypes t, bool n, Datum v) : Expr(t, !n), is_null(n), constval(v) {
317  if (n) {
318  set_null_value();
319  } else {
320  type_info.set_notnull(true);
321  }
322  }
323  Constant(const SQLTypeInfo& ti, bool n, Datum v) : Expr(ti), is_null(n), constval(v) {
324  if (n) {
325  set_null_value();
326  } else {
327  type_info.set_notnull(true);
328  }
329  }
331  bool n,
332  const std::list<std::shared_ptr<Analyzer::Expr>>& l)
333  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
334  ~Constant() override;
335  bool get_is_null() const { return is_null; }
336  Datum get_constval() const { return constval; }
337  void set_constval(Datum d) { constval = d; }
338  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
339  return value_list;
340  }
341  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
342  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
343  bool operator==(const Expr& rhs) const override;
344  std::string toString() const override;
345 
346  private:
347  bool is_null; // constant is NULL
348  Datum constval; // the constant value
349  const std::list<std::shared_ptr<Analyzer::Expr>> value_list;
350  void cast_number(const SQLTypeInfo& new_type_info);
351  void cast_string(const SQLTypeInfo& new_type_info);
352  void cast_from_string(const SQLTypeInfo& new_type_info);
353  void cast_to_string(const SQLTypeInfo& new_type_info);
354  void do_cast(const SQLTypeInfo& new_type_info);
355  void set_null_value();
356 };
357 
358 /*
359  * @type UOper
360  * @brief represents unary operator expressions. operator types include
361  * kUMINUS, kISNULL, kEXISTS, kCAST
362  */
363 class UOper : public Expr {
364  public:
365  UOper(const SQLTypeInfo& ti, bool has_agg, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
366  : Expr(ti, has_agg), optype(o), operand(p) {}
367  UOper(SQLTypes t, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
368  : Expr(t, o == kISNULL ? true : p->get_type_info().get_notnull())
369  , optype(o)
370  , operand(p) {}
371  SQLOps get_optype() const { return optype; }
372  const Expr* get_operand() const { return operand.get(); }
373  const std::shared_ptr<Analyzer::Expr> get_own_operand() const { return operand; }
374  void check_group_by(
375  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
376  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
377  void group_predicates(std::list<const Expr*>& scan_predicates,
378  std::list<const Expr*>& join_predicates,
379  std::list<const Expr*>& const_predicates) const override;
380  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
381  operand->collect_rte_idx(rte_idx_set);
382  }
384  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
385  colvar_set,
386  bool include_agg) const override {
387  operand->collect_column_var(colvar_set, include_agg);
388  }
389  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
390  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
391  return makeExpr<UOper>(
392  type_info, contains_agg, optype, operand->rewrite_with_targetlist(tlist));
393  }
394  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
395  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
396  return makeExpr<UOper>(
397  type_info, contains_agg, optype, operand->rewrite_with_child_targetlist(tlist));
398  }
399  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
400  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
401  return makeExpr<UOper>(
402  type_info, contains_agg, optype, operand->rewrite_agg_to_var(tlist));
403  }
404  bool operator==(const Expr& rhs) const override;
405  std::string toString() const override;
406  void find_expr(bool (*f)(const Expr*),
407  std::list<const Expr*>& expr_list) const override;
408  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
409 
410  private:
411  SQLOps optype; // operator type, e.g., kUMINUS, kISNULL, kEXISTS
412  std::shared_ptr<Analyzer::Expr> operand; // operand expression
413 };
414 
415 /*
416  * @type BinOper
417  * @brief represents binary operator expressions. it includes all
418  * comparison, arithmetic and boolean binary operators. it handles ANY/ALL qualifiers
419  * in case the right_operand is a subquery.
420  */
421 class BinOper : public Expr {
422  public:
423  BinOper(const SQLTypeInfo& ti,
424  bool has_agg,
425  SQLOps o,
426  SQLQualifier q,
427  std::shared_ptr<Analyzer::Expr> l,
428  std::shared_ptr<Analyzer::Expr> r)
429  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
431  SQLOps o,
432  SQLQualifier q,
433  std::shared_ptr<Analyzer::Expr> l,
434  std::shared_ptr<Analyzer::Expr> r)
435  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
436  , optype(o)
437  , qualifier(q)
438  , left_operand(l)
439  , right_operand(r) {}
440  SQLOps get_optype() const { return optype; }
441  bool is_overlaps_oper() const { return optype == kOVERLAPS; }
442  SQLQualifier get_qualifier() const { return qualifier; }
443  const Expr* get_left_operand() const { return left_operand.get(); }
444  const Expr* get_right_operand() const { return right_operand.get(); }
445  const std::shared_ptr<Analyzer::Expr> get_own_left_operand() const {
446  return left_operand;
447  }
448  const std::shared_ptr<Analyzer::Expr> get_own_right_operand() const {
449  return right_operand;
450  }
451  static SQLTypeInfo analyze_type_info(SQLOps op,
452  const SQLTypeInfo& left_type,
453  const SQLTypeInfo& right_type,
454  SQLTypeInfo* new_left_type,
455  SQLTypeInfo* new_right_type);
456  static SQLTypeInfo common_numeric_type(const SQLTypeInfo& type1,
457  const SQLTypeInfo& type2);
458  static SQLTypeInfo common_string_type(const SQLTypeInfo& type1,
459  const SQLTypeInfo& type2);
460  void check_group_by(
461  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
462  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
463  std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const override;
464  void group_predicates(std::list<const Expr*>& scan_predicates,
465  std::list<const Expr*>& join_predicates,
466  std::list<const Expr*>& const_predicates) const override;
467  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
468  left_operand->collect_rte_idx(rte_idx_set);
469  right_operand->collect_rte_idx(rte_idx_set);
470  }
472  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
473  colvar_set,
474  bool include_agg) const override {
475  left_operand->collect_column_var(colvar_set, include_agg);
476  right_operand->collect_column_var(colvar_set, include_agg);
477  }
478  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
479  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
480  return makeExpr<BinOper>(type_info,
481  contains_agg,
482  optype,
483  qualifier,
484  left_operand->rewrite_with_targetlist(tlist),
485  right_operand->rewrite_with_targetlist(tlist));
486  }
487  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
488  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
489  return makeExpr<BinOper>(type_info,
490  contains_agg,
491  optype,
492  qualifier,
493  left_operand->rewrite_with_child_targetlist(tlist),
494  right_operand->rewrite_with_child_targetlist(tlist));
495  }
496  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
497  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
498  return makeExpr<BinOper>(type_info,
499  contains_agg,
500  optype,
501  qualifier,
502  left_operand->rewrite_agg_to_var(tlist),
503  right_operand->rewrite_agg_to_var(tlist));
504  }
505  bool operator==(const Expr& rhs) const override;
506  std::string toString() const override;
507  void find_expr(bool (*f)(const Expr*),
508  std::list<const Expr*>& expr_list) const override;
509  static bool simple_predicate_has_simple_cast(
510  const std::shared_ptr<Analyzer::Expr> cast_operand,
511  const std::shared_ptr<Analyzer::Expr> const_operand);
512 
513  private:
514  SQLOps optype; // operator type, e.g., kLT, kAND, kPLUS, etc.
515  SQLQualifier qualifier; // qualifier kANY, kALL or kONE. Only relevant with
516  // right_operand is Subquery
517  std::shared_ptr<Analyzer::Expr> left_operand; // the left operand expression
518  std::shared_ptr<Analyzer::Expr> right_operand; // the right operand expression
519 };
520 
521 class Query;
522 
523 /*
524  * @type Subquery
525  * @brief subquery expression. Note that the type of the expression is the type of the
526  * TargetEntry in the subquery instead of the set.
527  */
528 class Subquery : public Expr {
529  public:
530  Subquery(const SQLTypeInfo& ti, Query* q)
531  : Expr(ti), parsetree(q) /*, plan(nullptr)*/ {}
532  ~Subquery() override;
533  const Query* get_parsetree() const { return parsetree; }
534  // const Plan *get_plan() const { return plan; }
535  // void set_plan(Plan *p) { plan = p; } // subquery plan is set by the optimizer
536  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
537  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
538  void group_predicates(std::list<const Expr*>& scan_predicates,
539  std::list<const Expr*>& join_predicates,
540  std::list<const Expr*>& const_predicates) const override {
541  CHECK(false);
542  }
543  void collect_rte_idx(std::set<int>& rte_idx_set) const override { CHECK(false); }
545  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
546  colvar_set,
547  bool include_agg) const override {
548  CHECK(false);
549  }
550  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
551  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
552  abort();
553  }
554  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
555  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
556  abort();
557  }
558  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
559  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
560  abort();
561  }
562  bool operator==(const Expr& rhs) const override {
563  CHECK(false);
564  return false;
565  }
566  std::string toString() const override;
567  void find_expr(bool (*f)(const Expr*),
568  std::list<const Expr*>& expr_list) const override {
569  CHECK(false);
570  }
571 
572  private:
573  Query* parsetree; // parse tree of the subquery
574 };
575 
576 /*
577  * @type InValues
578  * @brief represents predicate expr IN (v1, v2, ...)
579  * v1, v2, ... are can be either Constant or Parameter.
580  */
581 class InValues : public Expr {
582  public:
583  InValues(std::shared_ptr<Analyzer::Expr> a,
584  const std::list<std::shared_ptr<Analyzer::Expr>>& l);
585  const Expr* get_arg() const { return arg.get(); }
586  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
587  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
588  return value_list;
589  }
590  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
591  void group_predicates(std::list<const Expr*>& scan_predicates,
592  std::list<const Expr*>& join_predicates,
593  std::list<const Expr*>& const_predicates) const override;
594  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
595  arg->collect_rte_idx(rte_idx_set);
596  }
598  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
599  colvar_set,
600  bool include_agg) const override {
601  arg->collect_column_var(colvar_set, include_agg);
602  }
603  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
604  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
605  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
606  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
607  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
608  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
609  bool operator==(const Expr& rhs) const override;
610  std::string toString() const override;
611  void find_expr(bool (*f)(const Expr*),
612  std::list<const Expr*>& expr_list) const override;
613 
614  private:
615  std::shared_ptr<Analyzer::Expr> arg; // the argument left of IN
616  const std::list<std::shared_ptr<Analyzer::Expr>>
617  value_list; // the list of values right of IN
618 };
619 
620 /*
621  * @type InIntegerSet
622  * @brief represents predicate expr IN (v1, v2, ...) for the case where the right
623  * hand side is a list of integers or dictionary-encoded strings generated
624  * by a IN subquery. Avoids the overhead of storing a list of shared pointers
625  * to Constant objects, making it more suitable for IN sub-queries usage.
626  * v1, v2, ... are integers
627  */
628 class InIntegerSet : public Expr {
629  public:
630  InIntegerSet(const std::shared_ptr<const Analyzer::Expr> a,
631  const std::vector<int64_t>& values,
632  const bool not_null);
633 
634  const Expr* get_arg() const { return arg.get(); }
635 
636  const std::vector<int64_t>& get_value_list() const { return value_list; }
637 
638  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
639 
640  bool operator==(const Expr& rhs) const override;
641  std::string toString() const override;
642 
643  private:
644  const std::shared_ptr<const Analyzer::Expr> arg; // the argument left of IN
645  const std::vector<int64_t> value_list; // the list of values right of IN
646 };
647 
648 /*
649  * @type CharLengthExpr
650  * @brief expression for the CHAR_LENGTH expression.
651  * arg must evaluate to char, varchar or text.
652  */
653 class CharLengthExpr : public Expr {
654  public:
655  CharLengthExpr(std::shared_ptr<Analyzer::Expr> a, bool e)
656  : Expr(kINT, a->get_type_info().get_notnull()), arg(a), calc_encoded_length(e) {}
657  const Expr* get_arg() const { return arg.get(); }
658  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
659  bool get_calc_encoded_length() const { return calc_encoded_length; }
660  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
661  void group_predicates(std::list<const Expr*>& scan_predicates,
662  std::list<const Expr*>& join_predicates,
663  std::list<const Expr*>& const_predicates) const override;
664  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
665  arg->collect_rte_idx(rte_idx_set);
666  }
668  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
669  colvar_set,
670  bool include_agg) const override {
671  arg->collect_column_var(colvar_set, include_agg);
672  }
673  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
674  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
675  return makeExpr<CharLengthExpr>(arg->rewrite_with_targetlist(tlist),
676  calc_encoded_length);
677  }
678  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
679  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
680  return makeExpr<CharLengthExpr>(arg->rewrite_with_child_targetlist(tlist),
681  calc_encoded_length);
682  }
683  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
684  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
685  return makeExpr<CharLengthExpr>(arg->rewrite_agg_to_var(tlist), calc_encoded_length);
686  }
687  bool operator==(const Expr& rhs) const override;
688  std::string toString() const override;
689  void find_expr(bool (*f)(const Expr*),
690  std::list<const Expr*>& expr_list) const override;
691 
692  private:
693  std::shared_ptr<Analyzer::Expr> arg;
695 };
696 
697 /*
698  * @type KeyForStringExpr
699  * @brief expression for the KEY_FOR_STRING expression.
700  * arg must be a dict encoded column, not str literal.
701  */
702 class KeyForStringExpr : public Expr {
703  public:
704  KeyForStringExpr(std::shared_ptr<Analyzer::Expr> a)
705  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
706  const Expr* get_arg() const { return arg.get(); }
707  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
708  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
709  void group_predicates(std::list<const Expr*>& scan_predicates,
710  std::list<const Expr*>& join_predicates,
711  std::list<const Expr*>& const_predicates) const override;
712  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
713  arg->collect_rte_idx(rte_idx_set);
714  }
716  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
717  colvar_set,
718  bool include_agg) const override {
719  arg->collect_column_var(colvar_set, include_agg);
720  }
721  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
722  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
723  return makeExpr<KeyForStringExpr>(arg->rewrite_with_targetlist(tlist));
724  }
725  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
726  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
727  return makeExpr<KeyForStringExpr>(arg->rewrite_with_child_targetlist(tlist));
728  }
729  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
730  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
731  return makeExpr<KeyForStringExpr>(arg->rewrite_agg_to_var(tlist));
732  }
733  bool operator==(const Expr& rhs) const override;
734  std::string toString() const override;
735  void find_expr(bool (*f)(const Expr*),
736  std::list<const Expr*>& expr_list) const override;
737 
738  private:
739  std::shared_ptr<Analyzer::Expr> arg;
740 };
741 
742 /*
743  * @type SampleRatioExpr
744  * @brief expression for the SAMPLE_RATIO expression. Argument range is expected to be
745  * between 0 and 1.
746  */
747 class SampleRatioExpr : public Expr {
748  public:
749  SampleRatioExpr(std::shared_ptr<Analyzer::Expr> a)
750  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a) {}
751  const Expr* get_arg() const { return arg.get(); }
752  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
753  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
754  void group_predicates(std::list<const Expr*>& scan_predicates,
755  std::list<const Expr*>& join_predicates,
756  std::list<const Expr*>& const_predicates) const override;
757  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
758  arg->collect_rte_idx(rte_idx_set);
759  }
761  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
762  colvar_set,
763  bool include_agg) const override {
764  arg->collect_column_var(colvar_set, include_agg);
765  }
766  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
767  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
768  return makeExpr<SampleRatioExpr>(arg->rewrite_with_targetlist(tlist));
769  }
770  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
771  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
772  return makeExpr<SampleRatioExpr>(arg->rewrite_with_child_targetlist(tlist));
773  }
774  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
775  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
776  return makeExpr<SampleRatioExpr>(arg->rewrite_agg_to_var(tlist));
777  }
778  bool operator==(const Expr& rhs) const override;
779  std::string toString() const override;
780  void find_expr(bool (*f)(const Expr*),
781  std::list<const Expr*>& expr_list) const override;
782 
783  private:
784  std::shared_ptr<Analyzer::Expr> arg;
785 };
786 
792 class LowerExpr : public Expr {
793  public:
794  LowerExpr(std::shared_ptr<Analyzer::Expr> arg) : Expr(arg->get_type_info()), arg(arg) {}
795 
796  const Expr* get_arg() const { return arg.get(); }
797 
798  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
799 
800  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
801  arg->collect_rte_idx(rte_idx_set);
802  }
803 
805  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
806  colvar_set,
807  bool include_agg) const override {
808  arg->collect_column_var(colvar_set, include_agg);
809  }
810 
811  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
812  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
813  return makeExpr<LowerExpr>(arg->rewrite_with_targetlist(tlist));
814  }
815 
816  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
817  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
818  return makeExpr<LowerExpr>(arg->rewrite_with_child_targetlist(tlist));
819  }
820 
821  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
822  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
823  return makeExpr<LowerExpr>(arg->rewrite_agg_to_var(tlist));
824  }
825 
826  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
827 
828  void group_predicates(std::list<const Expr*>& scan_predicates,
829  std::list<const Expr*>& join_predicates,
830  std::list<const Expr*>& const_predicates) const override;
831 
832  bool operator==(const Expr& rhs) const override;
833 
834  std::string toString() const override;
835 
836  void find_expr(bool (*f)(const Expr*),
837  std::list<const Expr*>& expr_list) const override;
838 
839  private:
840  std::shared_ptr<Analyzer::Expr> arg;
841 };
842 
843 /*
844  * @type CardinalityExpr
845  * @brief expression for the CARDINALITY expression.
846  * arg must evaluate to array (or multiset when supported).
847  */
848 class CardinalityExpr : public Expr {
849  public:
850  CardinalityExpr(std::shared_ptr<Analyzer::Expr> a)
851  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
852  const Expr* get_arg() const { return arg.get(); }
853  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
854  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
855  void group_predicates(std::list<const Expr*>& scan_predicates,
856  std::list<const Expr*>& join_predicates,
857  std::list<const Expr*>& const_predicates) const override;
858  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
859  arg->collect_rte_idx(rte_idx_set);
860  }
862  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
863  colvar_set,
864  bool include_agg) const override {
865  arg->collect_column_var(colvar_set, include_agg);
866  }
867  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
868  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
869  return makeExpr<CardinalityExpr>(arg->rewrite_with_targetlist(tlist));
870  }
871  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
872  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
873  return makeExpr<CardinalityExpr>(arg->rewrite_with_child_targetlist(tlist));
874  }
875  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
876  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
877  return makeExpr<CardinalityExpr>(arg->rewrite_agg_to_var(tlist));
878  }
879  bool operator==(const Expr& rhs) const override;
880  std::string toString() const override;
881  void find_expr(bool (*f)(const Expr*),
882  std::list<const Expr*>& expr_list) const override;
883 
884  private:
885  std::shared_ptr<Analyzer::Expr> arg;
886 };
887 
888 /*
889  * @type LikeExpr
890  * @brief expression for the LIKE predicate.
891  * arg must evaluate to char, varchar or text.
892  */
893 class LikeExpr : public Expr {
894  public:
895  LikeExpr(std::shared_ptr<Analyzer::Expr> a,
896  std::shared_ptr<Analyzer::Expr> l,
897  std::shared_ptr<Analyzer::Expr> e,
898  bool i,
899  bool s)
900  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
901  , arg(a)
902  , like_expr(l)
903  , escape_expr(e)
904  , is_ilike(i)
905  , is_simple(s) {}
906  const Expr* get_arg() const { return arg.get(); }
907  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
908  const Expr* get_like_expr() const { return like_expr.get(); }
909  const Expr* get_escape_expr() const { return escape_expr.get(); }
910  bool get_is_ilike() const { return is_ilike; }
911  bool get_is_simple() const { return is_simple; }
912  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
913  void group_predicates(std::list<const Expr*>& scan_predicates,
914  std::list<const Expr*>& join_predicates,
915  std::list<const Expr*>& const_predicates) const override;
916  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
917  arg->collect_rte_idx(rte_idx_set);
918  }
920  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
921  colvar_set,
922  bool include_agg) const override {
923  arg->collect_column_var(colvar_set, include_agg);
924  }
925  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
926  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
927  return makeExpr<LikeExpr>(arg->rewrite_with_targetlist(tlist),
928  like_expr->deep_copy(),
929  escape_expr ? escape_expr->deep_copy() : nullptr,
930  is_ilike,
931  is_simple);
932  }
933  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
934  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
935  return makeExpr<LikeExpr>(arg->rewrite_with_child_targetlist(tlist),
936  like_expr->deep_copy(),
937  escape_expr ? escape_expr->deep_copy() : nullptr,
938  is_ilike,
939  is_simple);
940  }
941  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
942  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
943  return makeExpr<LikeExpr>(arg->rewrite_agg_to_var(tlist),
944  like_expr->deep_copy(),
945  escape_expr ? escape_expr->deep_copy() : nullptr,
946  is_ilike,
947  is_simple);
948  }
949  bool operator==(const Expr& rhs) const override;
950  std::string toString() const override;
951  void find_expr(bool (*f)(const Expr*),
952  std::list<const Expr*>& expr_list) const override;
953 
954  private:
955  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of LIKE
956  std::shared_ptr<Analyzer::Expr> like_expr; // expression that evaluates to like string
957  std::shared_ptr<Analyzer::Expr>
958  escape_expr; // expression that evaluates to escape string, can be nullptr
959  bool is_ilike; // is this ILIKE?
960  bool is_simple; // is this simple, meaning we can use fast path search (fits '%str%'
961  // pattern with no inner '%','_','[',']'
962 };
963 
964 /*
965  * @type RegexpExpr
966  * @brief expression for REGEXP.
967  * arg must evaluate to char, varchar or text.
968  */
969 class RegexpExpr : public Expr {
970  public:
971  RegexpExpr(std::shared_ptr<Analyzer::Expr> a,
972  std::shared_ptr<Analyzer::Expr> p,
973  std::shared_ptr<Analyzer::Expr> e)
974  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
975  , arg(a)
976  , pattern_expr(p)
977  , escape_expr(e) {}
978  const Expr* get_arg() const { return arg.get(); }
979  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
980  const Expr* get_pattern_expr() const { return pattern_expr.get(); }
981  const Expr* get_escape_expr() const { return escape_expr.get(); }
982  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
983  void group_predicates(std::list<const Expr*>& scan_predicates,
984  std::list<const Expr*>& join_predicates,
985  std::list<const Expr*>& const_predicates) const override;
986  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
987  arg->collect_rte_idx(rte_idx_set);
988  }
990  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
991  colvar_set,
992  bool include_agg) const override {
993  arg->collect_column_var(colvar_set, include_agg);
994  }
995  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
996  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
997  return makeExpr<RegexpExpr>(arg->rewrite_with_targetlist(tlist),
998  pattern_expr->deep_copy(),
999  escape_expr ? escape_expr->deep_copy() : nullptr);
1000  }
1001  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1002  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1003  return makeExpr<RegexpExpr>(arg->rewrite_with_child_targetlist(tlist),
1004  pattern_expr->deep_copy(),
1005  escape_expr ? escape_expr->deep_copy() : nullptr);
1006  }
1007  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1008  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1009  return makeExpr<RegexpExpr>(arg->rewrite_agg_to_var(tlist),
1010  pattern_expr->deep_copy(),
1011  escape_expr ? escape_expr->deep_copy() : nullptr);
1012  }
1013  bool operator==(const Expr& rhs) const override;
1014  std::string toString() const override;
1015  void find_expr(bool (*f)(const Expr*),
1016  std::list<const Expr*>& expr_list) const override;
1017 
1018  private:
1019  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of REGEXP
1020  std::shared_ptr<Analyzer::Expr>
1021  pattern_expr; // expression that evaluates to pattern string
1022  std::shared_ptr<Analyzer::Expr>
1023  escape_expr; // expression that evaluates to escape string, can be nullptr
1024 };
1025 
1026 /*
1027  * @type LikelihoodExpr
1028  * @brief expression for LIKELY and UNLIKELY boolean identity functions.
1029  */
1030 class LikelihoodExpr : public Expr {
1031  public:
1032  LikelihoodExpr(std::shared_ptr<Analyzer::Expr> a, float l = 0.5)
1033  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a), likelihood(l) {}
1034  const Expr* get_arg() const { return arg.get(); }
1035  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1036  float get_likelihood() const { return likelihood; }
1037  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1038  void group_predicates(std::list<const Expr*>& scan_predicates,
1039  std::list<const Expr*>& join_predicates,
1040  std::list<const Expr*>& const_predicates) const override;
1041  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1042  arg->collect_rte_idx(rte_idx_set);
1043  }
1045  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1046  colvar_set,
1047  bool include_agg) const override {
1048  arg->collect_column_var(colvar_set, include_agg);
1049  }
1050  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1051  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1052  return makeExpr<LikelihoodExpr>(arg->rewrite_with_targetlist(tlist), likelihood);
1053  }
1054  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1055  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1056  return makeExpr<LikelihoodExpr>(arg->rewrite_with_child_targetlist(tlist),
1057  likelihood);
1058  }
1059  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1060  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1061  return makeExpr<LikelihoodExpr>(arg->rewrite_agg_to_var(tlist), likelihood);
1062  }
1063  bool operator==(const Expr& rhs) const override;
1064  std::string toString() const override;
1065  void find_expr(bool (*f)(const Expr*),
1066  std::list<const Expr*>& expr_list) const override;
1067 
1068  private:
1069  std::shared_ptr<Analyzer::Expr> arg; // the argument to LIKELY, UNLIKELY
1070  float likelihood;
1071 };
1072 
1073 /*
1074  * @type AggExpr
1075  * @brief expression for builtin SQL aggregates.
1076  */
1077 class AggExpr : public Expr {
1078  public:
1080  SQLAgg a,
1081  std::shared_ptr<Analyzer::Expr> g,
1082  bool d,
1083  std::shared_ptr<Analyzer::Constant> e)
1084  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), error_rate(e) {}
1086  SQLAgg a,
1087  Expr* g,
1088  bool d,
1089  std::shared_ptr<Analyzer::Constant> e,
1090  int idx)
1091  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1092  , aggtype(a)
1093  , arg(g)
1094  , is_distinct(d)
1095  , error_rate(e) {}
1096  SQLAgg get_aggtype() const { return aggtype; }
1097  Expr* get_arg() const { return arg.get(); }
1098  std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1099  bool get_is_distinct() const { return is_distinct; }
1100  std::shared_ptr<Analyzer::Constant> get_error_rate() const { return error_rate; }
1101  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1102  void group_predicates(std::list<const Expr*>& scan_predicates,
1103  std::list<const Expr*>& join_predicates,
1104  std::list<const Expr*>& const_predicates) const override;
1105  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1106  if (arg) {
1107  arg->collect_rte_idx(rte_idx_set);
1108  }
1109  };
1111  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1112  colvar_set,
1113  bool include_agg) const override {
1114  if (include_agg && arg != nullptr) {
1115  arg->collect_column_var(colvar_set, include_agg);
1116  }
1117  }
1118  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1119  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1120  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1121  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1122  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1123  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1124  bool operator==(const Expr& rhs) const override;
1125  std::string toString() const override;
1126  void find_expr(bool (*f)(const Expr*),
1127  std::list<const Expr*>& expr_list) const override;
1128 
1129  private:
1130  SQLAgg aggtype; // aggregate type: kAVG, kMIN, kMAX, kSUM, kCOUNT
1131  std::shared_ptr<Analyzer::Expr> arg; // argument to aggregate
1132  bool is_distinct; // true only if it is for COUNT(DISTINCT x)
1133  std::shared_ptr<Analyzer::Constant> error_rate; // error rate of kAPPROX_COUNT_DISTINCT
1134 };
1135 
1136 /*
1137  * @type CaseExpr
1138  * @brief the CASE-WHEN-THEN-ELSE expression
1139  */
1140 class CaseExpr : public Expr {
1141  public:
1143  bool has_agg,
1144  const std::list<std::pair<std::shared_ptr<Analyzer::Expr>,
1145  std::shared_ptr<Analyzer::Expr>>>& w,
1146  std::shared_ptr<Analyzer::Expr> e)
1147  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
1148  const std::list<
1149  std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>&
1151  return expr_pair_list;
1152  }
1153  const Expr* get_else_expr() const { return else_expr.get(); }
1154  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1155  void check_group_by(
1156  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1157  void group_predicates(std::list<const Expr*>& scan_predicates,
1158  std::list<const Expr*>& join_predicates,
1159  std::list<const Expr*>& const_predicates) const override;
1160  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1161  void collect_column_var(
1162  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1163  colvar_set,
1164  bool include_agg) const override;
1165  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1166  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1167  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1168  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1169  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1170  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1171  bool operator==(const Expr& rhs) const override;
1172  std::string toString() const override;
1173  void find_expr(bool (*f)(const Expr*),
1174  std::list<const Expr*>& expr_list) const override;
1175  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
1176  void get_domain(DomainSet& domain_set) const override;
1177 
1178  private:
1179  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1180  expr_pair_list; // a pair of expressions for each WHEN expr1 THEN expr2. expr1
1181  // must be of boolean type. all expr2's must be of compatible
1182  // types and will be promoted to the common type.
1183  std::shared_ptr<Analyzer::Expr> else_expr; // expression for ELSE. nullptr if omitted.
1184 };
1185 
1186 /*
1187  * @type ExtractExpr
1188  * @brief the EXTRACT expression
1189  */
1190 class ExtractExpr : public Expr {
1191  public:
1193  bool has_agg,
1194  ExtractField f,
1195  std::shared_ptr<Analyzer::Expr> e)
1196  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1197  ExtractField get_field() const { return field_; }
1198  const Expr* get_from_expr() const { return from_expr_.get(); }
1199  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1200  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1201  void check_group_by(
1202  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1203  void group_predicates(std::list<const Expr*>& scan_predicates,
1204  std::list<const Expr*>& join_predicates,
1205  std::list<const Expr*>& const_predicates) const override;
1206  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1207  void collect_column_var(
1208  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1209  colvar_set,
1210  bool include_agg) const override;
1211  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1212  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1213  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1214  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1215  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1216  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1217  bool operator==(const Expr& rhs) const override;
1218  std::string toString() const override;
1219  void find_expr(bool (*f)(const Expr*),
1220  std::list<const Expr*>& expr_list) const override;
1221 
1222  private:
1224  std::shared_ptr<Analyzer::Expr> from_expr_;
1225 };
1226 
1227 /*
1228  * @type DateaddExpr
1229  * @brief the DATEADD expression
1230  */
1231 class DateaddExpr : public Expr {
1232  public:
1234  const DateaddField f,
1235  const std::shared_ptr<Analyzer::Expr> number,
1236  const std::shared_ptr<Analyzer::Expr> datetime)
1237  : Expr(ti, false), field_(f), number_(number), datetime_(datetime) {}
1238  DateaddField get_field() const { return field_; }
1239  const Expr* get_number_expr() const { return number_.get(); }
1240  const Expr* get_datetime_expr() const { return datetime_.get(); }
1241  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1242  void check_group_by(
1243  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1244  void group_predicates(std::list<const Expr*>& scan_predicates,
1245  std::list<const Expr*>& join_predicates,
1246  std::list<const Expr*>& const_predicates) const override;
1247  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1248  void collect_column_var(
1249  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1250  colvar_set,
1251  bool include_agg) const override;
1252  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1253  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1254  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1255  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1256  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1257  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1258  bool operator==(const Expr& rhs) const override;
1259  std::string toString() const override;
1260  void find_expr(bool (*f)(const Expr*),
1261  std::list<const Expr*>& expr_list) const override;
1262 
1263  private:
1265  const std::shared_ptr<Analyzer::Expr> number_;
1266  const std::shared_ptr<Analyzer::Expr> datetime_;
1267 };
1268 
1269 /*
1270  * @type DatediffExpr
1271  * @brief the DATEDIFF expression
1272  */
1273 class DatediffExpr : public Expr {
1274  public:
1276  const DatetruncField f,
1277  const std::shared_ptr<Analyzer::Expr> start,
1278  const std::shared_ptr<Analyzer::Expr> end)
1279  : Expr(ti, false), field_(f), start_(start), end_(end) {}
1280  DatetruncField get_field() const { return field_; }
1281  const Expr* get_start_expr() const { return start_.get(); }
1282  const Expr* get_end_expr() const { return end_.get(); }
1283  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1284  void check_group_by(
1285  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1286  void group_predicates(std::list<const Expr*>& scan_predicates,
1287  std::list<const Expr*>& join_predicates,
1288  std::list<const Expr*>& const_predicates) const override;
1289  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1290  void collect_column_var(
1291  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1292  colvar_set,
1293  bool include_agg) const override;
1294  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1295  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1296  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1297  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1298  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1299  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1300  bool operator==(const Expr& rhs) const override;
1301  std::string toString() const override;
1302  void find_expr(bool (*f)(const Expr*),
1303  std::list<const Expr*>& expr_list) const override;
1304 
1305  private:
1307  const std::shared_ptr<Analyzer::Expr> start_;
1308  const std::shared_ptr<Analyzer::Expr> end_;
1309 };
1310 
1311 /*
1312  * @type DatetruncExpr
1313  * @brief the DATE_TRUNC expression
1314  */
1315 class DatetruncExpr : public Expr {
1316  public:
1318  bool has_agg,
1319  DatetruncField f,
1320  std::shared_ptr<Analyzer::Expr> e)
1321  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1322  DatetruncField get_field() const { return field_; }
1323  const Expr* get_from_expr() const { return from_expr_.get(); }
1324  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1325  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1326  void check_group_by(
1327  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1328  void group_predicates(std::list<const Expr*>& scan_predicates,
1329  std::list<const Expr*>& join_predicates,
1330  std::list<const Expr*>& const_predicates) const override;
1331  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1332  void collect_column_var(
1333  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1334  colvar_set,
1335  bool include_agg) const override;
1336  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1337  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1338  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1339  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1340  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1341  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1342  bool operator==(const Expr& rhs) const override;
1343  std::string toString() const override;
1344  void find_expr(bool (*f)(const Expr*),
1345  std::list<const Expr*>& expr_list) const override;
1346 
1347  private:
1349  std::shared_ptr<Analyzer::Expr> from_expr_;
1350 };
1351 
1352 class FunctionOper : public Expr {
1353  public:
1355  const std::string& name,
1356  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1357  : Expr(ti, false), name_(name), args_(args) {}
1358 
1359  std::string getName() const { return name_; }
1360 
1361  size_t getArity() const { return args_.size(); }
1362 
1363  const Analyzer::Expr* getArg(const size_t i) const {
1364  CHECK_LT(i, args_.size());
1365  return args_[i].get();
1366  }
1367 
1368  std::shared_ptr<Analyzer::Expr> getOwnArg(const size_t i) const {
1369  CHECK_LT(i, args_.size());
1370  return args_[i];
1371  }
1372 
1373  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1374 
1375  bool operator==(const Expr& rhs) const override;
1376  std::string toString() const override;
1377 
1378  private:
1379  const std::string name_;
1380  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
1381 };
1382 
1384  public:
1386  const SQLTypeInfo& ti,
1387  const std::string& name,
1388  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1389  : FunctionOper(ti, name, args) {}
1390 
1391  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1392 
1393  bool operator==(const Expr& rhs) const override;
1394 };
1395 
1396 /*
1397  * @type OffsetInFragment
1398  * @brief The offset of a row in the current fragment. To be used by updates.
1399  */
1400 class OffsetInFragment : public Expr {
1401  public:
1403 
1404  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1405 
1406  bool operator==(const Expr& rhs) const override;
1407  std::string toString() const override;
1408 };
1409 
1410 /*
1411  * @type OrderEntry
1412  * @brief represents an entry in ORDER BY clause.
1413  */
1414 struct OrderEntry {
1415  OrderEntry(int t, bool d, bool nf) : tle_no(t), is_desc(d), nulls_first(nf){};
1417  std::string toString() const;
1418  void print() const { std::cout << toString(); }
1419  int tle_no; /* targetlist entry number: 1-based */
1420  bool is_desc; /* true if order is DESC */
1421  bool nulls_first; /* true if nulls are ordered first. otherwise last. */
1422 };
1423 
1424 /*
1425  * @type WindowFunction
1426  * @brief A window function.
1427  */
1428 class WindowFunction : public Expr {
1429  public:
1431  const SqlWindowFunctionKind kind,
1432  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1433  const std::vector<std::shared_ptr<Analyzer::Expr>>& partition_keys,
1434  const std::vector<std::shared_ptr<Analyzer::Expr>>& order_keys,
1435  const std::vector<OrderEntry>& collation)
1436  : Expr(ti)
1437  , kind_(kind)
1438  , args_(args)
1439  , partition_keys_(partition_keys)
1440  , order_keys_(order_keys)
1441  , collation_(collation){};
1442 
1443  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1444 
1445  bool operator==(const Expr& rhs) const override;
1446  std::string toString() const override;
1447 
1448  SqlWindowFunctionKind getKind() const { return kind_; }
1449 
1450  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs() const { return args_; }
1451 
1452  const std::vector<std::shared_ptr<Analyzer::Expr>>& getPartitionKeys() const {
1453  return partition_keys_;
1454  }
1455 
1456  const std::vector<std::shared_ptr<Analyzer::Expr>>& getOrderKeys() const {
1457  return order_keys_;
1458  }
1459 
1460  const std::vector<OrderEntry>& getCollation() const { return collation_; }
1461 
1462  private:
1464  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
1465  const std::vector<std::shared_ptr<Analyzer::Expr>> partition_keys_;
1466  const std::vector<std::shared_ptr<Analyzer::Expr>> order_keys_;
1467  const std::vector<OrderEntry> collation_;
1468 };
1469 
1470 /*
1471  * @type ArrayExpr
1472  * @brief Corresponds to ARRAY[] statements in SQL
1473  */
1474 
1475 class ArrayExpr : public Expr {
1476  public:
1477  ArrayExpr(SQLTypeInfo const& array_ti,
1478  ExpressionPtrVector const& array_exprs,
1479  bool is_null = false,
1480  bool local_alloc = false)
1481  : Expr(array_ti)
1482  , contained_expressions_(array_exprs)
1483  , local_alloc_(local_alloc)
1484  , is_null_(is_null) {}
1485 
1486  Analyzer::ExpressionPtr deep_copy() const override;
1487  std::string toString() const override;
1488  bool operator==(Expr const& rhs) const override;
1489  size_t getElementCount() const { return contained_expressions_.size(); }
1490  bool isLocalAlloc() const { return local_alloc_; }
1491  bool isNull() const { return is_null_; }
1492 
1493  const Analyzer::Expr* getElement(const size_t i) const {
1494  CHECK_LT(i, contained_expressions_.size());
1495  return contained_expressions_[i].get();
1496  }
1497 
1498  private:
1501  bool is_null_; // constant is NULL
1502 };
1503 
1504 /*
1505  * @type GeoUOper
1506  * @brief Geo unary operation
1507  */
1508 class GeoUOper : public Expr {
1509  public:
1511  const SQLTypeInfo& ti,
1512  const SQLTypeInfo& ti0,
1513  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1514  : Expr(ti), op_(op), ti0_(ti0), args0_(args){};
1515 
1516  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1517 
1518  bool operator==(const Expr& rhs) const override;
1519  std::string toString() const override;
1520 
1521  Geo_namespace::GeoBase::GeoOp getOp() const { return op_; }
1522  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
1523  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
1524 
1525  private:
1527  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
1528  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
1529 };
1530 
1531 /*
1532  * @type GeoBinOper
1533  * @brief Geo binary operation
1534  */
1535 class GeoBinOper : public Expr {
1536  public:
1538  const SQLTypeInfo& ti,
1539  const SQLTypeInfo& ti0,
1540  const SQLTypeInfo& ti1,
1541  const std::vector<std::shared_ptr<Analyzer::Expr>>& args0,
1542  const std::vector<std::shared_ptr<Analyzer::Expr>>& args1)
1543  : Expr(ti), op_(op), ti0_(ti0), ti1_(ti1), args0_(args0), args1_(args1){};
1544 
1545  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1546 
1547  bool operator==(const Expr& rhs) const override;
1548  std::string toString() const override;
1549 
1550  Geo_namespace::GeoBase::GeoOp getOp() const { return op_; }
1551  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
1552  const SQLTypeInfo getTypeInfo1() const { return ti1_; }
1553  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
1554  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs1() const { return args1_; }
1555 
1556  private:
1558  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
1559  SQLTypeInfo ti1_; // Type of geo input 1
1560  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
1561  const std::vector<std::shared_ptr<Analyzer::Expr>> args1_;
1562 };
1563 
1564 /*
1565  * @type TargetEntry
1566  * @brief Target list defines a relational projection. It is a list of TargetEntry's.
1567  */
1569  public:
1570  TargetEntry(const std::string& n, std::shared_ptr<Analyzer::Expr> e, bool u)
1571  : resname(n), expr(e), unnest(u) {}
1572  virtual ~TargetEntry() {}
1573  const std::string& get_resname() const { return resname; }
1574  void set_resname(const std::string& name) { resname = name; }
1575  Expr* get_expr() const { return expr.get(); }
1576  std::shared_ptr<Expr> get_own_expr() const { return expr; }
1577  void set_expr(std::shared_ptr<Analyzer::Expr> e) { expr = e; }
1578  bool get_unnest() const { return unnest; }
1579  std::string toString() const;
1580  void print() const { std::cout << toString(); }
1581 
1582  private:
1583  std::string resname; // alias name, e.g., SELECT salary + bonus AS compensation,
1584  std::shared_ptr<Analyzer::Expr> expr; // expression to evaluate for the value
1585  bool unnest; // unnest a collection type
1586 };
1587 
1588 class RangeTableEntry;
1589 
1590 /*
1591  * @type Query
1592  * @brief parse tree for a query
1593  */
1594 class Query {
1595  public:
1597  : is_distinct(false)
1598  , where_predicate(nullptr)
1599  , having_predicate(nullptr)
1600  , order_by(nullptr)
1601  , next_query(nullptr)
1602  , is_unionall(false)
1603  , stmt_type(kSELECT)
1604  , num_aggs(0)
1605  , result_table_id(0)
1606  , limit(0)
1607  , offset(0) {}
1608  virtual ~Query();
1609  bool get_is_distinct() const { return is_distinct; }
1610  int get_num_aggs() const { return num_aggs; }
1611  const std::vector<std::shared_ptr<TargetEntry>>& get_targetlist() const {
1612  return targetlist;
1613  }
1614  std::vector<std::shared_ptr<TargetEntry>>& get_targetlist_nonconst() {
1615  return targetlist;
1616  }
1617  const std::vector<RangeTableEntry*>& get_rangetable() const { return rangetable; }
1618  const Expr* get_where_predicate() const { return where_predicate.get(); }
1619  const std::list<std::shared_ptr<Analyzer::Expr>>& get_group_by() const {
1620  return group_by;
1621  };
1622  const Expr* get_having_predicate() const { return having_predicate.get(); }
1623  const std::list<OrderEntry>* get_order_by() const { return order_by; }
1624  const Query* get_next_query() const { return next_query; }
1625  SQLStmtType get_stmt_type() const { return stmt_type; }
1626  bool get_is_unionall() const { return is_unionall; }
1627  int get_result_table_id() const { return result_table_id; }
1628  const std::list<int>& get_result_col_list() const { return result_col_list; }
1629  void set_result_col_list(const std::list<int>& col_list) { result_col_list = col_list; }
1630  void set_result_table_id(int id) { result_table_id = id; }
1631  void set_is_distinct(bool d) { is_distinct = d; }
1632  void set_where_predicate(std::shared_ptr<Analyzer::Expr> p) { where_predicate = p; }
1633  void set_group_by(std::list<std::shared_ptr<Analyzer::Expr>>& g) { group_by = g; }
1634  void set_having_predicate(std::shared_ptr<Analyzer::Expr> p) { having_predicate = p; }
1635  void set_order_by(std::list<OrderEntry>* o) { order_by = o; }
1636  void set_next_query(Query* q) { next_query = q; }
1637  void set_is_unionall(bool u) { is_unionall = u; }
1638  void set_stmt_type(SQLStmtType t) { stmt_type = t; }
1639  void set_num_aggs(int a) { num_aggs = a; }
1640  int get_rte_idx(const std::string& range_var_name) const;
1641  RangeTableEntry* get_rte(int rte_idx) const { return rangetable[rte_idx]; }
1642  void add_rte(RangeTableEntry* rte);
1643  void add_tle(std::shared_ptr<TargetEntry> tle) { targetlist.push_back(tle); }
1644  int64_t get_limit() const { return limit; }
1645  void set_limit(int64_t l) { limit = l; }
1646  int64_t get_offset() const { return offset; }
1647  void set_offset(int64_t o) { offset = o; }
1648 
1649  private:
1650  bool is_distinct; // true only if SELECT DISTINCT
1651  std::vector<std::shared_ptr<TargetEntry>> targetlist; // represents the SELECT clause
1652  std::vector<RangeTableEntry*> rangetable; // represents the FROM clause for SELECT. For
1653  // INSERT, DELETE, UPDATE the result table is
1654  // always the first entry in rangetable.
1655  std::shared_ptr<Analyzer::Expr> where_predicate; // represents the WHERE clause
1656  std::list<std::shared_ptr<Analyzer::Expr>> group_by; // represents the GROUP BY clause
1657  std::shared_ptr<Analyzer::Expr> having_predicate; // represents the HAVING clause
1658  std::list<OrderEntry>* order_by; // represents the ORDER BY clause
1659  Query* next_query; // the next query to UNION
1660  bool is_unionall; // true only if it is UNION ALL
1662  int num_aggs; // number of aggregate functions in query
1663  int result_table_id; // for INSERT statements only
1664  std::list<int> result_col_list; // for INSERT statement only
1665  int64_t limit; // row count for LIMIT clause. 0 means ALL
1666  int64_t offset; // offset in OFFSET clause. 0 means no offset.
1667 };
1668 } // namespace Analyzer
1669 
1670 inline std::shared_ptr<Analyzer::Var> var_ref(const Analyzer::Expr* expr,
1671  const Analyzer::Var::WhichRow which_row,
1672  const int varno) {
1673  const auto col_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr);
1674  const int table_id = col_expr ? col_expr->get_table_id() : 0;
1675  const int column_id = col_expr ? col_expr->get_column_id() : 0;
1676  const int rte_idx = col_expr ? col_expr->get_rte_idx() : -1;
1677  return makeExpr<Analyzer::Var>(
1678  expr->get_type_info(), table_id, column_id, rte_idx, which_row, varno);
1679 }
1680 
1681 // Returns true iff the two expression lists are equal (same size and each element are
1682 // equal).
1683 bool expr_list_match(const std::vector<std::shared_ptr<Analyzer::Expr>>& lhs,
1684  const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs);
1685 
1686 // Remove a cast operator if present.
1687 std::shared_ptr<Analyzer::Expr> remove_cast(const std::shared_ptr<Analyzer::Expr>& expr);
1688 
1689 #endif // ANALYZER_H
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1069
std::list< ExpressionPtr > ExpressionPtrList
Definition: Analyzer.h:182
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1019
Query * next_query
Definition: Analyzer.h:1659
CaseExpr(const SQLTypeInfo &ti, bool has_agg, const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &w, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1142
SQLQualifier get_qualifier() const
Definition: Analyzer.h:442
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:798
bool operator==(const Expr &rhs) const override
Definition: Analyzer.h:562
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:597
TargetEntry(const std::string &n, std::shared_ptr< Analyzer::Expr > e, bool u)
Definition: Analyzer.h:1570
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:282
const Expr * get_where_predicate() const
Definition: Analyzer.h:1618
Query * parsetree
Definition: Analyzer.h:573
SQLAgg
Definition: sqldefs.h:71
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:285
std::shared_ptr< Analyzer::Expr > expr
Definition: Analyzer.h:1584
Var(const SQLTypeInfo &ti, int r, int c, int i, WhichRow o, int v)
Definition: Analyzer.h:270
const Expr * get_arg() const
Definition: Analyzer.h:751
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:206
virtual ~Expr()
Definition: Analyzer.h:77
const Expr * get_arg() const
Definition: Analyzer.h:585
Expr(SQLTypes t, int d, int s, bool notnull)
Definition: Analyzer.h:73
bool unnest
Definition: Analyzer.h:1585
Constant(const SQLTypeInfo &ti, bool n, Datum v)
Definition: Analyzer.h:323
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
Definition: Analyzer.h:1368
Var(const SQLTypeInfo &ti, WhichRow o, int v)
Definition: Analyzer.h:272
bool get_is_simple() const
Definition: Analyzer.h:911
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:800
void set_contains_agg(bool a)
Definition: Analyzer.h:82
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
OrderEntry(int t, bool d, bool nf)
Definition: Analyzer.h:1415
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:739
bool get_calc_encoded_length() const
Definition: Analyzer.h:659
int get_column_id() const
Definition: Analyzer.h:196
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:861
const std::vector< std::shared_ptr< TargetEntry > > & get_targetlist() const
Definition: Analyzer.h:1611
Definition: Analyzer.h:1568
DatediffExpr(const SQLTypeInfo &ti, const DatetruncField f, const std::shared_ptr< Analyzer::Expr > start, const std::shared_ptr< Analyzer::Expr > end)
Definition: Analyzer.h:1275
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:86
size_t getElementCount() const
Definition: Analyzer.h:1489
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
Definition: Analyzer.h:209
SQLTypes
Definition: sqltypes.h:40
const Expr * get_datetime_expr() const
Definition: Analyzer.h:1240
std::shared_ptr< Analyzer::Expr > operand
Definition: Analyzer.h:412
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:853
std::string getName() const
Definition: Analyzer.h:1359
AggExpr(SQLTypes t, SQLAgg a, Expr *g, bool d, std::shared_ptr< Analyzer::Constant > e, int idx)
Definition: Analyzer.h:1085
std::list< int > result_col_list
Definition: Analyzer.h:1664
void set_varno(int n)
Definition: Analyzer.h:277
const Expr * get_arg() const
Definition: Analyzer.h:634
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:693
const Expr * get_having_predicate() const
Definition: Analyzer.h:1622
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:214
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:394
static DEVICE void decompress(const SQLTypeInfo &ti, int8_t *compressed, VarlenDatum *result, Datum *datum)
Definition: ChunkIter.cpp:26
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:496
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:1363
const std::list< std::shared_ptr< Analyzer::Expr > > & get_group_by() const
Definition: Analyzer.h:1619
virtual void find_expr(bool(*f)(const Expr *), std::list< const Expr *> &expr_list) const
Definition: Analyzer.h:160
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:989
virtual std::shared_ptr< Analyzer::Expr > normalize_simple_predicate(int &rte_idx) const
Definition: Analyzer.h:95
SQLQualifier
Definition: sqldefs.h:69
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:757
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:518
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1105
SQLStmtType stmt_type
Definition: Analyzer.h:1661
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:1023
ColumnVar(const SQLTypeInfo &ti, int r, int c, int i)
Definition: Analyzer.h:193
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1133
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:289
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:338
SQLOps
Definition: sqldefs.h:29
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:1456
std::shared_ptr< Analyzer::Expr > get_shared_ptr()
Definition: Analyzer.h:78
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:919
virtual void get_domain(DomainSet &domain_set) const
Definition: Analyzer.h:174
std::list< std::shared_ptr< Analyzer::Expr > > group_by
Definition: Analyzer.h:1656
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:615
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:1528
SQLTypeInfo ti0_
Definition: Analyzer.h:1558
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:558
std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1098
int get_result_table_id() const
Definition: Analyzer.h:1627
std::shared_ptr< Analyzer::Expr > like_expr
Definition: Analyzer.h:956
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:1560
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1041
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:871
int tle_no
Definition: Analyzer.h:1419
~OrderEntry()
Definition: Analyzer.h:1416
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:1670
const std::shared_ptr< const Analyzer::Expr > arg
Definition: Analyzer.h:644
bool isLocalAlloc() const
Definition: Analyzer.h:1490
const SQLTypeInfo getTypeInfo1() const
Definition: Analyzer.h:1552
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:487
GeoBinOper(const Geo_namespace::GeoBase::GeoOp op, const SQLTypeInfo &ti, const SQLTypeInfo &ti0, const SQLTypeInfo &ti1, const std::vector< std::shared_ptr< Analyzer::Expr >> &args0, const std::vector< std::shared_ptr< Analyzer::Expr >> &args1)
Definition: Analyzer.h:1537
const Expr * get_start_expr() const
Definition: Analyzer.h:1281
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1054
DateaddField get_field() const
Definition: Analyzer.h:1238
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:181
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:1466
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:1635
int64_t get_offset() const
Definition: Analyzer.h:1646
void set_result_col_list(const std::list< int > &col_list)
Definition: Analyzer.h:1629
void set_which_row(WhichRow r)
Definition: Analyzer.h:275
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:925
virtual void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
Definition: Analyzer.h:84
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1380
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:1465
size_t getArity() const
Definition: Analyzer.h:1361
void set_offset(int64_t o)
Definition: Analyzer.h:1647
const Expr * get_from_expr() const
Definition: Analyzer.h:1198
UOper(SQLTypes t, SQLOps o, std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:367
WhichRow get_which_row() const
Definition: Analyzer.h:274
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:658
SQLQualifier qualifier
Definition: Analyzer.h:515
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:1523
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:478
SQLTypeInfo type_info
Definition: Analyzer.h:177
void print() const
Definition: Analyzer.h:1418
std::list< const Expr * > DomainSet
Definition: Analyzer.h:62
void set_constval(Datum d)
Definition: Analyzer.h:337
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:725
const std::shared_ptr< Analyzer::Expr > get_own_operand() const
Definition: Analyzer.h:373
const Expr * get_arg() const
Definition: Analyzer.h:852
virtual std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:126
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1007
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:554
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:678
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1001
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:544
void set_type_info(const SQLTypeInfo &ti)
Definition: Analyzer.h:80
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1464
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:816
LikelihoodExpr(std::shared_ptr< Analyzer::Expr > a, float l=0.5)
Definition: Analyzer.h:1032
SQLOps get_optype() const
Definition: Analyzer.h:440
Expr * get_arg() const
Definition: Analyzer.h:1097
BinOper(const SQLTypeInfo &ti, bool has_agg, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:423
DatetruncField get_field() const
Definition: Analyzer.h:1322
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:875
const Expr * get_arg() const
Definition: Analyzer.h:706
DatetruncField field_
Definition: Analyzer.h:1348
const Expr * get_arg() const
Definition: Analyzer.h:906
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:517
const Expr * get_else_expr() const
Definition: Analyzer.h:1153
const std::vector< std::shared_ptr< Analyzer::Expr > > args1_
Definition: Analyzer.h:1561
Datum get_constval() const
Definition: Analyzer.h:336
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:617
EncodingType
Definition: sqltypes.h:156
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:467
DatetruncExpr(const SQLTypeInfo &ti, bool has_agg, DatetruncField f, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1317
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:1641
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:471
virtual std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:145
const Analyzer::Expr * getElement(const size_t i) const
Definition: Analyzer.h:1493
Expr(const SQLTypeInfo &ti, bool has_agg=false)
Definition: Analyzer.h:75
const DatetruncField field_
Definition: Analyzer.h:1306
virtual void print() const
Definition: Analyzer.h:151
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:766
DateaddField
Definition: DateAdd.h:42
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:933
const Geo_namespace::GeoBase::GeoOp op_
Definition: Analyzer.h:1557
std::vector< std::shared_ptr< TargetEntry > > targetlist
Definition: Analyzer.h:1651
const DateaddField field_
Definition: Analyzer.h:1264
DatetruncField
Definition: DateTruncate.h:27
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.h:538
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1349
const std::list< int > & get_result_col_list() const
Definition: Analyzer.h:1628
const Expr * get_from_expr() const
Definition: Analyzer.h:1323
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:840
const Expr * get_escape_expr() const
Definition: Analyzer.h:909
Subquery(const SQLTypeInfo &ti, Query *q)
Definition: Analyzer.h:530
bool is_overlaps_oper() const
Definition: Analyzer.h:441
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:383
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:380
GeoUOper(const Geo_namespace::GeoBase::GeoOp op, const SQLTypeInfo &ti, const SQLTypeInfo &ti0, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1510
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
Definition: Analyzer.h:245
const std::shared_ptr< Analyzer::Expr > end_
Definition: Analyzer.h:1308
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:867
void set_expr(std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1577
const std::shared_ptr< Analyzer::Expr > number_
Definition: Analyzer.h:1265
ArrayExpr(SQLTypeInfo const &array_ti, ExpressionPtrVector const &array_exprs, bool is_null=false, bool local_alloc=false)
Definition: Analyzer.h:1477
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:349
std::string resname
Definition: Analyzer.h:1583
SQLStmtType get_stmt_type() const
Definition: Analyzer.h:1625
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:1460
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:673
SQLTypeInfo ti1_
Definition: Analyzer.h:1559
float get_likelihood() const
Definition: Analyzer.h:1036
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:550
const std::shared_ptr< Analyzer::Expr > start_
Definition: Analyzer.h:1307
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > & get_expr_pair_list() const
Definition: Analyzer.h:1150
virtual ~TargetEntry()
Definition: Analyzer.h:1572
int64_t get_limit() const
Definition: Analyzer.h:1644
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:858
bool expr_list_match(const std::vector< std::shared_ptr< Analyzer::Expr >> &lhs, const std::vector< std::shared_ptr< Analyzer::Expr >> &rhs)
Definition: Analyzer.cpp:3228
bool nulls_first
Definition: Analyzer.h:1421
FunctionOperWithCustomTypeHandling(const SQLTypeInfo &ti, const std::string &name, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1385
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:667
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:1467
ExtractExpr(const SQLTypeInfo &ti, bool has_agg, ExtractField f, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1192
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:1522
Constant(const SQLTypeInfo &ti, bool n, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.h:330
const Query * get_next_query() const
Definition: Analyzer.h:1624
const std::shared_ptr< Analyzer::Expr > get_own_left_operand() const
Definition: Analyzer.h:445
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:774
void set_num_aggs(int a)
Definition: Analyzer.h:1639
void set_group_by(std::list< std::shared_ptr< Analyzer::Expr >> &g)
Definition: Analyzer.h:1633
WhichRow which_row
Definition: Analyzer.h:297
void add_tle(std::shared_ptr< TargetEntry > tle)
Definition: Analyzer.h:1643
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:707
void set_next_query(Query *q)
Definition: Analyzer.h:1636
SQLStmtType
Definition: sqldefs.h:101
DatetruncField get_field() const
Definition: Analyzer.h:1280
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:955
const std::vector< std::shared_ptr< Analyzer::Expr > > tuple_
Definition: Analyzer.h:255
void set_having_predicate(std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:1634
void set_result_table_id(int id)
Definition: Analyzer.h:1630
bool get_is_unionall() const
Definition: Analyzer.h:1626
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:721
const std::vector< int64_t > value_list
Definition: Analyzer.h:645
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:389
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:1553
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:683
bool get_is_null() const
Definition: Analyzer.h:335
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:664
const std::shared_ptr< Analyzer::Expr > get_own_right_operand() const
Definition: Analyzer.h:448
#define CHECK_LT(x, y)
Definition: Logger.h:207
int64_t offset
Definition: Analyzer.h:1666
ExpressionPtrVector contained_expressions_
Definition: Analyzer.h:1499
virtual std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:135
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:760
UOper(const SQLTypeInfo &ti, bool has_agg, SQLOps o, std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:365
const Expr * get_arg() const
Definition: Analyzer.h:978
EncodingType get_compression() const
Definition: Analyzer.h:198
void set_is_distinct(bool d)
Definition: Analyzer.h:1631
WindowFunction(const SQLTypeInfo &ti, const SqlWindowFunctionKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::vector< std::shared_ptr< Analyzer::Expr >> &partition_keys, const std::vector< std::shared_ptr< Analyzer::Expr >> &order_keys, const std::vector< OrderEntry > &collation)
Definition: Analyzer.h:1430
std::enable_if< std::is_base_of< Analyzer::Expr, Tp >::value, std::shared_ptr< Tp > >::type makeExpr(Args &&... args)
Definition: Analyzer.h:53
bool is_null(const T &v, const SQLTypeInfo &t)
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:821
const Expr * get_pattern_expr() const
Definition: Analyzer.h:980
std::vector< std::shared_ptr< TargetEntry > > & get_targetlist_nonconst()
Definition: Analyzer.h:1614
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:811
virtual void group_predicates(std::list< const Expr *> &scan_predicates, std::list< const Expr *> &join_predicates, std::list< const Expr *> &const_predicates) const
Definition: Analyzer.h:103
const Expr * get_escape_expr() const
Definition: Analyzer.h:981
RegexpExpr(std::shared_ptr< Analyzer::Expr > a, std::shared_ptr< Analyzer::Expr > p, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:971
int get_rte_idx() const
Definition: Analyzer.h:197
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:1551
bool get_is_distinct() const
Definition: Analyzer.h:1609
void find_expr(bool(*f)(const Expr *), std::list< const Expr *> &expr_list) const override
Definition: Analyzer.h:567
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:729
SQLAgg get_aggtype() const
Definition: Analyzer.h:1096
int get_table_id() const
Definition: Analyzer.h:195
const std::vector< std::shared_ptr< Analyzer::Expr > > & getPartitionKeys() const
Definition: Analyzer.h:1452
const Expr * get_arg() const
Definition: Analyzer.h:1034
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:995
void set_is_unionall(bool u)
Definition: Analyzer.h:1637
SampleRatioExpr(std::shared_ptr< Analyzer::Expr > a)
Definition: Analyzer.h:749
Expr * get_expr() const
Definition: Analyzer.h:1575
void set_resname(const std::string &name)
Definition: Analyzer.h:1574
bool get_is_distinct() const
Definition: Analyzer.h:1099
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:804
bool operator==(const SlotSize &lhs, const SlotSize &rhs)
std::vector< RangeTableEntry * > rangetable
Definition: Analyzer.h:1652
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1224
void print() const
Definition: Analyzer.h:1580
Expression class for the LOWER (lowercase) string function. The "arg" constructor parameter must be a...
Definition: Analyzer.h:792
const std::list< OrderEntry > * get_order_by() const
Definition: Analyzer.h:1623
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:979
ExtractField
SqlWindowFunctionKind
Definition: sqldefs.h:82
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:916
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:784
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:1450
SQLTypeInfo ti0_
Definition: Analyzer.h:1527
const std::shared_ptr< Analyzer::Expr > get_own_from_expr() const
Definition: Analyzer.h:1199
void set_where_predicate(std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:1632
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:1638
int get_varno() const
Definition: Analyzer.h:276
std::shared_ptr< Analyzer::Constant > get_error_rate() const
Definition: Analyzer.h:1100
const std::shared_ptr< Analyzer::Expr > datetime_
Definition: Analyzer.h:1266
const std::shared_ptr< Analyzer::Expr > get_own_from_expr() const
Definition: Analyzer.h:1324
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:79
int get_num_aggs() const
Definition: Analyzer.h:1610
std::shared_ptr< Expr > get_own_expr() const
Definition: Analyzer.h:1576
const std::vector< RangeTableEntry * > & get_rangetable() const
Definition: Analyzer.h:1617
KeyForStringExpr(std::shared_ptr< Analyzer::Expr > a)
Definition: Analyzer.h:704
Constant(SQLTypes t, bool n)
Definition: Analyzer.h:309
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:885
const std::string & get_resname() const
Definition: Analyzer.h:1573
const Expr * get_arg() const
Definition: Analyzer.h:796
#define CHECK(condition)
Definition: Logger.h:197
LikeExpr(std::shared_ptr< Analyzer::Expr > a, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > e, bool i, bool s)
Definition: Analyzer.h:895
ExtractField field_
Definition: Analyzer.h:1223
BinOper(SQLTypes t, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:430
bool is_desc
Definition: Analyzer.h:1420
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1035
std::shared_ptr< Analyzer::Expr > having_predicate
Definition: Analyzer.h:1657
Expr(SQLTypes t, int d, bool notnull)
Definition: Analyzer.h:71
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:3241
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:543
std::vector< ExpressionPtr > ExpressionPtrVector
Definition: Analyzer.h:183
const Expr * get_arg() const
Definition: Analyzer.h:657
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:770
DateaddExpr(const SQLTypeInfo &ti, const DateaddField f, const std::shared_ptr< Analyzer::Expr > number, const std::shared_ptr< Analyzer::Expr > datetime)
Definition: Analyzer.h:1233
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:958
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:941
CharLengthExpr(std::shared_ptr< Analyzer::Expr > a, bool e)
Definition: Analyzer.h:655
const std::vector< int64_t > & get_value_list() const
Definition: Analyzer.h:636
ExpressionTuple(const std::vector< std::shared_ptr< Analyzer::Expr >> &tuple)
Definition: Analyzer.h:242
Geo_namespace::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:1521
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1044
bool get_contains_agg() const
Definition: Analyzer.h:81
Definition: sqltypes.h:47
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:1463
bool get_unnest() const
Definition: Analyzer.h:1578
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:399
Constant(SQLTypes t, bool n, Datum v)
Definition: Analyzer.h:316
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1110
const Expr * get_like_expr() const
Definition: Analyzer.h:908
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:907
std::shared_ptr< Analyzer::Expr > where_predicate
Definition: Analyzer.h:1655
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1059
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:715
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1050
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs1() const
Definition: Analyzer.h:1554
virtual void collect_rte_idx(std::set< int > &rte_idx_set) const
Definition: Analyzer.h:110
Definition: Analyzer.h:1414
void set_limit(int64_t l)
Definition: Analyzer.h:1645
ExtractField get_field() const
Definition: Analyzer.h:1197
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:587
int64_t limit
Definition: Analyzer.h:1665
Geo_namespace::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:1550
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:586
const Expr * get_end_expr() const
Definition: Analyzer.h:1282
bool contains_agg
Definition: Analyzer.h:178
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:594
const Geo_namespace::GeoBase::GeoOp op_
Definition: Analyzer.h:1526
std::list< OrderEntry > * order_by
Definition: Analyzer.h:1658
const Expr * get_number_expr() const
Definition: Analyzer.h:1239
bool is_distinct(const size_t input_idx, const RelAlgNode *node)
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:1448
bool isNull() const
Definition: Analyzer.h:1491
std::shared_ptr< Analyzer::Expr > pattern_expr
Definition: Analyzer.h:1021
const Query * get_parsetree() const
Definition: Analyzer.h:533
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1079
int get_comp_param() const
Definition: Analyzer.h:199
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
bool get_is_ilike() const
Definition: Analyzer.h:910
FunctionOper(const SQLTypeInfo &ti, const std::string &name, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1354
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:712
SQLOps get_optype() const
Definition: Analyzer.h:371
CardinalityExpr(std::shared_ptr< Analyzer::Expr > a)
Definition: Analyzer.h:850
SQLOps optype
Definition: Analyzer.h:411
const std::string name_
Definition: Analyzer.h:1379
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:752
LowerExpr(std::shared_ptr< Analyzer::Expr > arg)
Definition: Analyzer.h:794
const Expr * get_right_operand() const
Definition: Analyzer.h:444
virtual void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
Definition: Analyzer.h:117
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:986
const Expr * get_left_operand() const
Definition: Analyzer.h:443
const Expr * get_operand() const
Definition: Analyzer.h:372