OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 
22 #ifndef ANALYZER_H
23 #define ANALYZER_H
24 
25 #include "Geospatial/Types.h"
26 #include "Logger/Logger.h"
27 #include "Shared/sqldefs.h"
28 #include "Shared/sqltypes.h"
29 
30 #include <cstdint>
31 #include <iostream>
32 #include <list>
33 #include <map>
34 #include <optional>
35 #include <set>
36 #include <sstream>
37 #include <string>
38 #include <type_traits>
39 #include <utility>
40 #include <vector>
41 
42 extern bool g_enable_string_functions;
43 
44 namespace Analyzer {
45 class Expr;
46 }
47 
48 namespace Catalog_Namespace {
49 class Catalog;
50 }
51 
52 template <typename Tp, typename... Args>
53 inline typename std::enable_if<std::is_base_of<Analyzer::Expr, Tp>::value,
54  std::shared_ptr<Tp>>::type
55 makeExpr(Args&&... args) {
56  return std::make_shared<Tp>(std::forward<Args>(args)...);
57 }
58 
59 namespace Analyzer {
60 
61 class ColumnVar;
62 class TargetEntry;
63 class Expr;
64 using DomainSet = std::list<const Expr*>;
65 
66 /*
67  * @type Expr
68  * @brief super class for all expressions in parse trees and in query plans
69  */
70 class Expr : public std::enable_shared_from_this<Expr> {
71  public:
72  Expr(SQLTypes t, bool notnull) : type_info(t, notnull), contains_agg(false) {}
73  Expr(SQLTypes t, int d, bool notnull)
74  : type_info(t, d, 0, notnull), contains_agg(false) {}
75  Expr(SQLTypes t, int d, int s, bool notnull)
76  : type_info(t, d, s, notnull), contains_agg(false) {}
77  Expr(const SQLTypeInfo& ti, bool has_agg = false)
78  : type_info(ti), contains_agg(has_agg) {}
79  virtual ~Expr() {}
80  std::shared_ptr<Analyzer::Expr> get_shared_ptr() { return shared_from_this(); }
81  const SQLTypeInfo& get_type_info() const { return type_info; }
82  void set_type_info(const SQLTypeInfo& ti) { type_info = ti; }
83  bool get_contains_agg() const { return contains_agg; }
84  void set_contains_agg(bool a) { contains_agg = a; }
85  virtual std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info);
86  virtual void check_group_by(
87  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {};
88  virtual std::shared_ptr<Analyzer::Expr> deep_copy()
89  const = 0; // make a deep copy of self
90  /*
91  * @brief normalize_simple_predicate only applies to boolean expressions.
92  * it checks if it is an expression comparing a column
93  * with a constant. if so, it returns a normalized copy of the predicate with ColumnVar
94  * always as the left operand with rte_idx set to the rte_idx of the ColumnVar.
95  * it returns nullptr with rte_idx set to -1 otherwise.
96  */
97  virtual std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const {
98  rte_idx = -1;
99  return nullptr;
100  }
101  /*
102  * @brief seperate conjunctive predicates into scan predicates, join predicates and
103  * constant predicates.
104  */
105  virtual void group_predicates(std::list<const Expr*>& scan_predicates,
106  std::list<const Expr*>& join_predicates,
107  std::list<const Expr*>& const_predicates) const {}
108  /*
109  * @brief collect_rte_idx collects the indices of all the range table
110  * entries involved in an expression
111  */
112  virtual void collect_rte_idx(std::set<int>& rte_idx_set) const {}
113  /*
114  * @brief collect_column_var collects all unique ColumnVar nodes in an expression
115  * If include_agg = false, it does not include to ColumnVar nodes inside
116  * the argument to AggExpr's. Otherwise, they are included.
117  * It does not make copies of the ColumnVar
118  */
119  virtual void collect_column_var(
120  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
121  colvar_set,
122  bool include_agg) const {}
123 
124  virtual size_t get_num_column_vars(const bool include_agg) const;
125 
126  /*
127  * @brief rewrite_with_targetlist rewrite ColumnVar's in expression with entries in a
128  * targetlist. targetlist expressions are expected to be only Var's or AggExpr's.
129  * returns a new expression copy
130  */
131  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
132  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
133  return deep_copy();
134  };
135  /*
136  * @brief rewrite_with_child_targetlist rewrite ColumnVar's in expression with entries
137  * in a child plan's targetlist. targetlist expressions are expected to be only Var's or
138  * ColumnVar's returns a new expression copy
139  */
140  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
141  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
142  return deep_copy();
143  };
144  /*
145  * @brief rewrite_agg_to_var rewrite ColumnVar's in expression with entries in an
146  * AggPlan's targetlist. targetlist expressions are expected to be only Var's or
147  * ColumnVar's or AggExpr's All AggExpr's are written into Var's. returns a new
148  * expression copy
149  */
150  virtual std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
151  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
152  return deep_copy();
153  }
154  virtual bool operator==(const Expr& rhs) const = 0;
155  virtual std::string toString() const = 0;
156  virtual void print() const { std::cout << toString(); }
157 
158  virtual void add_unique(std::list<const Expr*>& expr_list) const;
159  /*
160  * @brief find_expr traverse Expr hierarchy and adds the node pointer to
161  * the expr_list if the function f returns true.
162  * Duplicate Expr's are not added the list.
163  * Cannot use std::set because we don't have an ordering function.
164  */
165  virtual void find_expr(bool (*f)(const Expr*),
166  std::list<const Expr*>& expr_list) const {
167  if (f(this)) {
168  add_unique(expr_list);
169  }
170  }
171  /*
172  * @brief decompress adds cast operator to decompress encoded result
173  */
174  std::shared_ptr<Analyzer::Expr> decompress();
175  /*
176  * @brief perform domain analysis on Expr and fill in domain
177  * information in domain_set. Empty domain_set means no information.
178  */
179  virtual void get_domain(DomainSet& domain_set) const { domain_set.clear(); }
180 
181  protected:
182  SQLTypeInfo type_info; // SQLTypeInfo of the return result of this expression
184 };
185 
186 using ExpressionPtr = std::shared_ptr<Analyzer::Expr>;
187 using ExpressionPtrList = std::list<ExpressionPtr>;
188 using ExpressionPtrVector = std::vector<ExpressionPtr>;
189 
190 /*
191  * @type ColumnVar
192  * @brief expression that evaluates to the value of a column in a given row from a base
193  * table. It is used in parse trees and is only used in Scan nodes in a query plan for
194  * scanning a table while Var nodes are used for all other plans.
195  */
196 class ColumnVar : public Expr {
197  public:
198  ColumnVar(const SQLTypeInfo& ti, int r, int c, int i)
199  : Expr(ti), table_id(r), column_id(c), rte_idx(i) {}
200  int get_table_id() const { return table_id; }
201  int get_column_id() const { return column_id; }
202  int get_rte_idx() const { return rte_idx; }
203  void set_rte_idx(int new_rte_idx) { rte_idx = new_rte_idx; }
205  int get_comp_param() const { return type_info.get_comp_param(); }
206  void check_group_by(
207  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
208  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
209  void group_predicates(std::list<const Expr*>& scan_predicates,
210  std::list<const Expr*>& join_predicates,
211  std::list<const Expr*>& const_predicates) const override;
212  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
213  rte_idx_set.insert(rte_idx);
214  }
215  static bool colvar_comp(const ColumnVar* l, const ColumnVar* r) {
216  return l->get_table_id() < r->get_table_id() ||
217  (l->get_table_id() == r->get_table_id() &&
218  l->get_column_id() < r->get_column_id());
219  }
221  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
222  colvar_set,
223  bool include_agg) const override {
224  colvar_set.insert(this);
225  }
226  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
227  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
228  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
229  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
230  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
231  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
232  bool operator==(const Expr& rhs) const override;
233  std::string toString() const override;
234 
235  protected:
236  int table_id; // the global table id
237  int column_id; // the column id
238  int rte_idx; // 0-based range table index, used for table ordering in multi-joins
239 };
240 
241 /*
242  * @type ExpressionTuple
243  * @brief A tuple of expressions on the side of an equi-join on multiple columns.
244  * Not to be used in any other context.
245  */
246 class ExpressionTuple : public Expr {
247  public:
248  ExpressionTuple(const std::vector<std::shared_ptr<Analyzer::Expr>>& tuple)
249  : Expr(SQLTypeInfo()), tuple_(tuple){};
250 
251  const std::vector<std::shared_ptr<Analyzer::Expr>>& getTuple() const { return tuple_; }
252 
253  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
254 
255  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
256 
257  bool operator==(const Expr& rhs) const override;
258  std::string toString() const override;
259 
260  private:
261  const std::vector<std::shared_ptr<Analyzer::Expr>> tuple_;
262 };
263 
264 /*
265  * @type Var
266  * @brief expression that evaluates to the value of a column in a given row generated
267  * from a query plan node. It is only used in plan nodes above Scan nodes.
268  * The row can be produced by either the inner or the outer plan in case of a join.
269  * It inherits from ColumnVar to keep track of the lineage through the plan nodes.
270  * The table_id will be set to 0 if the Var does not correspond to an original column
271  * value.
272  */
273 class Var : public ColumnVar {
274  public:
276  Var(const SQLTypeInfo& ti, int r, int c, int i, WhichRow o, int v)
277  : ColumnVar(ti, r, c, i), which_row(o), varno(v) {}
278  Var(const SQLTypeInfo& ti, WhichRow o, int v)
279  : ColumnVar(ti, 0, 0, -1), which_row(o), varno(v) {}
280  WhichRow get_which_row() const { return which_row; }
282  int get_varno() const { return varno; }
283  void set_varno(int n) { varno = n; }
284  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
285  std::string toString() const override;
286  void check_group_by(
287  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
288  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
289  rte_idx_set.insert(-1);
290  }
291  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
292  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
293  return deep_copy();
294  }
295  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
296  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
297  return deep_copy();
298  }
299  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
300  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
301 
302  private:
303  WhichRow which_row; // indicate which row this Var should project from. It can be from
304  // the outer input plan or the inner input plan (for joins) or the
305  // output row in the current plan.
306  int varno; // the column number in the row. 1-based
307 };
308 
309 /*
310  * @type Constant
311  * @brief expression for a constant value
312  */
313 class Constant : public Expr {
314  public:
315  Constant(SQLTypes t, bool n) : Expr(t, !n), is_null(n) {
316  if (n) {
317  set_null_value();
318  } else {
319  type_info.set_notnull(true);
320  }
321  }
322  Constant(SQLTypes t, bool n, Datum v) : Expr(t, !n), is_null(n), constval(v) {
323  if (n) {
324  set_null_value();
325  } else {
326  type_info.set_notnull(true);
327  }
328  }
329  Constant(const SQLTypeInfo& ti, bool n, Datum v) : Expr(ti), is_null(n), constval(v) {
330  if (n) {
331  set_null_value();
332  } else {
333  type_info.set_notnull(true);
334  }
335  }
337  bool n,
338  const std::list<std::shared_ptr<Analyzer::Expr>>& l)
339  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
340  ~Constant() override;
341  bool get_is_null() const { return is_null; }
342  Datum get_constval() const { return constval; }
343  void set_constval(Datum d) { constval = d; }
344  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
345  return value_list;
346  }
347  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
348  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
349  bool operator==(const Expr& rhs) const override;
350  std::string toString() const override;
351 
352  protected:
353  bool is_null; // constant is NULL
354  Datum constval; // the constant value
355  const std::list<std::shared_ptr<Analyzer::Expr>> value_list;
356  void cast_number(const SQLTypeInfo& new_type_info);
357  void cast_string(const SQLTypeInfo& new_type_info);
358  void cast_from_string(const SQLTypeInfo& new_type_info);
359  void cast_to_string(const SQLTypeInfo& new_type_info);
360  void do_cast(const SQLTypeInfo& new_type_info);
361  void set_null_value();
362 };
363 
364 /*
365  * @type UOper
366  * @brief represents unary operator expressions. operator types include
367  * kUMINUS, kISNULL, kEXISTS, kCAST
368  */
369 class UOper : public Expr {
370  public:
371  UOper(const SQLTypeInfo& ti, bool has_agg, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
372  : Expr(ti, has_agg), optype(o), operand(p) {}
373  UOper(SQLTypes t, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
374  : Expr(t, o == kISNULL ? true : p->get_type_info().get_notnull())
375  , optype(o)
376  , operand(p) {}
377  SQLOps get_optype() const { return optype; }
378  const Expr* get_operand() const { return operand.get(); }
379  const std::shared_ptr<Analyzer::Expr> get_own_operand() const { return operand; }
380  void check_group_by(
381  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
382  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
383  void group_predicates(std::list<const Expr*>& scan_predicates,
384  std::list<const Expr*>& join_predicates,
385  std::list<const Expr*>& const_predicates) const override;
386  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
387  operand->collect_rte_idx(rte_idx_set);
388  }
390  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
391  colvar_set,
392  bool include_agg) const override {
393  operand->collect_column_var(colvar_set, include_agg);
394  }
395  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
396  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
397  return makeExpr<UOper>(
398  type_info, contains_agg, optype, operand->rewrite_with_targetlist(tlist));
399  }
400  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
401  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
402  return makeExpr<UOper>(
403  type_info, contains_agg, optype, operand->rewrite_with_child_targetlist(tlist));
404  }
405  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
406  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
407  return makeExpr<UOper>(
408  type_info, contains_agg, optype, operand->rewrite_agg_to_var(tlist));
409  }
410  bool operator==(const Expr& rhs) const override;
411  std::string toString() const override;
412  void find_expr(bool (*f)(const Expr*),
413  std::list<const Expr*>& expr_list) const override;
414  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
415 
416  protected:
417  SQLOps optype; // operator type, e.g., kUMINUS, kISNULL, kEXISTS
418  std::shared_ptr<Analyzer::Expr> operand; // operand expression
419 };
420 
421 /*
422  * @type BinOper
423  * @brief represents binary operator expressions. it includes all
424  * comparison, arithmetic and boolean binary operators. it handles ANY/ALL qualifiers
425  * in case the right_operand is a subquery.
426  */
427 class BinOper : public Expr {
428  public:
429  BinOper(const SQLTypeInfo& ti,
430  bool has_agg,
431  SQLOps o,
432  SQLQualifier q,
433  std::shared_ptr<Analyzer::Expr> l,
434  std::shared_ptr<Analyzer::Expr> r)
435  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
437  SQLOps o,
438  SQLQualifier q,
439  std::shared_ptr<Analyzer::Expr> l,
440  std::shared_ptr<Analyzer::Expr> r)
441  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
442  , optype(o)
443  , qualifier(q)
444  , left_operand(l)
445  , right_operand(r) {}
446  SQLOps get_optype() const { return optype; }
447  bool is_overlaps_oper() const { return optype == kOVERLAPS; }
449  const Expr* get_left_operand() const { return left_operand.get(); }
450  const Expr* get_right_operand() const { return right_operand.get(); }
451  const std::shared_ptr<Analyzer::Expr> get_own_left_operand() const {
452  return left_operand;
453  }
454  const std::shared_ptr<Analyzer::Expr> get_own_right_operand() const {
455  return right_operand;
456  }
458  const SQLTypeInfo& left_type,
459  const SQLTypeInfo& right_type,
460  SQLTypeInfo* new_left_type,
461  SQLTypeInfo* new_right_type);
462  static SQLTypeInfo common_numeric_type(const SQLTypeInfo& type1,
463  const SQLTypeInfo& type2);
464  static SQLTypeInfo common_string_type(const SQLTypeInfo& type1,
465  const SQLTypeInfo& type2);
466  void check_group_by(
467  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
468  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
469  std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const override;
470  void group_predicates(std::list<const Expr*>& scan_predicates,
471  std::list<const Expr*>& join_predicates,
472  std::list<const Expr*>& const_predicates) const override;
473  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
474  left_operand->collect_rte_idx(rte_idx_set);
475  right_operand->collect_rte_idx(rte_idx_set);
476  }
478  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
479  colvar_set,
480  bool include_agg) const override {
481  left_operand->collect_column_var(colvar_set, include_agg);
482  right_operand->collect_column_var(colvar_set, include_agg);
483  }
484  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
485  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
486  return makeExpr<BinOper>(type_info,
487  contains_agg,
488  optype,
489  qualifier,
490  left_operand->rewrite_with_targetlist(tlist),
491  right_operand->rewrite_with_targetlist(tlist));
492  }
493  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
494  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
495  return makeExpr<BinOper>(type_info,
496  contains_agg,
497  optype,
498  qualifier,
499  left_operand->rewrite_with_child_targetlist(tlist),
500  right_operand->rewrite_with_child_targetlist(tlist));
501  }
502  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
503  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
504  return makeExpr<BinOper>(type_info,
505  contains_agg,
506  optype,
507  qualifier,
508  left_operand->rewrite_agg_to_var(tlist),
509  right_operand->rewrite_agg_to_var(tlist));
510  }
511  bool operator==(const Expr& rhs) const override;
512  std::string toString() const override;
513  void find_expr(bool (*f)(const Expr*),
514  std::list<const Expr*>& expr_list) const override;
516  const std::shared_ptr<Analyzer::Expr> cast_operand,
517  const std::shared_ptr<Analyzer::Expr> const_operand);
518 
519  private:
520  SQLOps optype; // operator type, e.g., kLT, kAND, kPLUS, etc.
521  SQLQualifier qualifier; // qualifier kANY, kALL or kONE. Only relevant with
522  // right_operand is Subquery
523  std::shared_ptr<Analyzer::Expr> left_operand; // the left operand expression
524  std::shared_ptr<Analyzer::Expr> right_operand; // the right operand expression
525 };
526 
531 class RangeOper : public Expr {
532  public:
533  RangeOper(const bool l_inclusive,
534  const bool r_inclusive,
535  std::shared_ptr<Analyzer::Expr> l,
536  std::shared_ptr<Analyzer::Expr> r)
537  : Expr(SQLTypeInfo(kNULLT), /*not_null=*/false)
538  , left_inclusive_(l_inclusive)
539  , right_inclusive_(r_inclusive)
540  , left_operand_(l)
541  , right_operand_(r) {
544  }
545 
546  const Expr* get_left_operand() const { return left_operand_.get(); }
547  const Expr* get_right_operand() const { return right_operand_.get(); }
548 
549  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
550  bool operator==(const Expr& rhs) const override;
551  std::string toString() const override;
552 
553  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
554  left_operand_->collect_rte_idx(rte_idx_set);
555  right_operand_->collect_rte_idx(rte_idx_set);
556  }
557 
559  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
560  colvar_set,
561  bool include_agg) const override {
562  left_operand_->collect_column_var(colvar_set, include_agg);
563  right_operand_->collect_column_var(colvar_set, include_agg);
564  }
565 
566  private:
567  // build a range between these two operands
570  std::shared_ptr<Analyzer::Expr> left_operand_;
571  std::shared_ptr<Analyzer::Expr> right_operand_;
572 };
573 
574 class Query;
575 
576 /*
577  * @type Subquery
578  * @brief subquery expression. Note that the type of the expression is the type of the
579  * TargetEntry in the subquery instead of the set.
580  */
581 class Subquery : public Expr {
582  public:
583  Subquery(const SQLTypeInfo& ti, Query* q)
584  : Expr(ti), parsetree(q) /*, plan(nullptr)*/ {}
585  ~Subquery() override;
586  const Query* get_parsetree() const { return parsetree; }
587  // const Plan *get_plan() const { return plan; }
588  // void set_plan(Plan *p) { plan = p; } // subquery plan is set by the optimizer
589  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
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  CHECK(false);
595  }
596  void collect_rte_idx(std::set<int>& rte_idx_set) const override { CHECK(false); }
598  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
599  colvar_set,
600  bool include_agg) const override {
601  CHECK(false);
602  }
603  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
604  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
605  abort();
606  }
607  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
608  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
609  abort();
610  }
611  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
612  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
613  abort();
614  }
615  bool operator==(const Expr& rhs) const override {
616  CHECK(false);
617  return false;
618  }
619  std::string toString() const override;
620  void find_expr(bool (*f)(const Expr*),
621  std::list<const Expr*>& expr_list) const override {
622  CHECK(false);
623  }
624 
625  private:
626  Query* parsetree; // parse tree of the subquery
627 };
628 
629 /*
630  * @type InValues
631  * @brief represents predicate expr IN (v1, v2, ...)
632  * v1, v2, ... are can be either Constant or Parameter.
633  */
634 class InValues : public Expr {
635  public:
636  InValues(std::shared_ptr<Analyzer::Expr> a,
637  const std::list<std::shared_ptr<Analyzer::Expr>>& l);
638  const Expr* get_arg() const { return arg.get(); }
639  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
640  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
641  return value_list;
642  }
643  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
644  void group_predicates(std::list<const Expr*>& scan_predicates,
645  std::list<const Expr*>& join_predicates,
646  std::list<const Expr*>& const_predicates) const override;
647  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
648  arg->collect_rte_idx(rte_idx_set);
649  }
651  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
652  colvar_set,
653  bool include_agg) const override {
654  arg->collect_column_var(colvar_set, include_agg);
655  }
656  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
657  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
658  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
659  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
660  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
661  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
662  bool operator==(const Expr& rhs) const override;
663  std::string toString() const override;
664  void find_expr(bool (*f)(const Expr*),
665  std::list<const Expr*>& expr_list) const override;
666 
667  private:
668  std::shared_ptr<Analyzer::Expr> arg; // the argument left of IN
669  const std::list<std::shared_ptr<Analyzer::Expr>>
670  value_list; // the list of values right of IN
671 };
672 
673 /*
674  * @type InIntegerSet
675  * @brief represents predicate expr IN (v1, v2, ...) for the case where the right
676  * hand side is a list of integers or dictionary-encoded strings generated
677  * by a IN subquery. Avoids the overhead of storing a list of shared pointers
678  * to Constant objects, making it more suitable for IN sub-queries usage.
679  * v1, v2, ... are integers
680  */
681 class InIntegerSet : public Expr {
682  public:
683  InIntegerSet(const std::shared_ptr<const Analyzer::Expr> a,
684  const std::vector<int64_t>& values,
685  const bool not_null);
686 
687  const Expr* get_arg() const { return arg.get(); }
688 
689  const std::vector<int64_t>& get_value_list() const { return value_list; }
690 
691  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
692 
693  bool operator==(const Expr& rhs) const override;
694  std::string toString() const override;
695 
696  private:
697  const std::shared_ptr<const Analyzer::Expr> arg; // the argument left of IN
698  const std::vector<int64_t> value_list; // the list of values right of IN
699 };
700 
701 /*
702  * @type CharLengthExpr
703  * @brief expression for the CHAR_LENGTH expression.
704  * arg must evaluate to char, varchar or text.
705  */
706 class CharLengthExpr : public Expr {
707  public:
708  CharLengthExpr(std::shared_ptr<Analyzer::Expr> a, bool e)
709  : Expr(kINT, a->get_type_info().get_notnull()), arg(a), calc_encoded_length(e) {}
710  const Expr* get_arg() const { return arg.get(); }
711  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
713  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
714  void group_predicates(std::list<const Expr*>& scan_predicates,
715  std::list<const Expr*>& join_predicates,
716  std::list<const Expr*>& const_predicates) const override;
717  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
718  arg->collect_rte_idx(rte_idx_set);
719  }
721  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
722  colvar_set,
723  bool include_agg) const override {
724  arg->collect_column_var(colvar_set, include_agg);
725  }
726  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
727  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
728  return makeExpr<CharLengthExpr>(arg->rewrite_with_targetlist(tlist),
730  }
731  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
732  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
733  return makeExpr<CharLengthExpr>(arg->rewrite_with_child_targetlist(tlist),
735  }
736  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
737  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
738  return makeExpr<CharLengthExpr>(arg->rewrite_agg_to_var(tlist), calc_encoded_length);
739  }
740  bool operator==(const Expr& rhs) const override;
741  std::string toString() const override;
742  void find_expr(bool (*f)(const Expr*),
743  std::list<const Expr*>& expr_list) const override;
744 
745  private:
746  std::shared_ptr<Analyzer::Expr> arg;
748 };
749 
750 /*
751  * @type KeyForStringExpr
752  * @brief expression for the KEY_FOR_STRING expression.
753  * arg must be a dict encoded column, not str literal.
754  */
755 class KeyForStringExpr : public Expr {
756  public:
757  KeyForStringExpr(std::shared_ptr<Analyzer::Expr> a)
758  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
759  const Expr* get_arg() const { return arg.get(); }
760  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
761  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
762  void group_predicates(std::list<const Expr*>& scan_predicates,
763  std::list<const Expr*>& join_predicates,
764  std::list<const Expr*>& const_predicates) const override;
765  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
766  arg->collect_rte_idx(rte_idx_set);
767  }
769  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
770  colvar_set,
771  bool include_agg) const override {
772  arg->collect_column_var(colvar_set, include_agg);
773  }
774  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
775  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
776  return makeExpr<KeyForStringExpr>(arg->rewrite_with_targetlist(tlist));
777  }
778  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
779  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
780  return makeExpr<KeyForStringExpr>(arg->rewrite_with_child_targetlist(tlist));
781  }
782  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
783  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
784  return makeExpr<KeyForStringExpr>(arg->rewrite_agg_to_var(tlist));
785  }
786  bool operator==(const Expr& rhs) const override;
787  std::string toString() const override;
788  void find_expr(bool (*f)(const Expr*),
789  std::list<const Expr*>& expr_list) const override;
790 
791  private:
792  std::shared_ptr<Analyzer::Expr> arg;
793 };
794 
795 /*
796  * @type SampleRatioExpr
797  * @brief expression for the SAMPLE_RATIO expression. Argument range is expected to be
798  * between 0 and 1.
799  */
800 class SampleRatioExpr : public Expr {
801  public:
802  SampleRatioExpr(std::shared_ptr<Analyzer::Expr> a)
803  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a) {}
804  const Expr* get_arg() const { return arg.get(); }
805  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
806  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
807  void group_predicates(std::list<const Expr*>& scan_predicates,
808  std::list<const Expr*>& join_predicates,
809  std::list<const Expr*>& const_predicates) const override;
810  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
811  arg->collect_rte_idx(rte_idx_set);
812  }
814  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
815  colvar_set,
816  bool include_agg) const override {
817  arg->collect_column_var(colvar_set, include_agg);
818  }
819  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
820  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
821  return makeExpr<SampleRatioExpr>(arg->rewrite_with_targetlist(tlist));
822  }
823  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
824  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
825  return makeExpr<SampleRatioExpr>(arg->rewrite_with_child_targetlist(tlist));
826  }
827  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
828  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
829  return makeExpr<SampleRatioExpr>(arg->rewrite_agg_to_var(tlist));
830  }
831  bool operator==(const Expr& rhs) const override;
832  std::string toString() const override;
833  void find_expr(bool (*f)(const Expr*),
834  std::list<const Expr*>& expr_list) const override;
835 
836  private:
837  std::shared_ptr<Analyzer::Expr> arg;
838 };
839 
840 /*
841  * @type CardinalityExpr
842  * @brief expression for the CARDINALITY expression.
843  * arg must evaluate to array (or multiset when supported).
844  */
845 class CardinalityExpr : public Expr {
846  public:
847  CardinalityExpr(std::shared_ptr<Analyzer::Expr> a)
848  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
849  const Expr* get_arg() const { return arg.get(); }
850  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
851  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
852  void group_predicates(std::list<const Expr*>& scan_predicates,
853  std::list<const Expr*>& join_predicates,
854  std::list<const Expr*>& const_predicates) const override;
855  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
856  arg->collect_rte_idx(rte_idx_set);
857  }
859  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
860  colvar_set,
861  bool include_agg) const override {
862  arg->collect_column_var(colvar_set, include_agg);
863  }
864  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
865  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
866  return makeExpr<CardinalityExpr>(arg->rewrite_with_targetlist(tlist));
867  }
868  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
869  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
870  return makeExpr<CardinalityExpr>(arg->rewrite_with_child_targetlist(tlist));
871  }
872  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
873  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
874  return makeExpr<CardinalityExpr>(arg->rewrite_agg_to_var(tlist));
875  }
876  bool operator==(const Expr& rhs) const override;
877  std::string toString() const override;
878  void find_expr(bool (*f)(const Expr*),
879  std::list<const Expr*>& expr_list) const override;
880 
881  private:
882  std::shared_ptr<Analyzer::Expr> arg;
883 };
884 
885 /*
886  * @type LikeExpr
887  * @brief expression for the LIKE predicate.
888  * arg must evaluate to char, varchar or text.
889  */
890 class LikeExpr : public Expr {
891  public:
892  LikeExpr(std::shared_ptr<Analyzer::Expr> a,
893  std::shared_ptr<Analyzer::Expr> l,
894  std::shared_ptr<Analyzer::Expr> e,
895  bool i,
896  bool s)
897  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
898  , arg(a)
899  , like_expr(l)
900  , escape_expr(e)
901  , is_ilike(i)
902  , is_simple(s) {}
903  const Expr* get_arg() const { return arg.get(); }
904  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
905  const Expr* get_like_expr() const { return like_expr.get(); }
906  const Expr* get_escape_expr() const { return escape_expr.get(); }
907  bool get_is_ilike() const { return is_ilike; }
908  bool get_is_simple() const { return is_simple; }
909  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
910  void group_predicates(std::list<const Expr*>& scan_predicates,
911  std::list<const Expr*>& join_predicates,
912  std::list<const Expr*>& const_predicates) const override;
913  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
914  arg->collect_rte_idx(rte_idx_set);
915  }
917  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
918  colvar_set,
919  bool include_agg) const override {
920  arg->collect_column_var(colvar_set, include_agg);
921  }
922  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
923  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
924  return makeExpr<LikeExpr>(arg->rewrite_with_targetlist(tlist),
925  like_expr->deep_copy(),
926  escape_expr ? escape_expr->deep_copy() : nullptr,
927  is_ilike,
928  is_simple);
929  }
930  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
931  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
932  return makeExpr<LikeExpr>(arg->rewrite_with_child_targetlist(tlist),
933  like_expr->deep_copy(),
934  escape_expr ? escape_expr->deep_copy() : nullptr,
935  is_ilike,
936  is_simple);
937  }
938  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
939  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
940  return makeExpr<LikeExpr>(arg->rewrite_agg_to_var(tlist),
941  like_expr->deep_copy(),
942  escape_expr ? escape_expr->deep_copy() : nullptr,
943  is_ilike,
944  is_simple);
945  }
946  bool operator==(const Expr& rhs) const override;
947  std::string toString() const override;
948  void find_expr(bool (*f)(const Expr*),
949  std::list<const Expr*>& expr_list) const override;
950 
951  private:
952  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of LIKE
953  std::shared_ptr<Analyzer::Expr> like_expr; // expression that evaluates to like string
954  std::shared_ptr<Analyzer::Expr>
955  escape_expr; // expression that evaluates to escape string, can be nullptr
956  bool is_ilike; // is this ILIKE?
957  bool is_simple; // is this simple, meaning we can use fast path search (fits '%str%'
958  // pattern with no inner '%','_','[',']'
959 };
960 
961 /*
962  * @type RegexpExpr
963  * @brief expression for REGEXP.
964  * arg must evaluate to char, varchar or text.
965  */
966 class RegexpExpr : public Expr {
967  public:
968  RegexpExpr(std::shared_ptr<Analyzer::Expr> a,
969  std::shared_ptr<Analyzer::Expr> p,
970  std::shared_ptr<Analyzer::Expr> e)
971  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
972  , arg(a)
973  , pattern_expr(p)
974  , escape_expr(e) {}
975  const Expr* get_arg() const { return arg.get(); }
976  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
977  const Expr* get_pattern_expr() const { return pattern_expr.get(); }
978  const Expr* get_escape_expr() const { return escape_expr.get(); }
979  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
980  void group_predicates(std::list<const Expr*>& scan_predicates,
981  std::list<const Expr*>& join_predicates,
982  std::list<const Expr*>& const_predicates) const override;
983  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
984  arg->collect_rte_idx(rte_idx_set);
985  }
987  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
988  colvar_set,
989  bool include_agg) const override {
990  arg->collect_column_var(colvar_set, include_agg);
991  }
992  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
993  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
994  return makeExpr<RegexpExpr>(arg->rewrite_with_targetlist(tlist),
995  pattern_expr->deep_copy(),
996  escape_expr ? escape_expr->deep_copy() : nullptr);
997  }
998  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
999  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1000  return makeExpr<RegexpExpr>(arg->rewrite_with_child_targetlist(tlist),
1001  pattern_expr->deep_copy(),
1002  escape_expr ? escape_expr->deep_copy() : nullptr);
1003  }
1004  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1005  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1006  return makeExpr<RegexpExpr>(arg->rewrite_agg_to_var(tlist),
1007  pattern_expr->deep_copy(),
1008  escape_expr ? escape_expr->deep_copy() : nullptr);
1009  }
1010  bool operator==(const Expr& rhs) const override;
1011  std::string toString() const override;
1012  void find_expr(bool (*f)(const Expr*),
1013  std::list<const Expr*>& expr_list) const override;
1014 
1015  private:
1016  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of REGEXP
1017  std::shared_ptr<Analyzer::Expr>
1018  pattern_expr; // expression that evaluates to pattern string
1019  std::shared_ptr<Analyzer::Expr>
1020  escape_expr; // expression that evaluates to escape string, can be nullptr
1021 };
1022 
1023 /*
1024  * @type WidthBucketExpr
1025  * @brief expression for width_bucket functions.
1026  */
1027 class WidthBucketExpr : public Expr {
1028  public:
1029  WidthBucketExpr(const std::shared_ptr<Analyzer::Expr> target_value,
1030  const std::shared_ptr<Analyzer::Expr> lower_bound,
1031  const std::shared_ptr<Analyzer::Expr> upper_bound,
1032  const std::shared_ptr<Analyzer::Expr> partition_count)
1033  : Expr(kINT, target_value->get_type_info().get_notnull())
1034  , target_value_(target_value)
1035  , lower_bound_(lower_bound)
1036  , upper_bound_(upper_bound)
1037  , partition_count_(partition_count)
1040  const Expr* get_target_value() const { return target_value_.get(); }
1041  const Expr* get_lower_bound() const { return lower_bound_.get(); }
1042  const Expr* get_upper_bound() const { return upper_bound_.get(); }
1043  const Expr* get_partition_count() const { return partition_count_.get(); }
1044  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1045  void group_predicates(std::list<const Expr*>& scan_predicates,
1046  std::list<const Expr*>& join_predicates,
1047  std::list<const Expr*>& const_predicates) const override;
1048  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1049  target_value_->collect_rte_idx(rte_idx_set);
1050  }
1052  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1053  colvar_set,
1054  bool include_agg) const override {
1055  target_value_->collect_column_var(colvar_set, include_agg);
1056  }
1057  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1058  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1059  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_targetlist(tlist),
1060  lower_bound_,
1061  upper_bound_,
1063  }
1064  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1065  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1066  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_child_targetlist(tlist),
1067  lower_bound_,
1068  upper_bound_,
1070  }
1071  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1072  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1073  return makeExpr<WidthBucketExpr>(target_value_->rewrite_agg_to_var(tlist),
1074  lower_bound_,
1075  upper_bound_,
1077  }
1078  double get_bound_val(const Analyzer::Expr* bound_expr) const;
1079  int32_t get_partition_count_val() const;
1080  template <typename T>
1081  int32_t compute_bucket(T target_const_val, SQLTypeInfo& ti) const {
1082  // this utility function is useful for optimizing expression range decision
1083  // for an expression depending on width_bucket expr
1084  T null_val = ti.is_integer() ? inline_int_null_val(ti) : inline_fp_null_val(ti);
1085  double lower_bound_val = get_bound_val(lower_bound_.get());
1086  double upper_bound_val = get_bound_val(upper_bound_.get());
1087  auto partition_count_val = get_partition_count_val();
1088  if (target_const_val == null_val) {
1089  return INT32_MIN;
1090  }
1091  float res;
1092  if (lower_bound_val < upper_bound_val) {
1093  if (target_const_val < lower_bound_val) {
1094  return 0;
1095  } else if (target_const_val >= upper_bound_val) {
1096  return partition_count_val + 1;
1097  }
1098  double dividend = upper_bound_val - lower_bound_val;
1099  res = ((partition_count_val * (target_const_val - lower_bound_val)) / dividend) + 1;
1100  } else {
1101  if (target_const_val > lower_bound_val) {
1102  return 0;
1103  } else if (target_const_val <= upper_bound_val) {
1104  return partition_count_val + 1;
1105  }
1106  double dividend = lower_bound_val - upper_bound_val;
1107  res = ((partition_count_val * (lower_bound_val - target_const_val)) / dividend) + 1;
1108  }
1109  return res;
1110  }
1111  bool operator==(const Expr& rhs) const override;
1112  std::string toString() const override;
1113  void find_expr(bool (*f)(const Expr*),
1114  std::list<const Expr*>& expr_list) const override;
1117  void set_constant_expr() const { constant_expr_ = true; }
1118  bool is_constant_expr() const { return constant_expr_; }
1119 
1120  private:
1121  std::shared_ptr<Analyzer::Expr> target_value_; // target value expression
1122  std::shared_ptr<Analyzer::Expr> lower_bound_; // lower_bound
1123  std::shared_ptr<Analyzer::Expr> upper_bound_; // upper_bound
1124  std::shared_ptr<Analyzer::Expr> partition_count_; // partition_count
1125  // true if lower, upper and partition count exprs are constant
1126  mutable bool constant_expr_;
1127  // true if we can skip oob check and is determined within compile time
1129 };
1130 
1131 /*
1132  * @type LikelihoodExpr
1133  * @brief expression for LIKELY and UNLIKELY boolean identity functions.
1134  */
1135 class LikelihoodExpr : public Expr {
1136  public:
1137  LikelihoodExpr(std::shared_ptr<Analyzer::Expr> a, float l = 0.5)
1138  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a), likelihood(l) {}
1139  const Expr* get_arg() const { return arg.get(); }
1140  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1141  float get_likelihood() const { return likelihood; }
1142  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1143  void group_predicates(std::list<const Expr*>& scan_predicates,
1144  std::list<const Expr*>& join_predicates,
1145  std::list<const Expr*>& const_predicates) const override;
1146  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1147  arg->collect_rte_idx(rte_idx_set);
1148  }
1150  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1151  colvar_set,
1152  bool include_agg) const override {
1153  arg->collect_column_var(colvar_set, include_agg);
1154  }
1155  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1156  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1157  return makeExpr<LikelihoodExpr>(arg->rewrite_with_targetlist(tlist), likelihood);
1158  }
1159  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1160  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1161  return makeExpr<LikelihoodExpr>(arg->rewrite_with_child_targetlist(tlist),
1162  likelihood);
1163  }
1164  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1165  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1166  return makeExpr<LikelihoodExpr>(arg->rewrite_agg_to_var(tlist), likelihood);
1167  }
1168  bool operator==(const Expr& rhs) const override;
1169  std::string toString() const override;
1170  void find_expr(bool (*f)(const Expr*),
1171  std::list<const Expr*>& expr_list) const override;
1172 
1173  private:
1174  std::shared_ptr<Analyzer::Expr> arg; // the argument to LIKELY, UNLIKELY
1175  float likelihood;
1176 };
1177 
1178 /*
1179  * @type AggExpr
1180  * @brief expression for builtin SQL aggregates.
1181  */
1182 class AggExpr : public Expr {
1183  public:
1185  SQLAgg a,
1186  std::shared_ptr<Analyzer::Expr> g,
1187  bool d,
1188  std::shared_ptr<Analyzer::Constant> e)
1189  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), arg1(e) {}
1191  SQLAgg a,
1192  Expr* g,
1193  bool d,
1194  std::shared_ptr<Analyzer::Constant> e,
1195  int idx)
1196  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1197  , aggtype(a)
1198  , arg(g)
1199  , is_distinct(d)
1200  , arg1(e) {}
1201  SQLAgg get_aggtype() const { return aggtype; }
1202  Expr* get_arg() const { return arg.get(); }
1203  std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1204  bool get_is_distinct() const { return is_distinct; }
1205  std::shared_ptr<Analyzer::Constant> get_arg1() const { return arg1; }
1206  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1207  void group_predicates(std::list<const Expr*>& scan_predicates,
1208  std::list<const Expr*>& join_predicates,
1209  std::list<const Expr*>& const_predicates) const override;
1210  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1211  if (arg) {
1212  arg->collect_rte_idx(rte_idx_set);
1213  }
1214  };
1216  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1217  colvar_set,
1218  bool include_agg) const override {
1219  if (include_agg && arg != nullptr) {
1220  arg->collect_column_var(colvar_set, include_agg);
1221  }
1222  }
1223  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1224  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1225  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1226  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1227  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1228  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1229  bool operator==(const Expr& rhs) const override;
1230  std::string toString() const override;
1231  void find_expr(bool (*f)(const Expr*),
1232  std::list<const Expr*>& expr_list) const override;
1233 
1234  private:
1235  SQLAgg aggtype; // aggregate type: kAVG, kMIN, kMAX, kSUM, kCOUNT
1236  std::shared_ptr<Analyzer::Expr> arg; // argument to aggregate
1237  bool is_distinct; // true only if it is for COUNT(DISTINCT x)
1238  // APPROX_COUNT_DISTINCT error_rate, APPROX_QUANTILE quantile
1239  std::shared_ptr<Analyzer::Constant> arg1;
1240 };
1241 
1242 /*
1243  * @type CaseExpr
1244  * @brief the CASE-WHEN-THEN-ELSE expression
1245  */
1246 class CaseExpr : public Expr {
1247  public:
1249  bool has_agg,
1250  const std::list<std::pair<std::shared_ptr<Analyzer::Expr>,
1251  std::shared_ptr<Analyzer::Expr>>>& w,
1252  std::shared_ptr<Analyzer::Expr> e)
1253  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
1254  const std::list<
1255  std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>&
1257  return expr_pair_list;
1258  }
1259  const Expr* get_else_expr() const { return else_expr.get(); }
1260  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1261  void check_group_by(
1262  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1263  void group_predicates(std::list<const Expr*>& scan_predicates,
1264  std::list<const Expr*>& join_predicates,
1265  std::list<const Expr*>& const_predicates) const override;
1266  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1267  void collect_column_var(
1268  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1269  colvar_set,
1270  bool include_agg) const override;
1271  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1272  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1273  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1274  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1275  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1276  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1277  bool operator==(const Expr& rhs) const override;
1278  std::string toString() const override;
1279  void find_expr(bool (*f)(const Expr*),
1280  std::list<const Expr*>& expr_list) const override;
1281  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
1282  void get_domain(DomainSet& domain_set) const override;
1283 
1284  private:
1285  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1286  expr_pair_list; // a pair of expressions for each WHEN expr1 THEN expr2. expr1
1287  // must be of boolean type. all expr2's must be of compatible
1288  // types and will be promoted to the common type.
1289  std::shared_ptr<Analyzer::Expr> else_expr; // expression for ELSE. nullptr if omitted.
1290 };
1291 
1292 /*
1293  * @type ExtractExpr
1294  * @brief the EXTRACT expression
1295  */
1296 class ExtractExpr : public Expr {
1297  public:
1299  bool has_agg,
1300  ExtractField f,
1301  std::shared_ptr<Analyzer::Expr> e)
1302  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1303  ExtractField get_field() const { return field_; }
1304  const Expr* get_from_expr() const { return from_expr_.get(); }
1305  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1306  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1307  void check_group_by(
1308  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1309  void group_predicates(std::list<const Expr*>& scan_predicates,
1310  std::list<const Expr*>& join_predicates,
1311  std::list<const Expr*>& const_predicates) const override;
1312  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1313  void collect_column_var(
1314  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1315  colvar_set,
1316  bool include_agg) const override;
1317  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1318  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1319  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1320  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1321  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1322  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1323  bool operator==(const Expr& rhs) const override;
1324  std::string toString() const override;
1325  void find_expr(bool (*f)(const Expr*),
1326  std::list<const Expr*>& expr_list) const override;
1327 
1328  private:
1330  std::shared_ptr<Analyzer::Expr> from_expr_;
1331 };
1332 
1333 /*
1334  * @type DateaddExpr
1335  * @brief the DATEADD expression
1336  */
1337 class DateaddExpr : public Expr {
1338  public:
1340  const DateaddField f,
1341  const std::shared_ptr<Analyzer::Expr> number,
1342  const std::shared_ptr<Analyzer::Expr> datetime)
1343  : Expr(ti, false), field_(f), number_(number), datetime_(datetime) {}
1344  DateaddField get_field() const { return field_; }
1345  const Expr* get_number_expr() const { return number_.get(); }
1346  const Expr* get_datetime_expr() const { return datetime_.get(); }
1347  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1348  void check_group_by(
1349  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1350  void group_predicates(std::list<const Expr*>& scan_predicates,
1351  std::list<const Expr*>& join_predicates,
1352  std::list<const Expr*>& const_predicates) const override;
1353  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1354  void collect_column_var(
1355  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1356  colvar_set,
1357  bool include_agg) const override;
1358  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1359  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1360  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1361  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1362  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1363  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1364  bool operator==(const Expr& rhs) const override;
1365  std::string toString() const override;
1366  void find_expr(bool (*f)(const Expr*),
1367  std::list<const Expr*>& expr_list) const override;
1368 
1369  private:
1371  const std::shared_ptr<Analyzer::Expr> number_;
1372  const std::shared_ptr<Analyzer::Expr> datetime_;
1373 };
1374 
1375 /*
1376  * @type DatediffExpr
1377  * @brief the DATEDIFF expression
1378  */
1379 class DatediffExpr : public Expr {
1380  public:
1382  const DatetruncField f,
1383  const std::shared_ptr<Analyzer::Expr> start,
1384  const std::shared_ptr<Analyzer::Expr> end)
1385  : Expr(ti, false), field_(f), start_(start), end_(end) {}
1386  DatetruncField get_field() const { return field_; }
1387  const Expr* get_start_expr() const { return start_.get(); }
1388  const Expr* get_end_expr() const { return end_.get(); }
1389  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1390  void check_group_by(
1391  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1392  void group_predicates(std::list<const Expr*>& scan_predicates,
1393  std::list<const Expr*>& join_predicates,
1394  std::list<const Expr*>& const_predicates) const override;
1395  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1396  void collect_column_var(
1397  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1398  colvar_set,
1399  bool include_agg) const override;
1400  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1401  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1402  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1403  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1404  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1405  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1406  bool operator==(const Expr& rhs) const override;
1407  std::string toString() const override;
1408  void find_expr(bool (*f)(const Expr*),
1409  std::list<const Expr*>& expr_list) const override;
1410 
1411  private:
1413  const std::shared_ptr<Analyzer::Expr> start_;
1414  const std::shared_ptr<Analyzer::Expr> end_;
1415 };
1416 
1417 /*
1418  * @type DatetruncExpr
1419  * @brief the DATE_TRUNC expression
1420  */
1421 class DatetruncExpr : public Expr {
1422  public:
1424  bool has_agg,
1425  DatetruncField f,
1426  std::shared_ptr<Analyzer::Expr> e)
1427  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1428  DatetruncField get_field() const { return field_; }
1429  const Expr* get_from_expr() const { return from_expr_.get(); }
1430  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1431  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1432  void check_group_by(
1433  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1434  void group_predicates(std::list<const Expr*>& scan_predicates,
1435  std::list<const Expr*>& join_predicates,
1436  std::list<const Expr*>& const_predicates) const override;
1437  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1438  void collect_column_var(
1439  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1440  colvar_set,
1441  bool include_agg) const override;
1442  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1443  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1444  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1445  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1446  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1447  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1448  bool operator==(const Expr& rhs) const override;
1449  std::string toString() const override;
1450  void find_expr(bool (*f)(const Expr*),
1451  std::list<const Expr*>& expr_list) const override;
1452 
1453  private:
1455  std::shared_ptr<Analyzer::Expr> from_expr_;
1456 };
1457 
1463 class StringOper : public Expr {
1464  public:
1465  // Todo(todd): Set nullability based on literals too
1466 
1468 
1470  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1472 
1474  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1475  const size_t min_args,
1476  const std::vector<OperandTypeFamily>& expected_type_families,
1477  const std::vector<std::string>& arg_names)
1479  check_operand_types(min_args, expected_type_families, arg_names);
1480  }
1481 
1483  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1484  const std::vector<std::shared_ptr<Analyzer::Expr>>& chained_string_op_exprs)
1486  , kind_(kind)
1487  , args_(args)
1488  , chained_string_op_exprs_(chained_string_op_exprs) {}
1489 
1490  StringOper(const StringOper& other_string_oper)
1491  : Expr(other_string_oper.get_type_info()) {
1492  kind_ = other_string_oper.kind_;
1493  args_ = other_string_oper.args_;
1495  }
1496 
1497  StringOper(const std::shared_ptr<StringOper>& other_string_oper)
1498  : Expr(other_string_oper->get_type_info()) {
1499  kind_ = other_string_oper->kind_;
1500  args_ = other_string_oper->args_;
1501  chained_string_op_exprs_ = other_string_oper->chained_string_op_exprs_;
1502  }
1503 
1504  SqlStringOpKind get_kind() const { return kind_; }
1505 
1506  size_t getArity() const { return args_.size(); }
1507 
1508  size_t getLiteralsArity() const {
1509  size_t num_literals{0UL};
1510  for (const auto& arg : args_) {
1511  if (dynamic_cast<const Constant*>(arg.get())) {
1512  num_literals++;
1513  }
1514  }
1515  return num_literals;
1516  }
1517 
1518  const Expr* getArg(const size_t i) const {
1519  CHECK_LT(i, args_.size());
1520  return args_[i].get();
1521  }
1522 
1523  std::shared_ptr<Analyzer::Expr> getOwnArg(const size_t i) const {
1524  CHECK_LT(i, args_.size());
1525  return args_[i];
1526  }
1527 
1528  std::vector<std::shared_ptr<Analyzer::Expr>> getOwnArgs() const { return args_; }
1529 
1530  std::vector<std::shared_ptr<Analyzer::Expr>> getChainedStringOpExprs() const {
1531  return chained_string_op_exprs_;
1532  }
1533 
1534  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1535 
1536  void collect_column_var(
1537  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1538  colvar_set,
1539  bool include_agg) const override;
1540 
1541  bool hasNoneEncodedTextArg() const {
1542  if (args_.empty()) {
1543  return false;
1544  }
1545  const auto& arg0_ti = args_[0]->get_type_info();
1546  if (!arg0_ti.is_string()) {
1547  return false;
1548  }
1549  if (arg0_ti.is_none_encoded_string()) {
1550  return true;
1551  }
1552  CHECK(arg0_ti.is_dict_encoded_string());
1553  return arg0_ti.get_comp_param() == TRANSIENT_DICT_ID;
1554  }
1555 
1563  bool hasSingleDictEncodedColInput() const;
1564 
1565  std::vector<size_t> getLiteralArgIndexes() const;
1566 
1567  using LiteralArgMap = std::map<size_t, std::pair<SQLTypes, Datum>>;
1568 
1569  LiteralArgMap getLiteralArgs() const;
1570 
1571  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1572  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1573 
1574  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1575  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1576 
1577  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1578  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1579 
1580  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1581 
1582  void group_predicates(std::list<const Expr*>& scan_predicates,
1583  std::list<const Expr*>& join_predicates,
1584  std::list<const Expr*>& const_predicates) const override;
1585 
1586  bool operator==(const Expr& rhs) const override;
1587 
1588  std::string toString() const override;
1589 
1590  void find_expr(bool (*f)(const Expr*),
1591  std::list<const Expr*>& expr_list) const override;
1592 
1593  virtual size_t getMinArgs() const {
1594  CHECK(false);
1595  return {};
1596  }
1597  virtual std::vector<OperandTypeFamily> getExpectedTypeFamilies() const {
1598  CHECK(false);
1599  return {};
1600  }
1601  virtual std::vector<std::string> getArgNames() const {
1602  CHECK(false);
1603  return {};
1604  }
1605 
1606  private:
1608  const std::vector<std::shared_ptr<Analyzer::Expr>> args);
1609 
1610  void check_operand_types(const size_t min_args,
1611  const std::vector<OperandTypeFamily>& expected_type_families,
1612  const std::vector<std::string>& arg_names,
1613  const bool dict_encoded_cols_only = true,
1614  const bool cols_first_arg_only = true) const;
1615 
1617  std::vector<std::shared_ptr<Analyzer::Expr>> args_;
1618  std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_;
1619 };
1620 
1621 class LowerStringOper : public StringOper {
1622  public:
1623  LowerStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1625  {operand},
1626  getMinArgs(),
1629 
1630  LowerStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1632  operands,
1633  getMinArgs(),
1635  getArgNames()) {}
1636 
1637  LowerStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1638  : StringOper(string_oper) {}
1639 
1640  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1641 
1642  size_t getMinArgs() const override { return 1UL; }
1643 
1644  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1646  }
1647 
1648  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1649 };
1650 class UpperStringOper : public StringOper {
1651  public:
1652  UpperStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1654  {operand},
1655  getMinArgs(),
1658 
1659  UpperStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1661  operands,
1662  getMinArgs(),
1664  getArgNames()) {}
1665 
1666  UpperStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1667  : StringOper(string_oper) {}
1668 
1669  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1670 
1671  size_t getMinArgs() const override { return 1UL; }
1672 
1673  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1675  }
1676 
1677  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1678 };
1679 
1681  public:
1682  InitCapStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1684  {operand},
1685  getMinArgs(),
1688 
1689  InitCapStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1691  operands,
1692  getMinArgs(),
1694  getArgNames()) {}
1695 
1696  InitCapStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1697  : StringOper(string_oper) {}
1698 
1699  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1700 
1701  size_t getMinArgs() const override { return 1UL; }
1702 
1703  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1705  }
1706  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1707 };
1708 
1710  public:
1711  ReverseStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1713  {operand},
1714  getMinArgs(),
1717 
1718  ReverseStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1720  operands,
1721  getMinArgs(),
1723  getArgNames()) {}
1724 
1725  ReverseStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1726  : StringOper(string_oper) {}
1727 
1728  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1729 
1730  size_t getMinArgs() const override { return 1UL; }
1731 
1732  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1734  }
1735  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1736 };
1737 
1739  public:
1740  RepeatStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1741  const std::shared_ptr<Analyzer::Expr>& num_repeats)
1743  {operand, num_repeats},
1744  getMinArgs(),
1747 
1748  RepeatStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1750  operands,
1751  getMinArgs(),
1753  getArgNames()) {}
1754 
1755  RepeatStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1756  : StringOper(string_oper) {}
1757 
1758  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1759 
1760  size_t getMinArgs() const override { return 2UL; }
1761 
1762  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1764  }
1765  std::vector<std::string> getArgNames() const override {
1766  return {"operand", "num_repeats"};
1767  }
1768 };
1769 
1771  public:
1772  ConcatStringOper(const std::shared_ptr<Analyzer::Expr>& left_operand,
1773  const std::shared_ptr<Analyzer::Expr>& right_operand)
1774  : StringOper(
1775  ConcatStringOper::get_concat_ordered_kind({left_operand, right_operand}),
1776  ConcatStringOper::normalize_operands({left_operand, right_operand}),
1777  getMinArgs(),
1780 
1781  ConcatStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1784  getMinArgs(),
1786  getArgNames()) {}
1787 
1788  ConcatStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1789  : StringOper(string_oper) {}
1790 
1791  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1792 
1793  size_t getMinArgs() const override { return 2UL; }
1794 
1795  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1797  }
1798  std::vector<std::string> getArgNames() const override {
1799  return {"left operand", "right operand"};
1800  }
1801 
1802  private:
1804  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
1805 
1806  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
1807  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
1808 };
1809 
1810 class PadStringOper : public StringOper {
1811  public:
1812  PadStringOper(const SqlStringOpKind pad_op_kind,
1813  const std::shared_ptr<Analyzer::Expr>& operand,
1814  const std::shared_ptr<Analyzer::Expr>& padded_length,
1815  const std::shared_ptr<Analyzer::Expr>& padding_str)
1817  {operand, padded_length, padding_str},
1818  getMinArgs(),
1821 
1822  PadStringOper(const SqlStringOpKind pad_op_kind,
1823  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1825  operands,
1826  getMinArgs(),
1828  getArgNames()) {}
1829 
1830  PadStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1831  : StringOper(string_oper) {}
1832 
1833  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1834 
1835  size_t getMinArgs() const override { return 3UL; }
1836 
1837  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1841  }
1842  std::vector<std::string> getArgNames() const override {
1843  return {"operand", "padded length", "padding string"};
1844  }
1845 
1846  private:
1848 };
1849 
1850 class TrimStringOper : public StringOper {
1851  public:
1852  TrimStringOper(const SqlStringOpKind trim_op_kind,
1853  const std::shared_ptr<Analyzer::Expr>& operand,
1854  const std::shared_ptr<Analyzer::Expr>& trim_chars)
1856  {operand, trim_chars},
1857  getMinArgs(),
1860 
1861  TrimStringOper(const SqlStringOpKind trim_op_kind,
1862  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1863  : StringOper(TrimStringOper::get_and_validate_trim_op_kind(trim_op_kind, operands),
1864  TrimStringOper::normalize_operands(operands, trim_op_kind),
1865  getMinArgs(),
1867  getArgNames()) {}
1868 
1869  TrimStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1870  : StringOper(string_oper) {}
1871 
1872  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1873 
1874  size_t getMinArgs() const override { return 2UL; }
1875 
1876  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1878  }
1879  std::vector<std::string> getArgNames() const override {
1880  return {"operand", "trim_chars"};
1881  }
1882 
1883  private:
1885  if (!(trim_op_kind == SqlStringOpKind::TRIM ||
1886  trim_op_kind == SqlStringOpKind::LTRIM ||
1887  trim_op_kind == SqlStringOpKind::RTRIM)) {
1888  // Arguably should CHECK here
1889  throw std::runtime_error("Invalid trim type supplied to TRIM operator");
1890  }
1891  return trim_op_kind;
1892  }
1893 
1895  const SqlStringOpKind trim_op_kind_maybe,
1896  const std::vector<std::shared_ptr<Analyzer::Expr>>& args);
1897 
1898  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
1899  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands,
1900  const SqlStringOpKind string_op_kind);
1901 };
1902 
1904  public:
1905  SubstringStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1906  const std::shared_ptr<Analyzer::Expr>& start_pos)
1908  {operand, start_pos},
1909  getMinArgs(),
1912 
1913  SubstringStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1914  const std::shared_ptr<Analyzer::Expr>& start_pos,
1915  const std::shared_ptr<Analyzer::Expr>& length)
1917  {operand, start_pos, length},
1918  getMinArgs(),
1921 
1922  SubstringStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1924  operands,
1925  getMinArgs(),
1927  getArgNames()) {}
1928 
1929  SubstringStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1930  : StringOper(string_oper) {}
1931 
1932  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1933 
1934  size_t getMinArgs() const override { return 2UL; }
1935 
1936  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1939  OperandTypeFamily::INT_FAMILY};
1940  }
1941  std::vector<std::string> getArgNames() const override {
1942  return {"operand", "start position", "substring length"};
1943  }
1944 };
1945 
1947  public:
1948  OverlayStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1949  const std::shared_ptr<Analyzer::Expr>& replacing_str,
1950  const std::shared_ptr<Analyzer::Expr>& start_pos)
1952  {operand, replacing_str, start_pos},
1953  getMinArgs(),
1956 
1957  OverlayStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1958  const std::shared_ptr<Analyzer::Expr>& replacing_str,
1959  const std::shared_ptr<Analyzer::Expr>& start_pos,
1960  const std::shared_ptr<Analyzer::Expr>& replacing_length)
1962  {operand, replacing_str, start_pos, replacing_length},
1963  getMinArgs(),
1966 
1967  OverlayStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1968  : StringOper(string_oper) {}
1969 
1970  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1971 
1972  OverlayStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1974  operands,
1975  getMinArgs(),
1977  getArgNames()) {}
1978 
1979  size_t getMinArgs() const override { return 3UL; }
1980 
1981  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1985  OperandTypeFamily::INT_FAMILY};
1986  }
1987  std::vector<std::string> getArgNames() const override {
1988  return {"operand", "replacing string", "start posistion", "replacing length"};
1989  }
1990 };
1991 
1993  public:
1994  ReplaceStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1995  const std::shared_ptr<Analyzer::Expr>& search_pattern,
1996  const std::shared_ptr<Analyzer::Expr>& replacing_str)
1998  {operand, search_pattern, replacing_str},
1999  getMinArgs(),
2002 
2003  ReplaceStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2005  operands,
2006  getMinArgs(),
2008  getArgNames()) {}
2009 
2010  ReplaceStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2011  : StringOper(string_oper) {}
2012 
2013  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2014 
2015  size_t getMinArgs() const override { return 3UL; }
2016 
2017  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2020  OperandTypeFamily::STRING_FAMILY};
2021  }
2022  std::vector<std::string> getArgNames() const override {
2023  return {"operand", "search pattern", "replacing string"};
2024  }
2025 };
2026 
2028  public:
2029  SplitPartStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2030  const std::shared_ptr<Analyzer::Expr>& delimiter,
2031  const std::shared_ptr<Analyzer::Expr>& split_index)
2033  {operand, delimiter, split_index},
2034  getMinArgs(),
2037 
2038  SplitPartStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2040  operands,
2041  getMinArgs(),
2043  getArgNames()) {}
2044 
2045  SplitPartStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2046  : StringOper(string_oper) {}
2047 
2048  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2049 
2050  size_t getMinArgs() const override { return 3UL; }
2051 
2052  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2056  }
2057  std::vector<std::string> getArgNames() const override {
2058  return {"operand", "delimiter", "split index"};
2059  }
2060 };
2061 
2063  public:
2064  RegexpReplaceStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2065  const std::shared_ptr<Analyzer::Expr>& regex_pattern,
2066  const std::shared_ptr<Analyzer::Expr>& replacing_str,
2067  const std::shared_ptr<Analyzer::Expr>& start_pos,
2068  const std::shared_ptr<Analyzer::Expr>& occurrence,
2069  const std::shared_ptr<Analyzer::Expr>& regex_params)
2070  : StringOper(
2072  {operand, regex_pattern, replacing_str, start_pos, occurrence, regex_params},
2073  getMinArgs(),
2076 
2077  RegexpReplaceStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2079  operands,
2080  getMinArgs(),
2082  getArgNames()) {}
2083 
2084  RegexpReplaceStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2085  : StringOper(string_oper) {}
2086 
2087  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2088 
2089  size_t getMinArgs() const override { return 6UL; }
2090 
2091  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2097  OperandTypeFamily::STRING_FAMILY};
2098  }
2099  std::vector<std::string> getArgNames() const override {
2100  return {"operand",
2101  "regex pattern",
2102  "replacing string",
2103  "start position",
2104  "occurrence",
2105  "regex parameters"};
2106  }
2107 };
2108 
2110  public:
2111  RegexpSubstrStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2112  const std::shared_ptr<Analyzer::Expr>& regex_pattern,
2113  const std::shared_ptr<Analyzer::Expr>& start_pos,
2114  const std::shared_ptr<Analyzer::Expr>& occurrence,
2115  const std::shared_ptr<Analyzer::Expr>& regex_params,
2116  const std::shared_ptr<Analyzer::Expr>& sub_match_group_idx)
2118  {operand,
2119  regex_pattern,
2120  start_pos,
2121  occurrence,
2122  regex_params,
2123  sub_match_group_idx},
2124  getMinArgs(),
2127 
2128  RegexpSubstrStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2130  operands,
2131  getMinArgs(),
2133  getArgNames()) {}
2134 
2135  RegexpSubstrStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2136  : StringOper(string_oper) {}
2137 
2138  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2139 
2140  size_t getMinArgs() const override { return 6UL; }
2141 
2142  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2148  OperandTypeFamily::INT_FAMILY};
2149  }
2150  std::vector<std::string> getArgNames() const override {
2151  return {"operand",
2152  "regex pattern",
2153  "start position",
2154  "occurrence",
2155  "regex parameters",
2156  "sub-match group index"};
2157  }
2158 };
2159 
2160 class FunctionOper : public Expr {
2161  public:
2163  const std::string& name,
2164  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
2165  : Expr(ti, false), name_(name), args_(args) {}
2166 
2167  std::string getName() const { return name_; }
2168 
2169  size_t getArity() const { return args_.size(); }
2170 
2171  const Analyzer::Expr* getArg(const size_t i) const {
2172  CHECK_LT(i, args_.size());
2173  return args_[i].get();
2174  }
2175 
2176  std::shared_ptr<Analyzer::Expr> getOwnArg(const size_t i) const {
2177  CHECK_LT(i, args_.size());
2178  return args_[i];
2179  }
2180 
2181  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2182  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
2183  void collect_column_var(
2184  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
2185  colvar_set,
2186  bool include_agg) const override;
2187 
2188  bool operator==(const Expr& rhs) const override;
2189  std::string toString() const override;
2190 
2191  private:
2192  const std::string name_;
2193  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
2194 };
2195 
2197  public:
2199  const SQLTypeInfo& ti,
2200  const std::string& name,
2201  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
2202  : FunctionOper(ti, name, args) {}
2203 
2204  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2205 
2206  bool operator==(const Expr& rhs) const override;
2207 };
2208 
2209 /*
2210  * @type OffsetInFragment
2211  * @brief The offset of a row in the current fragment. To be used by updates.
2212  */
2213 class OffsetInFragment : public Expr {
2214  public:
2216 
2217  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2218 
2219  bool operator==(const Expr& rhs) const override;
2220  std::string toString() const override;
2221 };
2222 
2223 /*
2224  * @type OrderEntry
2225  * @brief represents an entry in ORDER BY clause.
2226  */
2227 struct OrderEntry {
2228  OrderEntry(int t, bool d, bool nf) : tle_no(t), is_desc(d), nulls_first(nf){};
2230  std::string toString() const;
2231  void print() const { std::cout << toString(); }
2232  int tle_no; /* targetlist entry number: 1-based */
2233  bool is_desc; /* true if order is DESC */
2234  bool nulls_first; /* true if nulls are ordered first. otherwise last. */
2235 };
2236 
2237 /*
2238  * @type WindowFrame
2239  * @brief A window frame bound.
2240  */
2241 class WindowFrame : public Expr {
2242  public:
2244  const std::shared_ptr<Analyzer::Expr> bound_expr)
2245  : Expr(SQLTypeInfo(kVOID)), bound_type_(bound_type), bound_expr_(bound_expr) {}
2246 
2248 
2249  const Analyzer::Expr* getBoundExpr() const {
2250  CHECK(bound_expr_);
2251  return bound_expr_.get();
2252  }
2253 
2254  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2255 
2256  bool operator==(const Expr& rhs) const override;
2257 
2258  std::string toString() const override;
2259 
2260  private:
2262  const std::shared_ptr<Analyzer::Expr> bound_expr_;
2263 };
2264 
2265 /*
2266  * @type WindowFunction
2267  * @brief A window function.
2268  */
2269 class WindowFunction : public Expr {
2270  public:
2271  enum class FrameBoundType { NONE, ROW, RANGE };
2272 
2274  const SqlWindowFunctionKind kind,
2275  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
2276  const std::vector<std::shared_ptr<Analyzer::Expr>>& partition_keys,
2277  const std::vector<std::shared_ptr<Analyzer::Expr>>& order_keys,
2278  const FrameBoundType frame_bound_type,
2279  const std::shared_ptr<Expr> frame_start_bound,
2280  const std::shared_ptr<Expr> frame_end_bound,
2281  const std::vector<OrderEntry>& collation)
2282  : Expr(ti)
2283  , kind_(kind)
2284  , args_(args)
2285  , partition_keys_(partition_keys)
2286  , order_keys_(order_keys)
2287  , frame_bound_type_(frame_bound_type)
2288  , frame_start_bound_(frame_start_bound)
2289  , frame_end_bound_(frame_end_bound)
2290  , collation_(collation){};
2291 
2292  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2293 
2294  bool operator==(const Expr& rhs) const override;
2295  std::string toString() const override;
2296 
2298 
2299  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs() const { return args_; }
2300 
2301  const std::vector<std::shared_ptr<Analyzer::Expr>>& getPartitionKeys() const {
2302  return partition_keys_;
2303  }
2304 
2305  const std::vector<std::shared_ptr<Analyzer::Expr>>& getOrderKeys() const {
2306  return order_keys_;
2307  }
2308 
2310  std::shared_ptr<WindowFrame> frame_start_bound =
2311  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2312  CHECK(frame_start_bound);
2313  return frame_start_bound.get();
2314  }
2315 
2317  std::shared_ptr<WindowFrame> frame_end_bound =
2318  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2319  CHECK(frame_end_bound);
2320  return frame_end_bound.get();
2321  }
2322 
2323  const std::vector<OrderEntry>& getCollation() const { return collation_; }
2324 
2326  return frame_bound_type_;
2327  }
2328 
2330 
2332 
2334 
2335  private:
2337  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
2338  const std::vector<std::shared_ptr<Analyzer::Expr>> partition_keys_;
2339  const std::vector<std::shared_ptr<Analyzer::Expr>> order_keys_;
2341  const std::shared_ptr<Analyzer::Expr> frame_start_bound_;
2342  const std::shared_ptr<Analyzer::Expr> frame_end_bound_;
2343  const std::vector<OrderEntry> collation_;
2344 };
2345 
2346 /*
2347  * @type ArrayExpr
2348  * @brief Corresponds to ARRAY[] statements in SQL
2349  */
2350 
2351 class ArrayExpr : public Expr {
2352  public:
2353  ArrayExpr(SQLTypeInfo const& array_ti,
2354  ExpressionPtrVector const& array_exprs,
2355  bool is_null = false,
2356  bool local_alloc = false)
2357  : Expr(array_ti)
2358  , contained_expressions_(array_exprs)
2359  , local_alloc_(local_alloc)
2360  , is_null_(is_null) {}
2361 
2362  Analyzer::ExpressionPtr deep_copy() const override;
2363  std::string toString() const override;
2364  bool operator==(Expr const& rhs) const override;
2365  size_t getElementCount() const { return contained_expressions_.size(); }
2366  bool isLocalAlloc() const { return local_alloc_; }
2367  bool isNull() const { return is_null_; }
2368 
2369  const Analyzer::Expr* getElement(const size_t i) const {
2370  CHECK_LT(i, contained_expressions_.size());
2371  return contained_expressions_[i].get();
2372  }
2373 
2374  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
2375  void collect_column_var(
2376  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
2377  colvar_set,
2378  bool include_agg) const override;
2379 
2380  private:
2383  bool is_null_; // constant is NULL
2384 };
2385 
2386 /*
2387  * @type GeoUOper
2388  * @brief Geo unary operation
2389  */
2390 class GeoUOper : public Expr {
2391  public:
2393  const SQLTypeInfo& ti,
2394  const SQLTypeInfo& ti0,
2395  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
2396  : Expr(ti), op_(op), ti0_(ti0), args0_(args){};
2397 
2398  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2399 
2400  bool operator==(const Expr& rhs) const override;
2401  std::string toString() const override;
2402 
2404  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
2405  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
2406 
2407  private:
2409  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
2410  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
2411 };
2412 
2413 /*
2414  * @type GeoBinOper
2415  * @brief Geo binary operation
2416  */
2417 class GeoBinOper : public Expr {
2418  public:
2420  const SQLTypeInfo& ti,
2421  const SQLTypeInfo& ti0,
2422  const SQLTypeInfo& ti1,
2423  const std::vector<std::shared_ptr<Analyzer::Expr>>& args0,
2424  const std::vector<std::shared_ptr<Analyzer::Expr>>& args1)
2425  : Expr(ti), op_(op), ti0_(ti0), ti1_(ti1), args0_(args0), args1_(args1){};
2426 
2427  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2428 
2429  bool operator==(const Expr& rhs) const override;
2430  std::string toString() const override;
2431 
2433  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
2434  const SQLTypeInfo getTypeInfo1() const { return ti1_; }
2435  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
2436  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs1() const { return args1_; }
2437 
2438  private:
2440  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
2441  SQLTypeInfo ti1_; // Type of geo input 1
2442  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
2443  const std::vector<std::shared_ptr<Analyzer::Expr>> args1_;
2444 };
2445 
2446 /*
2447  * @type TargetEntry
2448  * @brief Target list defines a relational projection. It is a list of TargetEntry's.
2449  */
2451  public:
2452  TargetEntry(const std::string& n, std::shared_ptr<Analyzer::Expr> e, bool u)
2453  : resname(n), expr(e), unnest(u) {}
2454  virtual ~TargetEntry() {}
2455  const std::string& get_resname() const { return resname; }
2456  void set_resname(const std::string& name) { resname = name; }
2457  Expr* get_expr() const { return expr.get(); }
2458  std::shared_ptr<Expr> get_own_expr() const { return expr; }
2459  void set_expr(std::shared_ptr<Analyzer::Expr> e) { expr = e; }
2460  bool get_unnest() const { return unnest; }
2461  std::string toString() const;
2462  void print() const { std::cout << toString(); }
2463 
2464  private:
2465  std::string resname; // alias name, e.g., SELECT salary + bonus AS compensation,
2466  std::shared_ptr<Analyzer::Expr> expr; // expression to evaluate for the value
2467  bool unnest; // unnest a collection type
2468 };
2469 
2470 class RangeTableEntry;
2471 
2472 /*
2473  * @type Query
2474  * @brief parse tree for a query
2475  */
2476 class Query {
2477  public:
2479  : is_distinct(false)
2480  , where_predicate(nullptr)
2481  , having_predicate(nullptr)
2482  , order_by(nullptr)
2483  , next_query(nullptr)
2484  , is_unionall(false)
2485  , stmt_type(kSELECT)
2486  , num_aggs(0)
2487  , result_table_id(0)
2488  , limit(0)
2489  , offset(0) {}
2490  virtual ~Query();
2491  bool get_is_distinct() const { return is_distinct; }
2492  int get_num_aggs() const { return num_aggs; }
2493  const std::vector<std::shared_ptr<TargetEntry>>& get_targetlist() const {
2494  return targetlist;
2495  }
2496  std::vector<std::shared_ptr<TargetEntry>>& get_targetlist_nonconst() {
2497  return targetlist;
2498  }
2499  const std::vector<std::vector<std::shared_ptr<TargetEntry>>>& get_values_lists() const {
2500  return values_lists;
2501  }
2502  std::vector<std::vector<std::shared_ptr<TargetEntry>>>& get_values_lists() {
2503  return values_lists;
2504  }
2505  const std::vector<RangeTableEntry*>& get_rangetable() const { return rangetable; }
2506  const Expr* get_where_predicate() const { return where_predicate.get(); }
2507  const std::list<std::shared_ptr<Analyzer::Expr>>& get_group_by() const {
2508  return group_by;
2509  };
2510  const Expr* get_having_predicate() const { return having_predicate.get(); }
2511  const std::list<OrderEntry>* get_order_by() const { return order_by; }
2512  const Query* get_next_query() const { return next_query; }
2514  bool get_is_unionall() const { return is_unionall; }
2515  int get_result_table_id() const { return result_table_id; }
2516  const std::list<int>& get_result_col_list() const { return result_col_list; }
2517  void set_result_col_list(const std::list<int>& col_list) { result_col_list = col_list; }
2518  void set_result_table_id(int id) { result_table_id = id; }
2519  void set_is_distinct(bool d) { is_distinct = d; }
2520  void set_where_predicate(std::shared_ptr<Analyzer::Expr> p) { where_predicate = p; }
2521  void set_group_by(std::list<std::shared_ptr<Analyzer::Expr>>& g) { group_by = g; }
2522  void set_having_predicate(std::shared_ptr<Analyzer::Expr> p) { having_predicate = p; }
2523  void set_order_by(std::list<OrderEntry>* o) { order_by = o; }
2524  void set_next_query(Query* q) { next_query = q; }
2525  void set_is_unionall(bool u) { is_unionall = u; }
2527  void set_num_aggs(int a) { num_aggs = a; }
2528  int get_rte_idx(const std::string& range_var_name) const;
2529  RangeTableEntry* get_rte(int rte_idx) const { return rangetable[rte_idx]; }
2530  void add_rte(RangeTableEntry* rte);
2531  void add_tle(std::shared_ptr<TargetEntry> tle) { targetlist.push_back(tle); }
2532  int64_t get_limit() const { return limit; }
2533  void set_limit(int64_t l) { limit = l; }
2534  int64_t get_offset() const { return offset; }
2535  void set_offset(int64_t o) { offset = o; }
2536 
2537  private:
2538  bool is_distinct; // true only if SELECT DISTINCT
2539  std::vector<std::shared_ptr<TargetEntry>> targetlist; // represents the SELECT clause
2540  std::vector<RangeTableEntry*> rangetable; // represents the FROM clause for SELECT. For
2541  // INSERT, DELETE, UPDATE the result table is
2542  // always the first entry in rangetable.
2543  std::shared_ptr<Analyzer::Expr> where_predicate; // represents the WHERE clause
2544  std::list<std::shared_ptr<Analyzer::Expr>> group_by; // represents the GROUP BY clause
2545  std::shared_ptr<Analyzer::Expr> having_predicate; // represents the HAVING clause
2546  std::list<OrderEntry>* order_by; // represents the ORDER BY clause
2547  Query* next_query; // the next query to UNION
2548  bool is_unionall; // true only if it is UNION ALL
2550  int num_aggs; // number of aggregate functions in query
2551  int result_table_id; // for INSERT statements only
2552  std::list<int> result_col_list; // for INSERT statement only
2553  std::vector<std::vector<std::shared_ptr<TargetEntry>>> values_lists; // for INSERT only
2554  int64_t limit; // row count for LIMIT clause. 0 means ALL
2555  int64_t offset; // offset in OFFSET clause. 0 means no offset.
2556 };
2557 
2558 class GeoExpr : public Expr {
2559  public:
2560  GeoExpr(const SQLTypeInfo& ti) : Expr(ti) {}
2561 
2562  // geo expressions might hide child expressions (e.g. constructors). Centralize logic
2563  // for pulling out child expressions for simplicity in visitors.
2564  virtual std::vector<Analyzer::Expr*> getChildExprs() const { return {}; }
2565 };
2566 
2572 class GeoColumnVar : public ColumnVar {
2573  public:
2575  const int table_id,
2576  const int column_id,
2577  const int range_table_index,
2578  const bool with_bounds,
2579  const bool with_render_group)
2580  : ColumnVar(ti, table_id, column_id, range_table_index)
2581  , with_bounds_(with_bounds)
2582  , with_render_group_(with_render_group) {}
2583 
2585  const bool with_bounds,
2586  const bool with_render_group)
2587  : ColumnVar(column_var->get_type_info(),
2588  column_var->get_table_id(),
2589  column_var->get_column_id(),
2590  column_var->get_rte_idx())
2591  , with_bounds_(with_bounds)
2592  , with_render_group_(with_render_group) {}
2593 
2594  protected:
2597 };
2598 
2599 class GeoConstant : public GeoExpr {
2600  public:
2601  GeoConstant(std::unique_ptr<Geospatial::GeoBase>&& geo, const SQLTypeInfo& ti);
2602 
2603  std::shared_ptr<Analyzer::Expr> deep_copy() const final;
2604 
2605  std::string toString() const final;
2606 
2607  bool operator==(const Expr&) const final;
2608 
2609  size_t physicalCols() const;
2610 
2611  std::shared_ptr<Analyzer::Constant> makePhysicalConstant(const size_t index) const;
2612 
2613  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) final;
2614 
2615  std::string getWKTString() const;
2616 
2617  private:
2618  std::unique_ptr<Geospatial::GeoBase> geo_;
2619 };
2620 
2625 class GeoOperator : public GeoExpr {
2626  public:
2627  GeoOperator(const SQLTypeInfo& ti,
2628  const std::string& name,
2629  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
2630  const std::optional<int>& output_srid_override = std::nullopt);
2631 
2632  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2633 
2634  void collect_rte_idx(std::set<int>& rte_idx_set) const final;
2635 
2636  void collect_column_var(
2637  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
2638  colvar_set,
2639  bool include_agg) const final;
2640 
2641  std::string toString() const override;
2642 
2643  bool operator==(const Expr&) const override;
2644 
2645  size_t size() const;
2646 
2647  Analyzer::Expr* getOperand(const size_t index) const;
2648 
2649  const std::string& getName() const { return name_; }
2650 
2651  std::vector<std::shared_ptr<Analyzer::Expr>> getArgs() const { return args_; }
2652 
2653  std::vector<Analyzer::Expr*> getChildExprs() const override {
2654  std::vector<Analyzer::Expr*> ret;
2655  ret.reserve(args_.size());
2656  for (const auto& arg : args_) {
2657  ret.push_back(arg.get());
2658  }
2659  return ret;
2660  }
2661 
2662  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) final;
2663 
2665 
2666  protected:
2667  const std::string name_;
2668  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
2669 
2670  // for legacy geo code, allow passing in a srid to force a transform in the function
2671  std::optional<int> output_srid_override_;
2672 };
2673 
2675  public:
2677  const std::string& name,
2678  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
2679  const int32_t input_srid,
2680  const int32_t output_srid)
2681  : GeoOperator(ti, name, args), input_srid_(input_srid), output_srid_(output_srid) {}
2682 
2683  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2684 
2685  std::string toString() const override;
2686 
2687  bool operator==(const Expr&) const override;
2688 
2689  int32_t getInputSRID() const { return input_srid_; }
2690 
2691  int32_t getOutputSRID() const { return output_srid_; }
2692 
2693  private:
2694  const int32_t input_srid_;
2695  const int32_t output_srid_;
2696 };
2697 
2698 } // namespace Analyzer
2699 
2700 inline std::shared_ptr<Analyzer::Var> var_ref(const Analyzer::Expr* expr,
2701  const Analyzer::Var::WhichRow which_row,
2702  const int varno) {
2703  const auto col_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr);
2704  const int table_id = col_expr ? col_expr->get_table_id() : 0;
2705  const int column_id = col_expr ? col_expr->get_column_id() : 0;
2706  const int rte_idx = col_expr ? col_expr->get_rte_idx() : -1;
2707  return makeExpr<Analyzer::Var>(
2708  expr->get_type_info(), table_id, column_id, rte_idx, which_row, varno);
2709 }
2710 
2711 // Returns true iff the two expression lists are equal (same size and each element are
2712 // equal).
2713 bool expr_list_match(const std::vector<std::shared_ptr<Analyzer::Expr>>& lhs,
2714  const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs);
2715 
2716 // Remove a cast operator if present.
2717 std::shared_ptr<Analyzer::Expr> remove_cast(const std::shared_ptr<Analyzer::Expr>& expr);
2718 const Analyzer::Expr* remove_cast(const Analyzer::Expr* expr);
2719 
2720 #endif // ANALYZER_H
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3204
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1174
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3609
std::list< ExpressionPtr > ExpressionPtrList
Definition: Analyzer.h:187
int get_table_id() const
Definition: Analyzer.h:200
GeoBinOper(const Geospatial::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:2419
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1016
Query * next_query
Definition: Analyzer.h:2547
bool hasRangeModeFraming() const
Definition: Analyzer.h:2333
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:1248
InIntegerSet(const std::shared_ptr< const Analyzer::Expr > a, const std::vector< int64_t > &values, const bool not_null)
Definition: Analyzer.cpp:1628
SqlWindowFrameBoundType
Definition: sqldefs.h:136
virtual void get_domain(DomainSet &domain_set) const
Definition: Analyzer.h:179
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1977
bool operator==(const Expr &rhs) const override
Definition: Analyzer.h:615
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:650
WindowFrame(SqlWindowFrameBoundType bound_type, const std::shared_ptr< Analyzer::Expr > bound_expr)
Definition: Analyzer.h:2243
TargetEntry(const std::string &n, std::shared_ptr< Analyzer::Expr > e, bool u)
Definition: Analyzer.h:2452
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:288
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1837
std::string toString() const override
Definition: Analyzer.cpp:2819
Query * parsetree
Definition: Analyzer.h:626
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:344
TrimStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1869
SQLAgg
Definition: sqldefs.h:72
float get_likelihood() const
Definition: Analyzer.h:1141
size_t getMinArgs() const override
Definition: Analyzer.h:1760
std::vector< Analyzer::Expr * > getChildExprs() const override
Definition: Analyzer.h:2653
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2126
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:291
std::shared_ptr< Analyzer::Expr > expr
Definition: Analyzer.h:2466
virtual bool operator==(const Expr &rhs) const =0
std::string toString() const override
Definition: Analyzer.cpp:2741
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:558
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2052
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2297
LowerStringOper(const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:1623
std::vector< std::vector< std::shared_ptr< TargetEntry > > > & get_values_lists()
Definition: Analyzer.h:2502
Var(const SQLTypeInfo &ti, int r, int c, int i, WhichRow o, int v)
Definition: Analyzer.h:276
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:212
virtual ~Expr()
Definition: Analyzer.h:79
Expr(SQLTypes t, int d, int s, bool notnull)
Definition: Analyzer.h:75
bool unnest
Definition: Analyzer.h:2467
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1614
ConcatStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1788
InValues(std::shared_ptr< Analyzer::Expr > a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.cpp:1610
const Expr * get_from_expr() const
Definition: Analyzer.h:1304
static bool simple_predicate_has_simple_cast(const std::shared_ptr< Analyzer::Expr > cast_operand, const std::shared_ptr< Analyzer::Expr > const_operand)
Definition: Analyzer.cpp:1475
const Expr * get_partition_count() const
Definition: Analyzer.h:1043
InitCapStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1689
bool hasNoneEncodedTextArg() const
Definition: Analyzer.h:1541
Constant(const SQLTypeInfo &ti, bool n, Datum v)
Definition: Analyzer.h:329
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:976
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2464
std::string toString() const override
Definition: Analyzer.cpp:2570
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3179
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::vector< std::shared_ptr< Analyzer::Expr >> &chained_string_op_exprs)
Definition: Analyzer.h:1482
Var(const SQLTypeInfo &ti, WhichRow o, int v)
Definition: Analyzer.h:278
GeoConstant(std::unique_ptr< Geospatial::GeoBase > &&geo, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:3703
void get_domain(DomainSet &domain_set) const override
Definition: Analyzer.cpp:3387
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2148
std::string toString() const final
Definition: Analyzer.cpp:3718
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2250
bool is_constant_expr() const
Definition: Analyzer.h:1118
const Expr * get_else_expr() const
Definition: Analyzer.h:1259
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:2433
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3459
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2352
void set_contains_agg(bool a)
Definition: Analyzer.h:84
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1732
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:239
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:2435
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3569
const std::vector< int64_t > & get_value_list() const
Definition: Analyzer.h:689
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3073
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2242
OrderEntry(int t, bool d, bool nf)
Definition: Analyzer.h:2228
const Expr * get_escape_expr() const
Definition: Analyzer.h:906
virtual std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:131
size_t getMinArgs() const override
Definition: Analyzer.h:1874
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:792
std::vector< std::vector< std::shared_ptr< TargetEntry > > > values_lists
Definition: Analyzer.h:2553
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:858
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2055
std::shared_ptr< Analyzer::Expr > decompress()
Definition: Analyzer.cpp:702
size_t getArity() const
Definition: Analyzer.h:2169
std::optional< int > output_srid_override_
Definition: Analyzer.h:2671
Definition: Analyzer.h:2450
DatediffExpr(const SQLTypeInfo &ti, const DatetruncField f, const std::shared_ptr< Analyzer::Expr > start, const std::shared_ptr< Analyzer::Expr > end)
Definition: Analyzer.h:1381
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:132
int32_t getInputSRID() const
Definition: Analyzer.h:2689
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4196
RangeOper(const bool l_inclusive, const bool r_inclusive, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:533
size_t getMinArgs() const override
Definition: Analyzer.h:2015
ReplaceStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &search_pattern, const std::shared_ptr< Analyzer::Expr > &replacing_str)
Definition: Analyzer.h:1994
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
Definition: Analyzer.h:215
SQLTypes
Definition: sqltypes.h:38
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:2342
const std::vector< std::vector< std::shared_ptr< TargetEntry > > > & get_values_lists() const
Definition: Analyzer.h:2499
void add_rte(RangeTableEntry *rte)
Definition: Analyzer.cpp:1428
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:2404
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3112
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2150
std::shared_ptr< Analyzer::Expr > operand
Definition: Analyzer.h:418
AggExpr(SQLTypes t, SQLAgg a, Expr *g, bool d, std::shared_ptr< Analyzer::Constant > e, int idx)
Definition: Analyzer.h:1190
virtual void print() const
Definition: Analyzer.h:156
std::list< int > result_col_list
Definition: Analyzer.h:2552
void set_varno(int n)
Definition: Analyzer.h:283
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3494
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:746
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:805
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:220
GeoUOper(const Geospatial::GeoBase::GeoOp op, const SQLTypeInfo &ti, const SQLTypeInfo &ti0, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:2392
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1795
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2112
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:400
RegexpSubstrStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &regex_pattern, const std::shared_ptr< Analyzer::Expr > &start_pos, const std::shared_ptr< Analyzer::Expr > &occurrence, const std::shared_ptr< Analyzer::Expr > &regex_params, const std::shared_ptr< Analyzer::Expr > &sub_match_group_idx)
Definition: Analyzer.h:2111
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2481
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:502
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3446
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1140
StringOper(const StringOper &other_string_oper)
Definition: Analyzer.h:1490
void collect_rte_idx(std::set< int > &rte_idx_set) const final
Definition: Analyzer.cpp:3821
void set_rte_idx(int new_rte_idx)
Definition: Analyzer.h:203
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2098
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2304
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1550
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:986
SQLQualifier
Definition: sqldefs.h:70
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3046
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:810
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:524
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1876
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1210
SQLStmtType stmt_type
Definition: Analyzer.h:2549
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:1020
ColumnVar(const SQLTypeInfo &ti, int r, int c, int i)
Definition: Analyzer.h:198
const Query * get_parsetree() const
Definition: Analyzer.h:586
bool operator==(Expr const &rhs) const override
Definition: Analyzer.cpp:2516
ExtractField get_field() const
Definition: Analyzer.h:1303
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1842
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1918
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1647
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3277
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:140
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1981
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:295
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:102
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3345
const Expr * get_escape_expr() const
Definition: Analyzer.h:978
const Expr * get_right_operand() const
Definition: Analyzer.h:450
SQLOps
Definition: sqldefs.h:28
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1761
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3256
GeoTransformOperator(const SQLTypeInfo &ti, const std::string &name, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const int32_t input_srid, const int32_t output_srid)
Definition: Analyzer.h:2676
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1071
std::string toString() const override
Definition: Analyzer.cpp:2994
std::shared_ptr< Analyzer::Expr > get_shared_ptr()
Definition: Analyzer.h:80
virtual void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
Definition: Analyzer.h:86
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:916
RepeatStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1748
auto getOutputSridOverride() const
Definition: Analyzer.h:2664
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
Definition: Analyzer.h:1567
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3509
SqlWindowFrameBoundType bound_type_
Definition: Analyzer.h:2261
std::list< std::shared_ptr< Analyzer::Expr > > group_by
Definition: Analyzer.h:2544
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:668
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:87
void print() const
Definition: Analyzer.h:2462
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:2410
SQLTypeInfo ti0_
Definition: Analyzer.h:2440
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:611
std::shared_ptr< Analyzer::Expr > like_expr
Definition: Analyzer.h:953
bool get_is_null() const
Definition: Analyzer.h:341
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:2442
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1146
std::string toString() const override
Definition: Analyzer.cpp:3600
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:868
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3315
int tle_no
Definition: Analyzer.h:2232
~OrderEntry()
Definition: Analyzer.h:2229
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:148
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:2700
const std::shared_ptr< const Analyzer::Expr > arg
Definition: Analyzer.h:697
const std::shared_ptr< Analyzer::Expr > get_own_operand() const
Definition: Analyzer.h:379
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:213
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:222
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1064
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:493
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1141
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3464
bool get_contains_agg() const
Definition: Analyzer.h:83
SqlStringOpKind
Definition: sqldefs.h:84
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:3382
std::string toString() const override
Definition: Analyzer.cpp:2783
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1385
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1159
const SQLTypeInfo getTypeInfo1() const
Definition: Analyzer.h:2434
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:186
const Geospatial::GeoBase::GeoOp op_
Definition: Analyzer.h:2439
const Expr * get_arg() const
Definition: Analyzer.h:975
size_t getArity() const
Definition: Analyzer.h:1506
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2339
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2090
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3537
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:2523
Expr * get_arg() const
Definition: Analyzer.h:1202
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2407
DatetruncField get_field() const
Definition: Analyzer.h:1428
const std::list< OrderEntry > * get_order_by() const
Definition: Analyzer.h:2511
static SqlStringOpKind get_and_validate_trim_op_kind(const SqlStringOpKind trim_op_kind_maybe, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.cpp:4124
void set_result_col_list(const std::list< int > &col_list)
Definition: Analyzer.h:2517
const Expr * get_arg() const
Definition: Analyzer.h:1139
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
Constants for Builtin SQL Types supported by HEAVY.AI.
void set_which_row(WhichRow r)
Definition: Analyzer.h:281
size_t getMinArgs() const override
Definition: Analyzer.h:2140
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1366
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1236
const Expr * get_where_predicate() const
Definition: Analyzer.h:2506
int get_num_aggs() const
Definition: Analyzer.h:2492
RegexpReplaceStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &regex_pattern, const std::shared_ptr< Analyzer::Expr > &replacing_str, const std::shared_ptr< Analyzer::Expr > &start_pos, const std::shared_ptr< Analyzer::Expr > &occurrence, const std::shared_ptr< Analyzer::Expr > &regex_params)
Definition: Analyzer.h:2064
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3618
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3813
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:922
virtual std::vector< OperandTypeFamily > getExpectedTypeFamilies() const
Definition: Analyzer.h:1597
Definition: sqltypes.h:65
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:66
const Analyzer::WindowFrame * getFrameStartBound() const
Definition: Analyzer.h:2309
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2193
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2338
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.cpp:4106
void set_constant_expr() const
Definition: Analyzer.h:1117
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2017
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3504
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3270
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2386
void set_offset(int64_t o)
Definition: Analyzer.h:2535
ReplaceStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2003
UOper(SQLTypes t, SQLOps o, std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:373
~Constant() override
Definition: Analyzer.cpp:40
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
Definition: Analyzer.h:1523
std::unique_ptr< Geospatial::GeoBase > geo_
Definition: Analyzer.h:2618
size_t getLiteralsArity() const
Definition: Analyzer.h:1508
SQLQualifier qualifier
Definition: Analyzer.h:521
bool isNull() const
Definition: Analyzer.h:2367
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
virtual std::vector< Analyzer::Expr * > getChildExprs() const
Definition: Analyzer.h:2564
const Analyzer::WindowFrame * getFrameEndBound() const
Definition: Analyzer.h:2316
std::string toString() const override
Definition: Analyzer.cpp:2898
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1703
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:2305
std::string toString() const override
Definition: Analyzer.cpp:2631
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:484
SQLTypeInfo type_info
Definition: Analyzer.h:182
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:2323
const Expr * get_left_operand() const
Definition: Analyzer.h:546
GeoColumnVar(const SQLTypeInfo &ti, const int table_id, const int column_id, const int range_table_index, const bool with_bounds, const bool with_render_group)
Definition: Analyzer.h:2574
EncodingType get_compression() const
Definition: Analyzer.h:204
std::list< const Expr * > DomainSet
Definition: Analyzer.h:64
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
virtual void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
Definition: Analyzer.h:119
void set_constval(Datum d)
Definition: Analyzer.h:343
const Expr * get_arg() const
Definition: Analyzer.h:903
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:778
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1987
std::enable_if< std::is_base_of< Analyzer::Expr, Tp >::value, std::shared_ptr< Tp > >::type makeExpr(Args &&...args)
Definition: Analyzer.h:55
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3145
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:591
std::string toString() const override
Definition: Analyzer.cpp:2579
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1460
const std::string & get_resname() const
Definition: Analyzer.h:2455
double get_bound_val(const Analyzer::Expr *bound_expr) const
Definition: Analyzer.cpp:3641
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2084
constexpr double f
Definition: Utm.h:31
static SQLTypeInfo get_return_type(const std::vector< std::shared_ptr< Analyzer::Expr >> args)
Definition: Analyzer.cpp:3975
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1004
RepeatStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1755
~Subquery() override
Definition: Analyzer.cpp:46
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:607
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2424
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:731
TrimStringOper(const SqlStringOpKind trim_op_kind, const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &trim_chars)
Definition: Analyzer.h:1852
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:998
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:597
bool operator==(const Expr &) const override
Definition: Analyzer.cpp:3908
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1417
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1130
void set_type_info(const SQLTypeInfo &ti)
Definition: Analyzer.h:82
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2337
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:3365
std::string toString() const override
Definition: Analyzer.cpp:2600
const std::shared_ptr< Analyzer::Expr > get_own_from_expr() const
Definition: Analyzer.h:1430
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1618
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:76
std::string toString() const override
Definition: Analyzer.cpp:2706
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3514
LikelihoodExpr(std::shared_ptr< Analyzer::Expr > a, float l=0.5)
Definition: Analyzer.h:1137
constexpr double a
Definition: Utm.h:32
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2282
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3056
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1469
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:429
bool g_enable_string_functions
std::string toString() const override
Definition: Analyzer.cpp:2797
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2099
std::vector< size_t > getLiteralArgIndexes() const
Definition: Analyzer.cpp:3947
std::string toString() const override
Definition: Analyzer.cpp:2828
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:872
std::string toString() const override
Definition: Analyzer.cpp:2764
bool get_calc_encoded_length() const
Definition: Analyzer.h:712
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2259
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1968
std::string toString() const override
Definition: Analyzer.cpp:2971
DatetruncField field_
Definition: Analyzer.h:1454
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1932
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2340
const Geospatial::GeoBase::GeoOp op_
Definition: Analyzer.h:2408
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1051
std::string toString() const override
Definition: Analyzer.cpp:2921
SQLOps get_optype() const
Definition: Analyzer.h:446
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:523
void check_operand_types(const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names, const bool dict_encoded_cols_only=true, const bool cols_first_arg_only=true) const
Definition: Analyzer.cpp:3997
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2498
const std::vector< std::shared_ptr< Analyzer::Expr > > args1_
Definition: Analyzer.h:2443
RepeatStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &num_repeats)
Definition: Analyzer.h:1740
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1239
std::string toString() const
Definition: Analyzer.cpp:3024
SqlWindowFrameBoundType getBoundType() const
Definition: Analyzer.h:2247
const Query * get_next_query() const
Definition: Analyzer.h:2512
SubstringStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &start_pos, const std::shared_ptr< Analyzer::Expr > &length)
Definition: Analyzer.h:1913
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2341
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:115
std::shared_ptr< Analyzer::Expr > normalize_simple_predicate(int &rte_idx) const override
Definition: Analyzer.cpp:1499
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:670
EncodingType
Definition: sqltypes.h:233
SplitPartStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &delimiter, const std::shared_ptr< Analyzer::Expr > &split_index)
Definition: Analyzer.h:2029
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:173
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:166
static SQLTypeInfo common_string_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:425
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:217
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:473
UpperStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1659
DatetruncExpr(const SQLTypeInfo &ti, bool has_agg, DatetruncField f, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1423
std::shared_ptr< Analyzer::Expr > right_operand_
Definition: Analyzer.h:571
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1542
std::shared_ptr< Analyzer::Constant > get_arg1() const
Definition: Analyzer.h:1205
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:477
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:182
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.h:620
static SqlStringOpKind validate_trim_op_kind(const SqlStringOpKind trim_op_kind)
Definition: Analyzer.h:1884
bool hasSingleDictEncodedColInput() const
returns whether we have one and only one column involved in this StringOper and all its descendents...
Definition: Analyzer.cpp:3933
RegexpReplaceStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2084
Expr(const SQLTypeInfo &ti, bool has_agg=false)
Definition: Analyzer.h:77
std::shared_ptr< Analyzer::Expr > deep_copy() const final
Definition: Analyzer.cpp:3713
LiteralArgMap getLiteralArgs() const
Definition: Analyzer.cpp:3960
std::string toString() const override
Definition: Analyzer.cpp:2695
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2009
const DatetruncField field_
Definition: Analyzer.h:1412
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2485
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1691
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
Definition: Analyzer.h:251
CONSTEXPR DEVICE bool is_null(const T &value)
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3261
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2132
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:2299
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1795
RangeTableEntry * get_rte(int rte_idx) const
Definition: Analyzer.h:2529
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3252
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:819
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3283
const std::shared_ptr< Analyzer::Expr > get_own_from_expr() const
Definition: Analyzer.h:1305
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3132
DateaddField
Definition: DateAdd.h:42
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:930
bool is_integer() const
Definition: sqltypes.h:512
std::vector< std::shared_ptr< TargetEntry > > targetlist
Definition: Analyzer.h:2539
std::string toString() const override
Definition: Analyzer.cpp:2776
const DateaddField field_
Definition: Analyzer.h:1370
DatetruncField
Definition: DateTruncate.h:27
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:122
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1455
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:639
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:4183
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3328
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2733
Subquery(const SQLTypeInfo &ti, Query *q)
Definition: Analyzer.h:583
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:2405
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const size_t min_args, const std::vector< OperandTypeFamily > &expected_type_families, const std::vector< std::string > &arg_names)
Definition: Analyzer.h:1473
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
Definition: Analyzer.h:2176
ReverseStringOper(const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:1711
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:389
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1735
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:386
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:198
Expr * get_expr() const
Definition: Analyzer.h:2457
int64_t get_offset() const
Definition: Analyzer.h:2534
size_t getMinArgs() const override
Definition: Analyzer.h:1671
std::string toString() const override
Definition: Analyzer.cpp:2564
size_t getMinArgs() const override
Definition: Analyzer.h:2089
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1448
const std::shared_ptr< Analyzer::Expr > end_
Definition: Analyzer.h:1414
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2447
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:864
std::string toString() const override
Definition: Analyzer.cpp:2808
WhichRow get_which_row() const
Definition: Analyzer.h:280
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:3370
void set_expr(std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:2459
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2372
const std::shared_ptr< Analyzer::Expr > number_
Definition: Analyzer.h:1371
ArrayExpr(SQLTypeInfo const &array_ti, ExpressionPtrVector const &array_exprs, bool is_null=false, bool local_alloc=false)
Definition: Analyzer.h:2353
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:355
std::string resname
Definition: Analyzer.h:2465
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3479
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:2729
const Analyzer::Expr * getBoundExpr() const
Definition: Analyzer.h:2249
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2455
bool get_is_distinct() const
Definition: Analyzer.h:2491
const std::string & getName() const
Definition: Analyzer.h:2649
std::string toString() const override
Definition: Analyzer.cpp:2908
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:726
static SQLTypeInfo common_numeric_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:465
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3266
SQLTypeInfo ti1_
Definition: Analyzer.h:2441
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1986
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:603
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1705
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2154
const std::shared_ptr< Analyzer::Expr > start_
Definition: Analyzer.h:1413
virtual ~TargetEntry()
Definition: Analyzer.h:2454
size_t getMinArgs() const override
Definition: Analyzer.h:1979
int get_varno() const
Definition: Analyzer.h:282
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:553
virtual std::vector< std::string > getArgNames() const
Definition: Analyzer.h:1601
std::string toString() const
Definition: Analyzer.cpp:3034
bool get_is_simple() const
Definition: Analyzer.h:908
SplitPartStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2038
OverlayStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &replacing_str, const std::shared_ptr< Analyzer::Expr > &start_pos)
Definition: Analyzer.h:1948
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1661
std::vector< std::shared_ptr< Analyzer::Expr > > getArgs() const
Definition: Analyzer.h:2651
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:855
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1719
bool nulls_first
Definition: Analyzer.h:2234
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1950
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3290
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:711
int64_t get_limit() const
Definition: Analyzer.h:2532
bool get_is_distinct() const
Definition: Analyzer.h:1204
FunctionOperWithCustomTypeHandling(const SQLTypeInfo &ti, const std::string &name, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:2198
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands, const SqlStringOpKind string_op_kind)
Definition: Analyzer.cpp:4155
bool get_unnest() const
Definition: Analyzer.h:2460
ReplaceStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2010
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2270
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:720
const std::vector< OrderEntry > collation_
Definition: Analyzer.h:2343
bool g_enable_smem_group_by true
ExtractExpr(const SQLTypeInfo &ti, bool has_agg, ExtractField f, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1298
const Expr * get_start_expr() const
Definition: Analyzer.h:1387
void do_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1210
std::string toString() const override
Definition: Analyzer.cpp:2586
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1839
Constant(const SQLTypeInfo &ti, bool n, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.h:336
const Expr * get_right_operand() const
Definition: Analyzer.h:547
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2548
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1936
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:827
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3223
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3103
void set_num_aggs(int a)
Definition: Analyzer.h:2527
void set_group_by(std::list< std::shared_ptr< Analyzer::Expr >> &g)
Definition: Analyzer.h:2521
WhichRow which_row
Definition: Analyzer.h:303
const SQLTypeInfo & get_type_info() const
Definition: Analyzer.h:81
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2026
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3322
void add_tle(std::shared_ptr< TargetEntry > tle)
Definition: Analyzer.h:2531
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1809
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 FrameBoundType frame_bound_type, const std::shared_ptr< Expr > frame_start_bound, const std::shared_ptr< Expr > frame_end_bound, const std::vector< OrderEntry > &collation)
Definition: Analyzer.h:2273
void set_next_query(Query *q)
Definition: Analyzer.h:2524
bool get_is_unionall() const
Definition: Analyzer.h:2514
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3469
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) final
Definition: Analyzer.cpp:3784
int get_result_table_id() const
Definition: Analyzer.h:2515
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3529
size_t getElementCount() const
Definition: Analyzer.h:2365
int32_t getOutputSRID() const
Definition: Analyzer.h:2691
SQLStmtType
Definition: sqldefs.h:145
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:952
const std::vector< std::shared_ptr< Analyzer::Expr > > tuple_
Definition: Analyzer.h:261
RegexpSubstrStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2135
OverlayStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &replacing_str, const std::shared_ptr< Analyzer::Expr > &start_pos, const std::shared_ptr< Analyzer::Expr > &replacing_length)
Definition: Analyzer.h:1957
void set_having_predicate(std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:2522
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3888
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2142
std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:1617
void set_result_table_id(int id)
Definition: Analyzer.h:2518
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:774
const std::vector< int64_t > value_list
Definition: Analyzer.h:698
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:395
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:736
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3242
const Expr * get_pattern_expr() const
Definition: Analyzer.h:977
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:717
#define CHECK_LT(x, y)
Definition: Logger.h:232
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1879
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1644
int64_t offset
Definition: Analyzer.h:2555
virtual std::string toString() const =0
WidthBucketExpr(const std::shared_ptr< Analyzer::Expr > target_value, const std::shared_ptr< Analyzer::Expr > lower_bound, const std::shared_ptr< Analyzer::Expr > upper_bound, const std::shared_ptr< Analyzer::Expr > partition_count)
Definition: Analyzer.h:1029
ExpressionPtrVector contained_expressions_
Definition: Analyzer.h:2381
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2000
SqlStringOpKind kind_
Definition: Analyzer.h:1616
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1677
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3337
Expression class for string functions The &quot;arg&quot; constructor parameter must be an expression that reso...
Definition: Analyzer.h:1463
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:813
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1775
UOper(const SQLTypeInfo &ti, bool has_agg, SQLOps o, std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:371
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:144
const Expr * get_from_expr() const
Definition: Analyzer.h:1429
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3233
virtual ~Query()
Definition: Analyzer.cpp:50
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:259
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3123
size_t getMinArgs() const override
Definition: Analyzer.h:1934
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
const std::shared_ptr< Analyzer::Expr > bound_expr_
Definition: Analyzer.h:2262
RegexpReplaceStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2077
const Expr * get_datetime_expr() const
Definition: Analyzer.h:1346
void set_is_distinct(bool d)
Definition: Analyzer.h:2519
int get_comp_param() const
Definition: Analyzer.h:205
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:246
ReverseStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1718
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:194
size_t getMinArgs() const override
Definition: Analyzer.h:2050
StringOper(const std::shared_ptr< StringOper > &other_string_oper)
Definition: Analyzer.h:1497
bool isLocalAlloc() const
Definition: Analyzer.h:2366
SqlStringOpKind get_kind() const
Definition: Analyzer.h:1504
std::string toString() const override
Definition: Analyzer.cpp:2894
const Expr * get_like_expr() const
Definition: Analyzer.h:905
std::vector< std::shared_ptr< TargetEntry > > & get_targetlist_nonconst()
Definition: Analyzer.h:2496
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3065
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1853
const Analyzer::Expr * getArg(const size_t i) const
Definition: Analyzer.h:2171
RegexpExpr(std::shared_ptr< Analyzer::Expr > a, std::shared_ptr< Analyzer::Expr > p, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:968
UpperStringOper(const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:1652
std::string toString() const override
Definition: Analyzer.cpp:2912
ReverseStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1725
int get_rte_idx() const
Definition: Analyzer.h:202
const Expr * get_operand() const
Definition: Analyzer.h:378
size_t getMinArgs() const override
Definition: Analyzer.h:1642
Analyzer::ExpressionPtr deep_copy() const override
Definition: Analyzer.cpp:234
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:782
size_t getMinArgs() const override
Definition: Analyzer.h:1701
Datum get_constval() const
Definition: Analyzer.h:342
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3085
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2175
const Expr * get_arg() const
Definition: Analyzer.h:804
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) final
Definition: Analyzer.cpp:3874
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1747
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:992
void set_is_unionall(bool u)
Definition: Analyzer.h:2525
SampleRatioExpr(std::shared_ptr< Analyzer::Expr > a)
Definition: Analyzer.h:802
size_t getMinArgs() const override
Definition: Analyzer.h:1793
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1340
const Expr * get_arg() const
Definition: Analyzer.h:710
void set_resname(const std::string &name)
Definition: Analyzer.h:2456
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:640
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3651
std::string toString() const override
Definition: Analyzer.cpp:2903
std::vector< RangeTableEntry * > rangetable
Definition: Analyzer.h:2540
GeoOperator(const SQLTypeInfo &ti, const std::string &name, const std::vector< std::shared_ptr< Analyzer::Expr >> &args, const std::optional< int > &output_srid_override=std::nullopt)
Definition: Analyzer.cpp:3804
SubstringStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1929
std::shared_ptr< Analyzer::Expr > from_expr_
Definition: Analyzer.h:1330
std::string toString() const override
Definition: Analyzer.cpp:2834
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2140
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1675
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1733
virtual std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:716
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1455
void cast_number(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:855
ExtractField
virtual void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const
Definition: Analyzer.h:165
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
SqlWindowFunctionKind
Definition: sqldefs.h:110
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:913
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:837
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1057
UpperStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1666
virtual size_t getMinArgs() const
Definition: Analyzer.h:1593
size_t size() const
Definition: Analyzer.cpp:3865
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:70
SQLTypeInfo ti0_
Definition: Analyzer.h:2409
void set_where_predicate(std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:2520
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
void set_stmt_type(SQLStmtType t)
Definition: Analyzer.h:2526
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1648
const Expr * get_having_predicate() const
Definition: Analyzer.h:2510
DateaddField get_field() const
Definition: Analyzer.h:1344
SQLAgg get_aggtype() const
Definition: Analyzer.h:1201
std::string toString() const override
Definition: Analyzer.cpp:2956
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:850
PadStringOper(const SqlStringOpKind pad_op_kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1822
virtual std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:150
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:160
const Expr * get_target_value() const
Definition: Analyzer.h:1040
const std::shared_ptr< Analyzer::Expr > datetime_
Definition: Analyzer.h:1372
std::string toString() const override
Definition: Analyzer.cpp:3591
KeyForStringExpr(std::shared_ptr< Analyzer::Expr > a)
Definition: Analyzer.h:757
Constant(SQLTypes t, bool n)
Definition: Analyzer.h:315
const Expr * get_arg() const
Definition: Analyzer.h:759
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3213
std::shared_ptr< Expr > get_own_expr() const
Definition: Analyzer.h:2458
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3499
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3519
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:882
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1959
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3484
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3189
size_t getMinArgs() const override
Definition: Analyzer.h:1730
virtual std::shared_ptr< Analyzer::Expr > normalize_simple_predicate(int &rte_idx) const
Definition: Analyzer.h:97
bool g_enable_watchdog false
Definition: Execute.cpp:79
void set_notnull(bool n)
Definition: sqltypes.h:436
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:105
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1048
PadStringOper(const SqlStringOpKind pad_op_kind, const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &padded_length, const std::shared_ptr< Analyzer::Expr > &padding_str)
Definition: Analyzer.h:1812
const Expr * get_end_expr() const
Definition: Analyzer.h:1388
#define CHECK(condition)
Definition: Logger.h:222
SQLStmtType get_stmt_type() const
Definition: Analyzer.h:2513
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:892
Geospatial::GeoBase::GeoOp getOp() const
Definition: Analyzer.h:2403
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2315
bool can_skip_out_of_bound_check() const
Definition: Analyzer.h:1115
ExtractField field_
Definition: Analyzer.h:1329
GeoColumnVar(const Analyzer::ColumnVar *column_var, const bool with_bounds, const bool with_render_group)
Definition: Analyzer.h:2584
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2106
BinOper(SQLTypes t, SQLOps o, SQLQualifier q, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:436
bool is_desc
Definition: Analyzer.h:2233
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1411
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1765
SubstringStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &start_pos)
Definition: Analyzer.h:1905
std::shared_ptr< Analyzer::Expr > having_predicate
Definition: Analyzer.h:2545
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:760
Expr(SQLTypes t, int d, bool notnull)
Definition: Analyzer.h:73
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2293
void cast_to_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1149
TrimStringOper(const SqlStringOpKind trim_op_kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1861
Analyzer::WindowFunction::FrameBoundType getFrameBoundType() const
Definition: Analyzer.h:2325
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3474
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:1941
int32_t compute_bucket(T target_const_val, SQLTypeInfo &ti) const
Definition: Analyzer.h:1081
virtual void collect_rte_idx(std::set< int > &rte_idx_set) const
Definition: Analyzer.h:112
const std::list< std::shared_ptr< Analyzer::Expr > > & get_group_by() const
Definition: Analyzer.h:2507
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:136
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:596
std::vector< ExpressionPtr > ExpressionPtrVector
Definition: Analyzer.h:188
static SqlStringOpKind get_and_validate_pad_op_kind(const SqlStringOpKind pad_op_kind)
Definition: Analyzer.cpp:4115
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1564
std::shared_ptr< Analyzer::Expr > left_operand_
Definition: Analyzer.h:570
std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1203
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:823
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:128
std::string toString() const override
Definition: Analyzer.cpp:3897
RegexpSubstrStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2128
Analyzer::Expr * getOperand(const size_t index) const
Definition: Analyzer.cpp:3869
bool operator==(const Expr &) const final
Definition: Analyzer.cpp:3731
DateaddExpr(const SQLTypeInfo &ti, const DateaddField f, const std::shared_ptr< Analyzer::Expr > number, const std::shared_ptr< Analyzer::Expr > datetime)
Definition: Analyzer.h:1339
std::string toString() const override
Definition: Analyzer.cpp:2916
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:955
OverlayStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1967
void group_predicates(std::list< const Expr * > &scan_predicates, std::list< const Expr * > &join_predicates, std::list< const Expr * > &const_predicates) const override
Definition: Analyzer.cpp:1633
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:938
const Expr * get_left_operand() const
Definition: Analyzer.h:449
bool is_overlaps_oper() const
Definition: Analyzer.h:447
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:208
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:106
CharLengthExpr(std::shared_ptr< Analyzer::Expr > a, bool e)
Definition: Analyzer.h:708
SubstringStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1922
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3302
ExpressionTuple(const std::vector< std::shared_ptr< Analyzer::Expr >> &tuple)
Definition: Analyzer.h:248
void find_expr(bool(*f)(const Expr *), std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3170
Common Enum definitions for SQL processing.
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1149
size_t getMinArgs() const override
Definition: Analyzer.h:1835
Definition: sqltypes.h:45
void skip_out_of_bound_check() const
Definition: Analyzer.h:1116
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2069
const SqlWindowFunctionKind kind_
Definition: Analyzer.h:2336
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1432
std::shared_ptr< Analyzer::Constant > makePhysicalConstant(const size_t index) const
Definition: Analyzer.cpp:3753
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:904
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1798
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:1706
const Expr * get_lower_bound() const
Definition: Analyzer.h:1041
int get_column_id() const
Definition: Analyzer.h:201
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:405
std::string toString() const override
Definition: Analyzer.cpp:2702
const std::shared_ptr< Analyzer::Expr > get_own_right_operand() const
Definition: Analyzer.h:454
Constant(SQLTypes t, bool n, Datum v)
Definition: Analyzer.h:322
std::string getName() const
Definition: Analyzer.h:2167
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1215
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const final
Definition: Analyzer.cpp:3828
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2057
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2473
void print() const
Definition: Analyzer.h:2231
const Expr * get_arg() const
Definition: Analyzer.h:687
LowerStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1630
std::shared_ptr< Analyzer::Expr > where_predicate
Definition: Analyzer.h:2543
string name
Definition: setup.in.py:72
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1164
constexpr double n
Definition: Utm.h:38
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:768
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1155
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2225
bool hasRowModeFraming() const
Definition: Analyzer.h:2331