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