OmniSciDB  a5dc49c757
 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 #pragma once
23 
24 #include "Geospatial/Types.h"
25 #include "Logger/Logger.h"
26 #include "Shared/DbObjectKeys.h"
27 #include "Shared/sqldefs.h"
28 #include "Shared/sqltypes.h"
29 
30 #include <algorithm>
31 #include <cstdint>
32 #include <functional>
33 #include <iostream>
34 #include <list>
35 #include <map>
36 #include <optional>
37 #include <set>
38 #include <sstream>
39 #include <string>
40 #include <type_traits>
41 #include <utility>
42 #include <vector>
43 
44 extern bool g_enable_string_functions;
45 
46 namespace Analyzer {
47 class Expr;
48 }
49 
50 template <typename Tp, typename... Args>
51 inline typename std::enable_if<std::is_base_of<Analyzer::Expr, Tp>::value,
52  std::shared_ptr<Tp>>::type
53 makeExpr(Args&&... args) {
54  return std::make_shared<Tp>(std::forward<Args>(args)...);
55 }
56 
57 namespace Analyzer {
58 
59 class ColumnVar;
60 class TargetEntry;
61 class Expr;
62 using DomainSet = std::list<const Expr*>;
63 
64 /*
65  * @type Expr
66  * @brief super class for all expressions in parse trees and in query plans
67  */
68 class Expr : public std::enable_shared_from_this<Expr> {
69  public:
70  Expr(SQLTypes t, bool notnull) : type_info(t, notnull), contains_agg(false) {}
71  Expr(SQLTypes t, int d, bool notnull)
72  : type_info(t, d, 0, notnull), contains_agg(false) {}
73  Expr(SQLTypes t, int d, int s, bool notnull)
74  : type_info(t, d, s, notnull), contains_agg(false) {}
75  Expr(const SQLTypeInfo& ti, bool has_agg = false)
76  : type_info(ti), contains_agg(has_agg) {}
77  virtual ~Expr() {}
78  std::shared_ptr<Analyzer::Expr> get_shared_ptr() { return shared_from_this(); }
79  const SQLTypeInfo& get_type_info() const { return type_info; }
80  void set_type_info(const SQLTypeInfo& ti) { type_info = ti; }
81  bool get_contains_agg() const { return contains_agg; }
82  void set_contains_agg(bool a) { contains_agg = a; }
83  virtual std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info);
84  virtual void check_group_by(
85  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const {};
86  virtual std::shared_ptr<Analyzer::Expr> deep_copy()
87  const = 0; // make a deep copy of self
88  /*
89  * @brief normalize_simple_predicate only applies to boolean expressions.
90  * it checks if it is an expression comparing a column
91  * with a constant. if so, it returns a normalized copy of the predicate with ColumnVar
92  * always as the left operand with rte_idx set to the rte_idx of the ColumnVar.
93  * it returns nullptr with rte_idx set to -1 otherwise.
94  */
95  virtual std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const {
96  rte_idx = -1;
97  return nullptr;
98  }
99  /*
100  * @brief seperate conjunctive predicates into scan predicates, join predicates and
101  * constant predicates.
102  */
103  virtual void group_predicates(std::list<const Expr*>& scan_predicates,
104  std::list<const Expr*>& join_predicates,
105  std::list<const Expr*>& const_predicates) const {}
106  /*
107  * @brief collect_rte_idx collects the indices of all the range table
108  * entries involved in an expression
109  */
110  virtual void collect_rte_idx(std::set<int>& rte_idx_set) const {}
111  /*
112  * @brief collect_column_var collects all unique ColumnVar nodes in an expression
113  * If include_agg = false, it does not include to ColumnVar nodes inside
114  * the argument to AggExpr's. Otherwise, they are included.
115  * It does not make copies of the ColumnVar
116  */
117  virtual void collect_column_var(
118  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
119  colvar_set,
120  bool include_agg) const {}
121 
122  virtual size_t get_num_column_vars(const bool include_agg) const;
123 
124  /*
125  * @brief rewrite_with_targetlist rewrite ColumnVar's in expression with entries in a
126  * targetlist. targetlist expressions are expected to be only Var's or AggExpr's.
127  * returns a new expression copy
128  */
129  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
130  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
131  return deep_copy();
132  };
133  /*
134  * @brief rewrite_with_child_targetlist rewrite ColumnVar's in expression with entries
135  * in a child plan's targetlist. targetlist expressions are expected to be only Var's or
136  * ColumnVar's returns a new expression copy
137  */
138  virtual std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
139  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
140  return deep_copy();
141  };
142  /*
143  * @brief rewrite_agg_to_var rewrite ColumnVar's in expression with entries in an
144  * AggPlan's targetlist. targetlist expressions are expected to be only Var's or
145  * ColumnVar's or AggExpr's All AggExpr's are written into Var's. returns a new
146  * expression copy
147  */
148  virtual std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
149  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const {
150  return deep_copy();
151  }
152  virtual bool operator==(const Expr& rhs) const = 0;
153  virtual std::string toString() const = 0;
154  virtual void print() const { std::cout << toString(); }
155 
156  virtual void add_unique(std::list<const Expr*>& expr_list) const;
157  /*
158  * @brief find_expr traverse Expr hierarchy and adds the node pointer to
159  * the expr_list if the function f returns true.
160  * Duplicate Expr's are not added the list.
161  * Cannot use std::set because we don't have an ordering function.
162  */
163  virtual void find_expr(std::function<bool(const Expr*)> f,
164  std::list<const Expr*>& expr_list) const {
165  if (f(this)) {
166  add_unique(expr_list);
167  }
168  }
169  /*
170  * @brief decompress adds cast operator to decompress encoded result
171  */
172  std::shared_ptr<Analyzer::Expr> decompress();
173  /*
174  * @brief perform domain analysis on Expr and fill in domain
175  * information in domain_set. Empty domain_set means no information.
176  */
177  virtual void get_domain(DomainSet& domain_set) const { domain_set.clear(); }
178 
179  protected:
180  SQLTypeInfo type_info; // SQLTypeInfo of the return result of this expression
182 };
183 
184 using ExpressionPtr = std::shared_ptr<Analyzer::Expr>;
185 using ExpressionPtrList = std::list<ExpressionPtr>;
186 using ExpressionPtrVector = std::vector<ExpressionPtr>;
187 
188 /*
189  * @type ColumnVar
190  * @brief expression that evaluates to the value of a column in a given row from a base
191  * table. It is used in parse trees and is only used in Scan nodes in a query plan for
192  * scanning a table while Var nodes are used for all other plans.
193  */
194 class ColumnVar : public Expr {
195  public:
196  ColumnVar(const SQLTypeInfo& ti, const shared::ColumnKey& column_key, int32_t rte_idx)
197  : Expr(ti), column_key_(column_key), rte_idx_(rte_idx) {}
198  const shared::ColumnKey& getColumnKey() const { return column_key_; }
201  }
202  int32_t get_rte_idx() const { return rte_idx_; }
203  void set_rte_idx(int32_t new_rte_idx) { rte_idx_ = new_rte_idx; }
205 
206  void check_group_by(
207  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
208  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
209  void group_predicates(std::list<const Expr*>& scan_predicates,
210  std::list<const Expr*>& join_predicates,
211  std::list<const Expr*>& const_predicates) const override;
212  void collect_rte_idx(std::set<int32_t>& rte_idx_set) const override {
213  rte_idx_set.insert(rte_idx_);
214  }
215  static bool colvar_comp(const ColumnVar* l, const ColumnVar* r) {
216  CHECK(l);
217  const auto& l_column_key = l->column_key_;
218  CHECK(r);
219  const auto& r_column_key = r->column_key_;
220  return l_column_key < r_column_key;
221  }
223  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
224  colvar_set,
225  bool include_agg) const override {
226  colvar_set.insert(this);
227  }
228 
229  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
230  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
231  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
232  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
233  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
234  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
235  bool operator==(const Expr& rhs) const override;
236  std::string toString() const override;
237 
238  protected:
240  int32_t rte_idx_; // 0-based range table index, used for table ordering in multi-joins
241 };
242 
243 /*
244  * @type ExpressionTuple
245  * @brief A tuple of expressions on the side of an equi-join on multiple columns.
246  * Not to be used in any other context.
247  */
248 class ExpressionTuple : public Expr {
249  public:
250  ExpressionTuple(const std::vector<std::shared_ptr<Analyzer::Expr>>& tuple)
251  : Expr(SQLTypeInfo()), tuple_(tuple){};
252 
253  const std::vector<std::shared_ptr<Analyzer::Expr>>& getTuple() const { return tuple_; }
254 
255  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
256 
257  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
258 
259  bool operator==(const Expr& rhs) const override;
260  std::string toString() const override;
261 
262  private:
263  const std::vector<std::shared_ptr<Analyzer::Expr>> tuple_;
264 };
265 
266 /*
267  * @type Var
268  * @brief expression that evaluates to the value of a column in a given row generated
269  * from a query plan node. It is only used in plan nodes above Scan nodes.
270  * The row can be produced by either the inner or the outer plan in case of a join.
271  * It inherits from ColumnVar to keep track of the lineage through the plan nodes.
272  * The table_id will be set to 0 if the Var does not correspond to an original column
273  * value.
274  */
275 class Var : public ColumnVar {
276  public:
278  Var(const SQLTypeInfo& ti,
279  const shared::ColumnKey& column_key,
280  int32_t rte_idx,
281  WhichRow o,
282  int32_t v)
283  : ColumnVar(ti, column_key, rte_idx), which_row(o), varno(v) {}
284  Var(const SQLTypeInfo& ti, WhichRow o, int32_t v)
285  : ColumnVar(ti, {0, 0, 0}, -1), which_row(o), varno(v) {}
286  WhichRow get_which_row() const { return which_row; }
288  int32_t get_varno() const { return varno; }
289  void set_varno(int32_t n) { varno = n; }
290  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
291  std::string toString() const override;
292  void check_group_by(
293  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
294  void collect_rte_idx(std::set<int32_t>& rte_idx_set) const override {
295  rte_idx_set.insert(-1);
296  }
297  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
298  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
299  return deep_copy();
300  }
301  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
302  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
303  return deep_copy();
304  }
305  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
306  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
307 
308  private:
309  WhichRow which_row; // indicate which row this Var should project from. It can be from
310  // the outer input plan or the inner input plan (for joins) or the
311  // output row in the current plan.
312  int32_t varno; // the column number in the row. 1-based
313 };
314 
315 /*
316  * @type Constant
317  * @brief expression for a constant value
318  */
319 class Constant : public Expr {
320  public:
321  Constant(SQLTypes t, bool n) : Expr(t, !n), is_null(n) {
322  if (n) {
323  set_null_value();
324  } else {
325  type_info.set_notnull(true);
326  }
327  }
328  Constant(SQLTypes t, bool n, Datum v) : Expr(t, !n), is_null(n), constval(v) {
329  if (n) {
330  set_null_value();
331  } else {
332  type_info.set_notnull(true);
333  }
334  }
335  Constant(const SQLTypeInfo& ti, bool n, Datum v) : Expr(ti), is_null(n), constval(v) {
336  if (n) {
337  set_null_value();
338  } else {
339  type_info.set_notnull(true);
340  }
341  }
343  bool n,
344  const std::list<std::shared_ptr<Analyzer::Expr>>& l)
345  : Expr(ti), is_null(n), constval(Datum{0}), value_list(l) {}
346  ~Constant() override;
347  bool get_is_null() const { return is_null; }
348  Datum get_constval() const { return constval; }
349  void set_constval(Datum d) { constval = d; }
350  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
351  return value_list;
352  }
353  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
354  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
355  bool operator==(const Expr& rhs) const override;
356  std::string toString() const override;
357 
358  protected:
359  bool is_null; // constant is NULL
360  Datum constval; // the constant value
361  const std::list<std::shared_ptr<Analyzer::Expr>> value_list;
362  void cast_number(const SQLTypeInfo& new_type_info);
363  void cast_string(const SQLTypeInfo& new_type_info);
364  void cast_from_string(const SQLTypeInfo& new_type_info);
365  void cast_to_string(const SQLTypeInfo& new_type_info);
366  void do_cast(const SQLTypeInfo& new_type_info);
367  void set_null_value();
368 };
369 
370 /*
371  * @type UOper
372  * @brief represents unary operator expressions. operator types include
373  * kUMINUS, kISNULL, kEXISTS, kCAST
374  */
375 class UOper : public Expr {
376  public:
377  UOper(const SQLTypeInfo& ti, bool has_agg, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
378  : Expr(ti, has_agg), optype(o), operand(p) {}
379  UOper(SQLTypes t, SQLOps o, std::shared_ptr<Analyzer::Expr> p)
380  : Expr(t, o == kISNULL ? true : p->get_type_info().get_notnull())
381  , optype(o)
382  , operand(p) {}
383  SQLOps get_optype() const { return optype; }
384  const Expr* get_operand() const { return operand.get(); }
385  const std::shared_ptr<Analyzer::Expr> get_own_operand() const { return operand; }
386  void check_group_by(
387  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
388  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
389  void group_predicates(std::list<const Expr*>& scan_predicates,
390  std::list<const Expr*>& join_predicates,
391  std::list<const Expr*>& const_predicates) const override;
392  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
393  operand->collect_rte_idx(rte_idx_set);
394  }
396  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
397  colvar_set,
398  bool include_agg) const override {
399  operand->collect_column_var(colvar_set, include_agg);
400  }
401  std::shared_ptr<Analyzer::Expr> rewrite_with_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_targetlist(tlist));
405  }
406  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
407  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
408  return makeExpr<UOper>(
409  type_info, contains_agg, optype, operand->rewrite_with_child_targetlist(tlist));
410  }
411  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
412  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
413  return makeExpr<UOper>(
414  type_info, contains_agg, optype, operand->rewrite_agg_to_var(tlist));
415  }
416  bool operator==(const Expr& rhs) const override;
417  std::string toString() const override;
418  void find_expr(std::function<bool(const Expr*)> f,
419  std::list<const Expr*>& expr_list) const override;
420  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
421 
422  protected:
423  SQLOps optype; // operator type, e.g., kUMINUS, kISNULL, kEXISTS
424  std::shared_ptr<Analyzer::Expr> operand; // operand expression
425 };
426 
427 /*
428  * @type BinOper
429  * @brief represents binary operator expressions. it includes all
430  * comparison, arithmetic and boolean binary operators. it handles ANY/ALL qualifiers
431  * in case the right_operand is a subquery.
432  */
433 class BinOper : public Expr {
434  public:
435  BinOper(const SQLTypeInfo& ti,
436  bool has_agg,
437  SQLOps o,
438  SQLQualifier q,
439  std::shared_ptr<Analyzer::Expr> l,
440  std::shared_ptr<Analyzer::Expr> r)
441  : Expr(ti, has_agg), optype(o), qualifier(q), left_operand(l), right_operand(r) {}
443  SQLOps o,
444  SQLQualifier q,
445  std::shared_ptr<Analyzer::Expr> l,
446  std::shared_ptr<Analyzer::Expr> r)
447  : Expr(t, l->get_type_info().get_notnull() && r->get_type_info().get_notnull())
448  , optype(o)
449  , qualifier(q)
450  , left_operand(l)
451  , right_operand(r) {}
452  SQLOps get_optype() const { return optype; }
453  bool is_bbox_intersect_oper() const { return optype == kBBOX_INTERSECT; }
455  const Expr* get_left_operand() const { return left_operand.get(); }
456  const Expr* get_right_operand() const { return right_operand.get(); }
457  const std::shared_ptr<Analyzer::Expr> get_own_left_operand() const {
458  return left_operand;
459  }
460  const std::shared_ptr<Analyzer::Expr> get_own_right_operand() const {
461  return right_operand;
462  }
464  const SQLTypeInfo& left_type,
465  const SQLTypeInfo& right_type,
466  SQLTypeInfo* new_left_type,
467  SQLTypeInfo* new_right_type);
468  static SQLTypeInfo common_numeric_type(const SQLTypeInfo& type1,
469  const SQLTypeInfo& type2);
470  static SQLTypeInfo common_string_type(const SQLTypeInfo& type1,
471  const SQLTypeInfo& type2);
472  void check_group_by(
473  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
474  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
475  std::shared_ptr<Analyzer::Expr> normalize_simple_predicate(int& rte_idx) const override;
476  void group_predicates(std::list<const Expr*>& scan_predicates,
477  std::list<const Expr*>& join_predicates,
478  std::list<const Expr*>& const_predicates) const override;
479  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
480  left_operand->collect_rte_idx(rte_idx_set);
481  right_operand->collect_rte_idx(rte_idx_set);
482  }
484  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
485  colvar_set,
486  bool include_agg) const override {
487  left_operand->collect_column_var(colvar_set, include_agg);
488  right_operand->collect_column_var(colvar_set, include_agg);
489  }
490  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
491  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
492  return makeExpr<BinOper>(type_info,
493  contains_agg,
494  optype,
495  qualifier,
496  left_operand->rewrite_with_targetlist(tlist),
497  right_operand->rewrite_with_targetlist(tlist));
498  }
499  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
500  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
501  return makeExpr<BinOper>(type_info,
502  contains_agg,
503  optype,
504  qualifier,
505  left_operand->rewrite_with_child_targetlist(tlist),
506  right_operand->rewrite_with_child_targetlist(tlist));
507  }
508  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
509  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
510  return makeExpr<BinOper>(type_info,
511  contains_agg,
512  optype,
513  qualifier,
514  left_operand->rewrite_agg_to_var(tlist),
515  right_operand->rewrite_agg_to_var(tlist));
516  }
517  bool operator==(const Expr& rhs) const override;
518  std::string toString() const override;
519  void find_expr(std::function<bool(const Expr*)> f,
520  std::list<const Expr*>& expr_list) const override;
522  const std::shared_ptr<Analyzer::Expr> cast_operand,
523  const std::shared_ptr<Analyzer::Expr> const_operand);
524 
525  private:
526  SQLOps optype; // operator type, e.g., kLT, kAND, kPLUS, etc.
527  SQLQualifier qualifier; // qualifier kANY, kALL or kONE. Only relevant with
528  // right_operand is Subquery
529  std::shared_ptr<Analyzer::Expr> left_operand; // the left operand expression
530  std::shared_ptr<Analyzer::Expr> right_operand; // the right operand expression
531 };
532 
537 class RangeOper : public Expr {
538  public:
539  RangeOper(const bool l_inclusive,
540  const bool r_inclusive,
541  std::shared_ptr<Analyzer::Expr> l,
542  std::shared_ptr<Analyzer::Expr> r)
543  : Expr(SQLTypeInfo(kNULLT), /*not_null=*/false)
544  , left_inclusive_(l_inclusive)
545  , right_inclusive_(r_inclusive)
546  , left_operand_(l)
547  , right_operand_(r) {
550  }
551 
552  const Expr* get_left_operand() const { return left_operand_.get(); }
553  const Expr* get_right_operand() const { return right_operand_.get(); }
554 
555  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
556  bool operator==(const Expr& rhs) const override;
557  std::string toString() const override;
558 
559  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
560  left_operand_->collect_rte_idx(rte_idx_set);
561  right_operand_->collect_rte_idx(rte_idx_set);
562  }
563 
565  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
566  colvar_set,
567  bool include_agg) const override {
568  left_operand_->collect_column_var(colvar_set, include_agg);
569  right_operand_->collect_column_var(colvar_set, include_agg);
570  }
571 
572  private:
573  // build a range between these two operands
576  std::shared_ptr<Analyzer::Expr> left_operand_;
577  std::shared_ptr<Analyzer::Expr> right_operand_;
578 };
579 
580 class Query;
581 
582 /*
583  * @type Subquery
584  * @brief subquery expression. Note that the type of the expression is the type of the
585  * TargetEntry in the subquery instead of the set.
586  */
587 class Subquery : public Expr {
588  public:
589  Subquery(const SQLTypeInfo& ti, Query* q)
590  : Expr(ti), parsetree(q) /*, plan(nullptr)*/ {}
591  ~Subquery() override;
592  const Query* get_parsetree() const { return parsetree; }
593  // const Plan *get_plan() const { return plan; }
594  // void set_plan(Plan *p) { plan = p; } // subquery plan is set by the optimizer
595  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
596  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
597  void group_predicates(std::list<const Expr*>& scan_predicates,
598  std::list<const Expr*>& join_predicates,
599  std::list<const Expr*>& const_predicates) const override {
600  CHECK(false);
601  }
602  void collect_rte_idx(std::set<int>& rte_idx_set) const override { CHECK(false); }
604  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
605  colvar_set,
606  bool include_agg) const override {
607  CHECK(false);
608  }
609  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
610  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
611  abort();
612  }
613  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
614  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
615  abort();
616  }
617  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
618  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
619  abort();
620  }
621  bool operator==(const Expr& rhs) const override {
622  CHECK(false);
623  return false;
624  }
625  std::string toString() const override;
626  void find_expr(std::function<bool(const Expr*)> f,
627  std::list<const Expr*>& expr_list) const override {
628  CHECK(false);
629  }
630 
631  private:
632  Query* parsetree; // parse tree of the subquery
633 };
634 
635 /*
636  * @type InValues
637  * @brief represents predicate expr IN (v1, v2, ...)
638  * v1, v2, ... are can be either Constant or Parameter.
639  */
640 class InValues : public Expr {
641  public:
642  InValues(std::shared_ptr<Analyzer::Expr> a,
643  const std::list<std::shared_ptr<Analyzer::Expr>>& l);
644  const Expr* get_arg() const { return arg.get(); }
645  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
646  const std::list<std::shared_ptr<Analyzer::Expr>>& get_value_list() const {
647  return value_list;
648  }
649  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
650  void group_predicates(std::list<const Expr*>& scan_predicates,
651  std::list<const Expr*>& join_predicates,
652  std::list<const Expr*>& const_predicates) const override;
653  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
654  arg->collect_rte_idx(rte_idx_set);
655  }
657  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
658  colvar_set,
659  bool include_agg) const override {
660  arg->collect_column_var(colvar_set, include_agg);
661  }
662  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
663  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
664  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
665  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
666  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
667  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
668  bool operator==(const Expr& rhs) const override;
669  std::string toString() const override;
670  void find_expr(std::function<bool(const Expr*)> f,
671  std::list<const Expr*>& expr_list) const override;
672 
673  private:
674  std::shared_ptr<Analyzer::Expr> arg; // the argument left of IN
675  const std::list<std::shared_ptr<Analyzer::Expr>>
676  value_list; // the list of values right of IN
677 };
678 
679 /*
680  * @type InIntegerSet
681  * @brief represents predicate expr IN (v1, v2, ...) for the case where the right
682  * hand side is a list of integers or dictionary-encoded strings generated
683  * by a IN subquery. Avoids the overhead of storing a list of shared pointers
684  * to Constant objects, making it more suitable for IN sub-queries usage.
685  * v1, v2, ... are integers
686  */
687 class InIntegerSet : public Expr {
688  public:
689  InIntegerSet(const std::shared_ptr<const Analyzer::Expr> a,
690  const std::vector<int64_t>& values,
691  const bool not_null);
692 
693  const Expr* get_arg() const { return arg.get(); }
694 
695  const std::vector<int64_t>& get_value_list() const { return value_list; }
696 
697  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
698 
699  bool operator==(const Expr& rhs) const override;
700  std::string toString() const override;
701 
702  private:
703  const std::shared_ptr<const Analyzer::Expr> arg; // the argument left of IN
704  const std::vector<int64_t> value_list; // the list of values right of IN
705 };
706 
707 class MLPredictExpr : public Expr {
708  public:
709  MLPredictExpr(const std::shared_ptr<Analyzer::Expr>& model,
710  const std::vector<std::shared_ptr<Analyzer::Expr>>& regressors)
711  : Expr(kDOUBLE, false), model_value_(model), regressor_values_(regressors) {}
712 
713  const Expr* get_model_value() const { return model_value_.get(); }
714  const std::vector<std::shared_ptr<Analyzer::Expr>>& get_regressor_values() const {
715  return regressor_values_;
716  }
717  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
718 
719  void group_predicates(std::list<const Expr*>& scan_predicates,
720  std::list<const Expr*>& join_predicates,
721  std::list<const Expr*>& const_predicates) const override;
722 
723  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
724  for (const auto& regressor_value : regressor_values_) {
725  regressor_value->collect_rte_idx(rte_idx_set);
726  }
727  }
728 
730  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
731  colvar_set,
732  bool include_agg) const override {
733  for (const auto& regressor_value : regressor_values_) {
734  regressor_value->collect_column_var(colvar_set, include_agg);
735  }
736  }
737 
738  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
739  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
740  std::vector<std::shared_ptr<Analyzer::Expr>> new_regressor_values;
741  for (auto& r : regressor_values_) {
742  new_regressor_values.push_back(r->deep_copy());
743  }
744  return makeExpr<MLPredictExpr>(model_value_->rewrite_with_targetlist(tlist),
745  new_regressor_values);
746  }
747 
748  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
749  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
750  std::vector<std::shared_ptr<Analyzer::Expr>> new_regressor_values;
751  for (auto& r : regressor_values_) {
752  new_regressor_values.push_back(r->deep_copy());
753  }
754  return makeExpr<MLPredictExpr>(model_value_->rewrite_with_child_targetlist(tlist),
755  new_regressor_values);
756  }
757 
758  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
759  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
760  std::vector<std::shared_ptr<Analyzer::Expr>> new_regressor_values;
761  for (auto& r : regressor_values_) {
762  new_regressor_values.push_back(r->deep_copy());
763  }
764  return makeExpr<MLPredictExpr>(model_value_->rewrite_agg_to_var(tlist),
765  new_regressor_values);
766  }
767 
768  bool operator==(const Expr& rhs) const override;
769  std::string toString() const override;
770  void find_expr(std::function<bool(const Expr*)> f,
771  std::list<const Expr*>& expr_list) const override;
772 
773  private:
774  std::shared_ptr<Analyzer::Expr> model_value_;
775  std::vector<std::shared_ptr<Analyzer::Expr>> regressor_values_;
776 };
777 
778 class PCAProjectExpr : public Expr {
779  public:
780  PCAProjectExpr(const std::shared_ptr<Analyzer::Expr>& model,
781  const std::vector<std::shared_ptr<Analyzer::Expr>>& features,
782  const std::shared_ptr<Analyzer::Expr>& pc_dimension)
783  : Expr(kDOUBLE, false)
784  , model_value_(model)
785  , feature_values_(features)
786  , pc_dimension_value_(pc_dimension) {}
787 
788  const Expr* get_model_value() const { return model_value_.get(); }
789  const std::vector<std::shared_ptr<Analyzer::Expr>>& get_feature_values() const {
790  return feature_values_;
791  }
792  const Expr* get_pc_dimension_value() const { return pc_dimension_value_.get(); }
793  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
794 
795  void group_predicates(std::list<const Expr*>& scan_predicates,
796  std::list<const Expr*>& join_predicates,
797  std::list<const Expr*>& const_predicates) const override;
798 
799  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
800  for (const auto& feature_value : feature_values_) {
801  feature_value->collect_rte_idx(rte_idx_set);
802  }
803  }
804 
806  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
807  colvar_set,
808  bool include_agg) const override {
809  for (const auto& feature_value : feature_values_) {
810  feature_value->collect_column_var(colvar_set, include_agg);
811  }
812  }
813 
814  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
815  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
816  std::vector<std::shared_ptr<Analyzer::Expr>> new_feature_values;
817  for (auto& r : feature_values_) {
818  new_feature_values.push_back(r->deep_copy());
819  }
820  return makeExpr<PCAProjectExpr>(model_value_->rewrite_with_targetlist(tlist),
821  new_feature_values,
822  pc_dimension_value_->rewrite_with_targetlist(tlist));
823  }
824 
825  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
826  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
827  std::vector<std::shared_ptr<Analyzer::Expr>> new_feature_values;
828  for (auto& r : feature_values_) {
829  new_feature_values.push_back(r->deep_copy());
830  }
831  return makeExpr<PCAProjectExpr>(
832  model_value_->rewrite_with_child_targetlist(tlist),
833  new_feature_values,
834  pc_dimension_value_->rewrite_with_child_targetlist(tlist));
835  }
836 
837  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
838  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
839  std::vector<std::shared_ptr<Analyzer::Expr>> new_feature_values;
840  for (auto& r : feature_values_) {
841  new_feature_values.push_back(r->deep_copy());
842  }
843  return makeExpr<PCAProjectExpr>(model_value_->rewrite_agg_to_var(tlist),
844  new_feature_values,
845  pc_dimension_value_->rewrite_agg_to_var(tlist));
846  }
847 
848  bool operator==(const Expr& rhs) const override;
849  std::string toString() const override;
850  void find_expr(std::function<bool(const Expr*)> f,
851  std::list<const Expr*>& expr_list) const override;
852 
853  private:
854  std::shared_ptr<Analyzer::Expr> model_value_;
855  std::vector<std::shared_ptr<Analyzer::Expr>> feature_values_;
856  std::shared_ptr<Analyzer::Expr> pc_dimension_value_;
857 };
858 
859 /*
860  * @type CharLengthExpr
861  * @brief expression for the CHAR_LENGTH expression.
862  * arg must evaluate to char, varchar or text.
863  */
864 class CharLengthExpr : public Expr {
865  public:
866  CharLengthExpr(std::shared_ptr<Analyzer::Expr> a, bool e)
867  : Expr(kINT, a->get_type_info().get_notnull()), arg(a), calc_encoded_length(e) {}
868  const Expr* get_arg() const { return arg.get(); }
869  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
871  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
872  void group_predicates(std::list<const Expr*>& scan_predicates,
873  std::list<const Expr*>& join_predicates,
874  std::list<const Expr*>& const_predicates) const override;
875  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
876  arg->collect_rte_idx(rte_idx_set);
877  }
879  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
880  colvar_set,
881  bool include_agg) const override {
882  arg->collect_column_var(colvar_set, include_agg);
883  }
884  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
885  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
886  return makeExpr<CharLengthExpr>(arg->rewrite_with_targetlist(tlist),
888  }
889  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
890  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
891  return makeExpr<CharLengthExpr>(arg->rewrite_with_child_targetlist(tlist),
893  }
894  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
895  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
896  return makeExpr<CharLengthExpr>(arg->rewrite_agg_to_var(tlist), calc_encoded_length);
897  }
898  bool operator==(const Expr& rhs) const override;
899  std::string toString() const override;
900  void find_expr(std::function<bool(const Expr*)> f,
901  std::list<const Expr*>& expr_list) const override;
902 
903  private:
904  std::shared_ptr<Analyzer::Expr> arg;
906 };
907 
908 /*
909  * @type KeyForStringExpr
910  * @brief expression for the KEY_FOR_STRING expression.
911  * arg must be a dict encoded column, not str literal.
912  */
913 class KeyForStringExpr : public Expr {
914  public:
915  KeyForStringExpr(std::shared_ptr<Analyzer::Expr> a)
916  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
917  const Expr* get_arg() const { return arg.get(); }
918  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
919  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
920  void group_predicates(std::list<const Expr*>& scan_predicates,
921  std::list<const Expr*>& join_predicates,
922  std::list<const Expr*>& const_predicates) const override;
923  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
924  arg->collect_rte_idx(rte_idx_set);
925  }
927  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
928  colvar_set,
929  bool include_agg) const override {
930  arg->collect_column_var(colvar_set, include_agg);
931  }
932  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
933  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
934  return makeExpr<KeyForStringExpr>(arg->rewrite_with_targetlist(tlist));
935  }
936  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
937  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
938  return makeExpr<KeyForStringExpr>(arg->rewrite_with_child_targetlist(tlist));
939  }
940  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
941  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
942  return makeExpr<KeyForStringExpr>(arg->rewrite_agg_to_var(tlist));
943  }
944  bool operator==(const Expr& rhs) const override;
945  std::string toString() const override;
946  void find_expr(std::function<bool(const Expr*)> f,
947  std::list<const Expr*>& expr_list) const override;
948 
949  private:
950  std::shared_ptr<Analyzer::Expr> arg;
951 };
952 
953 /*
954  * @type SampleRatioExpr
955  * @brief expression for the SAMPLE_RATIO expression. Argument range is expected to be
956  * between 0 and 1.
957  */
958 class SampleRatioExpr : public Expr {
959  public:
960  SampleRatioExpr(std::shared_ptr<Analyzer::Expr> a)
961  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a) {}
962  const Expr* get_arg() const { return arg.get(); }
963  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
964  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
965  void group_predicates(std::list<const Expr*>& scan_predicates,
966  std::list<const Expr*>& join_predicates,
967  std::list<const Expr*>& const_predicates) const override;
968  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
969  arg->collect_rte_idx(rte_idx_set);
970  }
972  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
973  colvar_set,
974  bool include_agg) const override {
975  arg->collect_column_var(colvar_set, include_agg);
976  }
977  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
978  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
979  return makeExpr<SampleRatioExpr>(arg->rewrite_with_targetlist(tlist));
980  }
981  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
982  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
983  return makeExpr<SampleRatioExpr>(arg->rewrite_with_child_targetlist(tlist));
984  }
985  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
986  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
987  return makeExpr<SampleRatioExpr>(arg->rewrite_agg_to_var(tlist));
988  }
989  bool operator==(const Expr& rhs) const override;
990  std::string toString() const override;
991  void find_expr(std::function<bool(const Expr*)> f,
992  std::list<const Expr*>& expr_list) const override;
993 
994  private:
995  std::shared_ptr<Analyzer::Expr> arg;
996 };
997 
998 /*
999  * @type CardinalityExpr
1000  * @brief expression for the CARDINALITY expression.
1001  * arg must evaluate to array (or multiset when supported).
1002  */
1003 class CardinalityExpr : public Expr {
1004  public:
1005  CardinalityExpr(std::shared_ptr<Analyzer::Expr> a)
1006  : Expr(kINT, a->get_type_info().get_notnull()), arg(a) {}
1007  const Expr* get_arg() const { return arg.get(); }
1008  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1009  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1010  void group_predicates(std::list<const Expr*>& scan_predicates,
1011  std::list<const Expr*>& join_predicates,
1012  std::list<const Expr*>& const_predicates) const override;
1013  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1014  arg->collect_rte_idx(rte_idx_set);
1015  }
1017  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1018  colvar_set,
1019  bool include_agg) const override {
1020  arg->collect_column_var(colvar_set, include_agg);
1021  }
1022  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1023  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1024  return makeExpr<CardinalityExpr>(arg->rewrite_with_targetlist(tlist));
1025  }
1026  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1027  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1028  return makeExpr<CardinalityExpr>(arg->rewrite_with_child_targetlist(tlist));
1029  }
1030  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1031  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1032  return makeExpr<CardinalityExpr>(arg->rewrite_agg_to_var(tlist));
1033  }
1034  bool operator==(const Expr& rhs) const override;
1035  std::string toString() const override;
1036  void find_expr(std::function<bool(const Expr*)> f,
1037  std::list<const Expr*>& expr_list) const override;
1038 
1039  private:
1040  std::shared_ptr<Analyzer::Expr> arg;
1041 };
1042 
1043 /*
1044  * @type LikeExpr
1045  * @brief expression for the LIKE predicate.
1046  * arg must evaluate to char, varchar or text.
1047  */
1048 class LikeExpr : public Expr {
1049  public:
1050  LikeExpr(std::shared_ptr<Analyzer::Expr> a,
1051  std::shared_ptr<Analyzer::Expr> l,
1052  std::shared_ptr<Analyzer::Expr> e,
1053  bool i,
1054  bool s)
1055  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
1056  , arg(a)
1057  , like_expr(l)
1058  , escape_expr(e)
1059  , is_ilike(i)
1060  , is_simple(s) {}
1061  const Expr* get_arg() const { return arg.get(); }
1062  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1063  const Expr* get_like_expr() const { return like_expr.get(); }
1064  const Expr* get_escape_expr() const { return escape_expr.get(); }
1065  bool get_is_ilike() const { return is_ilike; }
1066  bool get_is_simple() const { return is_simple; }
1067  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1068  void group_predicates(std::list<const Expr*>& scan_predicates,
1069  std::list<const Expr*>& join_predicates,
1070  std::list<const Expr*>& const_predicates) const override;
1071  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1072  arg->collect_rte_idx(rte_idx_set);
1073  }
1075  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1076  colvar_set,
1077  bool include_agg) const override {
1078  arg->collect_column_var(colvar_set, include_agg);
1079  }
1080  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1081  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1082  return makeExpr<LikeExpr>(arg->rewrite_with_targetlist(tlist),
1083  like_expr->deep_copy(),
1084  escape_expr ? escape_expr->deep_copy() : nullptr,
1085  is_ilike,
1086  is_simple);
1087  }
1088  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1089  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1090  return makeExpr<LikeExpr>(arg->rewrite_with_child_targetlist(tlist),
1091  like_expr->deep_copy(),
1092  escape_expr ? escape_expr->deep_copy() : nullptr,
1093  is_ilike,
1094  is_simple);
1095  }
1096  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1097  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1098  return makeExpr<LikeExpr>(arg->rewrite_agg_to_var(tlist),
1099  like_expr->deep_copy(),
1100  escape_expr ? escape_expr->deep_copy() : nullptr,
1101  is_ilike,
1102  is_simple);
1103  }
1104  bool operator==(const Expr& rhs) const override;
1105  std::string toString() const override;
1106  void find_expr(std::function<bool(const Expr*)> f,
1107  std::list<const Expr*>& expr_list) const override;
1108 
1109  private:
1110  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of LIKE
1111  std::shared_ptr<Analyzer::Expr> like_expr; // expression that evaluates to like string
1112  std::shared_ptr<Analyzer::Expr>
1113  escape_expr; // expression that evaluates to escape string, can be nullptr
1114  bool is_ilike; // is this ILIKE?
1115  bool is_simple; // is this simple, meaning we can use fast path search (fits '%str%'
1116  // pattern with no inner '%','_','[',']'
1117 };
1118 
1119 /*
1120  * @type RegexpExpr
1121  * @brief expression for REGEXP.
1122  * arg must evaluate to char, varchar or text.
1123  */
1124 class RegexpExpr : public Expr {
1125  public:
1126  RegexpExpr(std::shared_ptr<Analyzer::Expr> a,
1127  std::shared_ptr<Analyzer::Expr> p,
1128  std::shared_ptr<Analyzer::Expr> e)
1129  : Expr(kBOOLEAN, a->get_type_info().get_notnull())
1130  , arg(a)
1131  , pattern_expr(p)
1132  , escape_expr(e) {}
1133  const Expr* get_arg() const { return arg.get(); }
1134  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1135  const Expr* get_pattern_expr() const { return pattern_expr.get(); }
1136  const Expr* get_escape_expr() const { return escape_expr.get(); }
1137  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1138  void group_predicates(std::list<const Expr*>& scan_predicates,
1139  std::list<const Expr*>& join_predicates,
1140  std::list<const Expr*>& const_predicates) const override;
1141  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1142  arg->collect_rte_idx(rte_idx_set);
1143  }
1145  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1146  colvar_set,
1147  bool include_agg) const override {
1148  arg->collect_column_var(colvar_set, include_agg);
1149  }
1150  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1151  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1152  return makeExpr<RegexpExpr>(arg->rewrite_with_targetlist(tlist),
1153  pattern_expr->deep_copy(),
1154  escape_expr ? escape_expr->deep_copy() : nullptr);
1155  }
1156  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1157  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1158  return makeExpr<RegexpExpr>(arg->rewrite_with_child_targetlist(tlist),
1159  pattern_expr->deep_copy(),
1160  escape_expr ? escape_expr->deep_copy() : nullptr);
1161  }
1162  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1163  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1164  return makeExpr<RegexpExpr>(arg->rewrite_agg_to_var(tlist),
1165  pattern_expr->deep_copy(),
1166  escape_expr ? escape_expr->deep_copy() : nullptr);
1167  }
1168  bool operator==(const Expr& rhs) const override;
1169  std::string toString() const override;
1170  void find_expr(std::function<bool(const Expr*)> f,
1171  std::list<const Expr*>& expr_list) const override;
1172 
1173  private:
1174  std::shared_ptr<Analyzer::Expr> arg; // the argument to the left of REGEXP
1175  std::shared_ptr<Analyzer::Expr>
1176  pattern_expr; // expression that evaluates to pattern string
1177  std::shared_ptr<Analyzer::Expr>
1178  escape_expr; // expression that evaluates to escape string, can be nullptr
1179 };
1180 
1181 /*
1182  * @type WidthBucketExpr
1183  * @brief expression for width_bucket functions.
1184  */
1185 class WidthBucketExpr : public Expr {
1186  public:
1187  WidthBucketExpr(const std::shared_ptr<Analyzer::Expr> target_value,
1188  const std::shared_ptr<Analyzer::Expr> lower_bound,
1189  const std::shared_ptr<Analyzer::Expr> upper_bound,
1190  const std::shared_ptr<Analyzer::Expr> partition_count)
1191  : Expr(kINT, target_value->get_type_info().get_notnull())
1192  , target_value_(target_value)
1193  , lower_bound_(lower_bound)
1194  , upper_bound_(upper_bound)
1195  , partition_count_(partition_count)
1198  const Expr* get_target_value() const { return target_value_.get(); }
1199  const Expr* get_lower_bound() const { return lower_bound_.get(); }
1200  const Expr* get_upper_bound() const { return upper_bound_.get(); }
1201  const Expr* get_partition_count() const { return partition_count_.get(); }
1202  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1203  void group_predicates(std::list<const Expr*>& scan_predicates,
1204  std::list<const Expr*>& join_predicates,
1205  std::list<const Expr*>& const_predicates) const override;
1206  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1207  target_value_->collect_rte_idx(rte_idx_set);
1208  }
1210  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1211  colvar_set,
1212  bool include_agg) const override {
1213  target_value_->collect_column_var(colvar_set, include_agg);
1214  }
1215  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1216  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1217  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_targetlist(tlist),
1218  lower_bound_,
1219  upper_bound_,
1221  }
1222  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1223  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1224  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_child_targetlist(tlist),
1225  lower_bound_,
1226  upper_bound_,
1228  }
1229  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1230  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1231  return makeExpr<WidthBucketExpr>(target_value_->rewrite_agg_to_var(tlist),
1232  lower_bound_,
1233  upper_bound_,
1235  }
1236  double get_bound_val(const Analyzer::Expr* bound_expr) const;
1237  int32_t get_partition_count_val() const;
1238  int32_t compute_bucket(double target_const_val) const;
1239  bool operator==(const Expr& rhs) const override;
1240  std::string toString() const override;
1241  void find_expr(std::function<bool(const Expr*)> f,
1242  std::list<const Expr*>& expr_list) const override;
1245  void set_constant_expr() const { constant_expr_ = true; }
1246  bool is_constant_expr() const { return constant_expr_; }
1247 
1248  private:
1249  std::shared_ptr<Analyzer::Expr> target_value_; // target value expression
1250  std::shared_ptr<Analyzer::Expr> lower_bound_; // lower_bound
1251  std::shared_ptr<Analyzer::Expr> upper_bound_; // upper_bound
1252  std::shared_ptr<Analyzer::Expr> partition_count_; // partition_count
1253  // true if lower, upper and partition count exprs are constant
1254  mutable bool constant_expr_;
1255  // true if we can skip oob check and is determined within compile time
1257 };
1258 
1259 /*
1260  * @type LikelihoodExpr
1261  * @brief expression for LIKELY and UNLIKELY boolean identity functions.
1262  */
1263 class LikelihoodExpr : public Expr {
1264  public:
1265  LikelihoodExpr(std::shared_ptr<Analyzer::Expr> a, float l = 0.5)
1266  : Expr(kBOOLEAN, a->get_type_info().get_notnull()), arg(a), likelihood(l) {}
1267  const Expr* get_arg() const { return arg.get(); }
1268  const std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1269  float get_likelihood() const { return likelihood; }
1270  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1271  void group_predicates(std::list<const Expr*>& scan_predicates,
1272  std::list<const Expr*>& join_predicates,
1273  std::list<const Expr*>& const_predicates) const override;
1274  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1275  arg->collect_rte_idx(rte_idx_set);
1276  }
1278  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1279  colvar_set,
1280  bool include_agg) const override {
1281  arg->collect_column_var(colvar_set, include_agg);
1282  }
1283  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1284  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1285  return makeExpr<LikelihoodExpr>(arg->rewrite_with_targetlist(tlist), likelihood);
1286  }
1287  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1288  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1289  return makeExpr<LikelihoodExpr>(arg->rewrite_with_child_targetlist(tlist),
1290  likelihood);
1291  }
1292  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1293  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override {
1294  return makeExpr<LikelihoodExpr>(arg->rewrite_agg_to_var(tlist), likelihood);
1295  }
1296  bool operator==(const Expr& rhs) const override;
1297  std::string toString() const override;
1298  void find_expr(std::function<bool(const Expr*)> f,
1299  std::list<const Expr*>& expr_list) const override;
1300 
1301  private:
1302  std::shared_ptr<Analyzer::Expr> arg; // the argument to LIKELY, UNLIKELY
1303  float likelihood;
1304 };
1305 
1306 /*
1307  * @type AggExpr
1308  * @brief expression for builtin SQL aggregates.
1309  */
1310 class AggExpr : public Expr {
1311  public:
1313  SQLAgg a,
1314  std::shared_ptr<Analyzer::Expr> g,
1315  bool d,
1316  std::shared_ptr<Analyzer::Expr> e)
1317  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), arg1(e) {}
1319  SQLAgg a,
1320  Expr* g,
1321  bool d,
1322  std::shared_ptr<Analyzer::Expr> e,
1323  int idx)
1324  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1325  , aggtype(a)
1326  , arg(g)
1327  , is_distinct(d)
1328  , arg1(e) {}
1329  SQLAgg get_aggtype() const { return aggtype; }
1330  Expr* get_arg() const { return arg.get(); }
1331  std::shared_ptr<Analyzer::Expr> get_own_arg() const { return arg; }
1332  bool get_is_distinct() const { return is_distinct; }
1333  std::shared_ptr<Analyzer::Expr> get_arg1() const { return arg1; }
1334  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1335  void group_predicates(std::list<const Expr*>& scan_predicates,
1336  std::list<const Expr*>& join_predicates,
1337  std::list<const Expr*>& const_predicates) const override;
1338  void collect_rte_idx(std::set<int>& rte_idx_set) const override {
1339  if (arg) {
1340  arg->collect_rte_idx(rte_idx_set);
1341  }
1342  };
1344  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1345  colvar_set,
1346  bool include_agg) const override {
1347  if (include_agg && arg != nullptr) {
1348  arg->collect_column_var(colvar_set, include_agg);
1349  }
1350  }
1351  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1352  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1353  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1354  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1355  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1356  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1357  bool operator==(const Expr& rhs) const override;
1358  std::string toString() const override;
1359  void find_expr(std::function<bool(const Expr*)> f,
1360  std::list<const Expr*>& expr_list) const override;
1361 
1362  private:
1363  SQLAgg aggtype; // aggregate type: kAVG, kMIN, kMAX, kSUM, kCOUNT
1364  std::shared_ptr<Analyzer::Expr> arg; // argument to aggregate
1365  bool is_distinct; // true only if it is for COUNT(DISTINCT x)
1366  // APPROX_COUNT_DISTINCT error_rate, APPROX_QUANTILE quantile
1367  std::shared_ptr<Analyzer::Expr> arg1;
1368 };
1369 
1370 /*
1371  * @type CaseExpr
1372  * @brief the CASE-WHEN-THEN-ELSE expression
1373  */
1374 class CaseExpr : public Expr {
1375  public:
1377  bool has_agg,
1378  const std::list<std::pair<std::shared_ptr<Analyzer::Expr>,
1379  std::shared_ptr<Analyzer::Expr>>>& w,
1380  std::shared_ptr<Analyzer::Expr> e)
1381  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
1382  const std::list<
1383  std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>&
1385  return expr_pair_list;
1386  }
1387  const Expr* get_else_expr() const { return else_expr.get(); }
1388  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1389  void check_group_by(
1390  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1391  void group_predicates(std::list<const Expr*>& scan_predicates,
1392  std::list<const Expr*>& join_predicates,
1393  std::list<const Expr*>& const_predicates) const override;
1394  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1395  void collect_column_var(
1396  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1397  colvar_set,
1398  bool include_agg) const override;
1399  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1400  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1401  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1402  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1403  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1404  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1405  bool operator==(const Expr& rhs) const override;
1406  std::string toString() const override;
1407  void find_expr(std::function<bool(const Expr*)> f,
1408  std::list<const Expr*>& expr_list) const override;
1409  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) override;
1410  void get_domain(DomainSet& domain_set) const override;
1411 
1412  private:
1413  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1414  expr_pair_list; // a pair of expressions for each WHEN expr1 THEN expr2. expr1
1415  // must be of boolean type. all expr2's must be of compatible
1416  // types and will be promoted to the common type.
1417  std::shared_ptr<Analyzer::Expr> else_expr; // expression for ELSE. nullptr if omitted.
1418 };
1419 
1420 /*
1421  * @type ExtractExpr
1422  * @brief the EXTRACT expression
1423  */
1424 class ExtractExpr : public Expr {
1425  public:
1427  bool has_agg,
1428  ExtractField f,
1429  std::shared_ptr<Analyzer::Expr> e)
1430  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1431  ExtractField get_field() const { return field_; }
1432  const Expr* get_from_expr() const { return from_expr_.get(); }
1433  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1434  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1435  void check_group_by(
1436  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1437  void group_predicates(std::list<const Expr*>& scan_predicates,
1438  std::list<const Expr*>& join_predicates,
1439  std::list<const Expr*>& const_predicates) const override;
1440  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1441  void collect_column_var(
1442  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1443  colvar_set,
1444  bool include_agg) const override;
1445  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1446  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1447  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1448  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1449  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1450  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1451  bool operator==(const Expr& rhs) const override;
1452  std::string toString() const override;
1453  void find_expr(std::function<bool(const Expr*)> f,
1454  std::list<const Expr*>& expr_list) const override;
1455 
1456  private:
1458  std::shared_ptr<Analyzer::Expr> from_expr_;
1459 };
1460 
1461 /*
1462  * @type DateaddExpr
1463  * @brief the DATEADD expression
1464  */
1465 class DateaddExpr : public Expr {
1466  public:
1468  const DateaddField f,
1469  const std::shared_ptr<Analyzer::Expr> number,
1470  const std::shared_ptr<Analyzer::Expr> datetime)
1471  : Expr(ti, false)
1472  , field_(f)
1473  , number_(number)
1474  , datetime_(datetime)
1476  DateaddField get_field() const { return field_; }
1477  const Expr* get_number_expr() const { return number_.get(); }
1478  const Expr* get_datetime_expr() const { return datetime_.get(); }
1481  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1482  void check_group_by(
1483  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1484  void group_predicates(std::list<const Expr*>& scan_predicates,
1485  std::list<const Expr*>& join_predicates,
1486  std::list<const Expr*>& const_predicates) const override;
1487  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1488  void collect_column_var(
1489  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1490  colvar_set,
1491  bool include_agg) const override;
1492  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1493  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1494  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1495  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1496  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1497  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1498  bool operator==(const Expr& rhs) const override;
1499  std::string toString() const override;
1500  void find_expr(std::function<bool(const Expr*)> f,
1501  std::list<const Expr*>& expr_list) const override;
1502 
1503  private:
1505  const std::shared_ptr<Analyzer::Expr> number_;
1506  const std::shared_ptr<Analyzer::Expr> datetime_;
1507  // if expr (i.e., column_var) of datetime has fixed encoding but is not casted
1508  // to nullable int64_t type before generating a code for this dateAdd expr,
1509  // we manually set this to deal with such case during the codegen
1511 };
1512 
1513 /*
1514  * @type DatediffExpr
1515  * @brief the DATEDIFF expression
1516  */
1517 class DatediffExpr : public Expr {
1518  public:
1520  const DatetruncField f,
1521  const std::shared_ptr<Analyzer::Expr> start,
1522  const std::shared_ptr<Analyzer::Expr> end)
1523  : Expr(ti, false), field_(f), start_(start), end_(end) {}
1524  DatetruncField get_field() const { return field_; }
1525  const Expr* get_start_expr() const { return start_.get(); }
1526  const Expr* get_end_expr() const { return end_.get(); }
1527  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1528  void check_group_by(
1529  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1530  void group_predicates(std::list<const Expr*>& scan_predicates,
1531  std::list<const Expr*>& join_predicates,
1532  std::list<const Expr*>& const_predicates) const override;
1533  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1534  void collect_column_var(
1535  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1536  colvar_set,
1537  bool include_agg) const override;
1538  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1539  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1540  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1541  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1542  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1543  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1544  bool operator==(const Expr& rhs) const override;
1545  std::string toString() const override;
1546  void find_expr(std::function<bool(const Expr*)> f,
1547  std::list<const Expr*>& expr_list) const override;
1548 
1549  private:
1551  const std::shared_ptr<Analyzer::Expr> start_;
1552  const std::shared_ptr<Analyzer::Expr> end_;
1553 };
1554 
1555 /*
1556  * @type DatetruncExpr
1557  * @brief the DATE_TRUNC expression
1558  */
1559 class DatetruncExpr : public Expr {
1560  public:
1562  bool has_agg,
1563  DatetruncField f,
1564  std::shared_ptr<Analyzer::Expr> e)
1565  : Expr(ti, has_agg), field_(f), from_expr_(e) {}
1566  DatetruncField get_field() const { return field_; }
1567  const Expr* get_from_expr() const { return from_expr_.get(); }
1568  const std::shared_ptr<Analyzer::Expr> get_own_from_expr() const { return from_expr_; }
1569  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1570  void check_group_by(
1571  const std::list<std::shared_ptr<Analyzer::Expr>>& groupby) const override;
1572  void group_predicates(std::list<const Expr*>& scan_predicates,
1573  std::list<const Expr*>& join_predicates,
1574  std::list<const Expr*>& const_predicates) const override;
1575  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1576  void collect_column_var(
1577  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1578  colvar_set,
1579  bool include_agg) const override;
1580  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1581  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1582  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1583  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1584  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1585  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1586  bool operator==(const Expr& rhs) const override;
1587  std::string toString() const override;
1588  void find_expr(std::function<bool(const Expr*)> f,
1589  std::list<const Expr*>& expr_list) const override;
1590 
1591  private:
1593  std::shared_ptr<Analyzer::Expr> from_expr_;
1594 };
1595 
1601 class StringOper : public Expr {
1602  public:
1603  // Todo(todd): Set nullability based on literals too
1604 
1606 
1608  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1609  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {}
1610 
1612  const SQLTypeInfo& return_ti,
1613  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
1614  : Expr(return_ti), kind_(kind), args_(args) {}
1615 
1617  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1618  const size_t min_args,
1619  const std::vector<OperandTypeFamily>& expected_type_families,
1620  const std::vector<std::string>& arg_names)
1621  : Expr(StringOper::get_return_type(kind, args)), kind_(kind), args_(args) {
1623  min_args,
1624  expected_type_families,
1625  arg_names,
1626  false /* dict_encoded_cols_only */,
1627  !(kind == SqlStringOpKind::CONCAT || kind == SqlStringOpKind::RCONCAT ||
1629  kind == SqlStringOpKind::LEVENSHTEIN_DISTANCE) /* cols_first_arg_only */);
1630  }
1631 
1633  const SQLTypeInfo& return_ti,
1634  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1635  const size_t min_args,
1636  const std::vector<OperandTypeFamily>& expected_type_families,
1637  const std::vector<std::string>& arg_names)
1638  : Expr(return_ti), kind_(kind), args_(args) {
1640  min_args,
1641  expected_type_families,
1642  arg_names,
1643  false /* dict_encoded_cols_only */,
1644  !(kind == SqlStringOpKind::CONCAT || kind == SqlStringOpKind::RCONCAT ||
1646  kind == SqlStringOpKind::LEVENSHTEIN_DISTANCE) /* cols_first_arg_only */);
1647  }
1648 
1650  const SQLTypeInfo& return_ti,
1651  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
1652  const std::vector<std::shared_ptr<Analyzer::Expr>>& chained_string_op_exprs)
1653  : Expr(return_ti)
1654  , kind_(kind)
1655  , args_(args)
1656  , chained_string_op_exprs_(chained_string_op_exprs) {}
1657 
1658  StringOper(const StringOper& other_string_oper)
1659  : Expr(other_string_oper.get_type_info()) {
1660  kind_ = other_string_oper.kind_;
1661  args_ = other_string_oper.args_;
1663  }
1664 
1665  StringOper(const std::shared_ptr<StringOper>& other_string_oper)
1666  : Expr(other_string_oper->get_type_info()) {
1667  kind_ = other_string_oper->kind_;
1668  args_ = other_string_oper->args_;
1669  chained_string_op_exprs_ = other_string_oper->chained_string_op_exprs_;
1670  }
1671 
1672  SqlStringOpKind get_kind() const { return kind_; }
1673 
1674  size_t getArity() const { return args_.size(); }
1675 
1676  size_t getLiteralsArity() const {
1677  size_t num_literals{0UL};
1678  for (const auto& arg : args_) {
1679  if (dynamic_cast<const Constant*>(arg.get())) {
1680  num_literals++;
1681  }
1682  }
1683  return num_literals;
1684  }
1685 
1686  size_t getNonLiteralsArity() const { return getArity() - getLiteralsArity(); }
1687 
1688  const Expr* getArg(const size_t i) const {
1689  CHECK_LT(i, args_.size());
1690  return args_[i].get();
1691  }
1692 
1693  std::shared_ptr<Analyzer::Expr> getOwnArg(const size_t i) const {
1694  CHECK_LT(i, args_.size());
1695  return args_[i];
1696  }
1697 
1698  std::vector<std::shared_ptr<Analyzer::Expr>> getOwnArgs() const { return args_; }
1699 
1700  std::vector<std::shared_ptr<Analyzer::Expr>> getChainedStringOpExprs() const {
1701  return chained_string_op_exprs_;
1702  }
1703 
1705  const auto& return_ti = get_type_info();
1706  if (return_ti.is_none_encoded_string() ||
1707  (return_ti.is_dict_encoded_string() &&
1708  return_ti.getStringDictKey().isTransientDict())) {
1709  return true;
1710  }
1711 
1712  // Anything that returns the transient dictionary by definition
1713  // (see StringOper::get_return_type) requires per-row translation,
1714  // but there is also a path with string->numeric functions (the output is
1715  // not a string) where we need to see if any of the inputs are none-encoded
1716  // or transient dictionary encoded, in which case we also need to do per-row
1717  // translation. The handling of that condition follows below.
1718 
1719  size_t num_var_str_args{0};
1720  for (const auto& arg : args_) {
1721  const auto arg_is_const = dynamic_cast<const Analyzer::Constant*>(arg.get());
1722  if (arg_is_const) {
1723  continue;
1724  }
1725  const auto& arg_ti = arg->get_type_info();
1726  if (arg_ti.is_none_encoded_string() ||
1727  (arg_ti.is_dict_encoded_string() &&
1728  arg_ti.getStringDictKey().isTransientDict())) {
1729  return true;
1730  }
1731  num_var_str_args++;
1732  }
1733  return num_var_str_args > 1UL;
1734  }
1735 
1736  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
1737 
1738  void collect_column_var(
1739  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
1740  colvar_set,
1741  bool include_agg) const override;
1742 
1743  bool hasNoneEncodedTextArg() const {
1744  if (args_.empty()) {
1745  return false;
1746  }
1747  const auto& arg0_ti = args_[0]->get_type_info();
1748  if (!arg0_ti.is_string()) {
1749  return false;
1750  }
1751  if (arg0_ti.is_none_encoded_string()) {
1752  return true;
1753  }
1754  CHECK(arg0_ti.is_dict_encoded_string());
1755  return arg0_ti.getStringDictKey().isTransientDict();
1756  }
1757 
1765  bool hasSingleDictEncodedColInput() const;
1766 
1767  std::vector<size_t> getLiteralArgIndexes() const;
1768 
1769  using LiteralArgMap = std::map<size_t, std::pair<SQLTypes, Datum>>;
1770 
1771  LiteralArgMap getLiteralArgs() const;
1772 
1773  std::shared_ptr<Analyzer::Expr> rewrite_with_targetlist(
1774  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1775 
1776  std::shared_ptr<Analyzer::Expr> rewrite_with_child_targetlist(
1777  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1778 
1779  std::shared_ptr<Analyzer::Expr> rewrite_agg_to_var(
1780  const std::vector<std::shared_ptr<TargetEntry>>& tlist) const override;
1781 
1782  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1783 
1784  void group_predicates(std::list<const Expr*>& scan_predicates,
1785  std::list<const Expr*>& join_predicates,
1786  std::list<const Expr*>& const_predicates) const override;
1787 
1788  bool operator==(const Expr& rhs) const override;
1789 
1790  std::string toString() const override;
1791 
1792  void find_expr(std::function<bool(const Expr*)> f,
1793  std::list<const Expr*>& expr_list) const override;
1794 
1795  virtual size_t getMinArgs() const {
1796  CHECK(false);
1797  return {};
1798  }
1799  virtual std::vector<OperandTypeFamily> getExpectedTypeFamilies() const {
1800  CHECK(false);
1801  return {};
1802  }
1803  virtual std::vector<std::string> getArgNames() const {
1804  CHECK(false);
1805  return {};
1806  }
1807 
1808  private:
1810  const SqlStringOpKind kind,
1811  const std::vector<std::shared_ptr<Analyzer::Expr>>& args);
1812 
1813  void check_operand_types(const size_t min_args,
1814  const std::vector<OperandTypeFamily>& expected_type_families,
1815  const std::vector<std::string>& arg_names,
1816  const bool dict_encoded_cols_only = false,
1817  const bool cols_first_arg_only = true) const;
1818 
1820  std::vector<std::shared_ptr<Analyzer::Expr>> args_;
1821  std::vector<std::shared_ptr<Analyzer::Expr>> chained_string_op_exprs_;
1822 };
1823 
1824 class LowerStringOper : public StringOper {
1825  public:
1826  LowerStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1828  {operand},
1829  getMinArgs(),
1832 
1833  LowerStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1835  operands,
1836  getMinArgs(),
1838  getArgNames()) {}
1839 
1840  LowerStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1841  : StringOper(string_oper) {}
1842 
1843  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1844 
1845  size_t getMinArgs() const override { return 1UL; }
1846 
1847  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1849  }
1850 
1851  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1852 };
1853 class UpperStringOper : public StringOper {
1854  public:
1855  UpperStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1857  {operand},
1858  getMinArgs(),
1861 
1862  UpperStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1864  operands,
1865  getMinArgs(),
1867  getArgNames()) {}
1868 
1869  UpperStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1870  : StringOper(string_oper) {}
1871 
1872  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1873 
1874  size_t getMinArgs() const override { return 1UL; }
1875 
1876  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1878  }
1879 
1880  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1881 };
1882 
1884  public:
1885  InitCapStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1887  {operand},
1888  getMinArgs(),
1891 
1892  InitCapStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1894  operands,
1895  getMinArgs(),
1897  getArgNames()) {}
1898 
1899  InitCapStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1900  : StringOper(string_oper) {}
1901 
1902  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1903 
1904  size_t getMinArgs() const override { return 1UL; }
1905 
1906  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1908  }
1909  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1910 };
1911 
1913  public:
1914  ReverseStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
1916  {operand},
1917  getMinArgs(),
1920 
1921  ReverseStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1923  operands,
1924  getMinArgs(),
1926  getArgNames()) {}
1927 
1928  ReverseStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1929  : StringOper(string_oper) {}
1930 
1931  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1932 
1933  size_t getMinArgs() const override { return 1UL; }
1934 
1935  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1937  }
1938  std::vector<std::string> getArgNames() const override { return {"operand"}; }
1939 };
1940 
1942  public:
1943  RepeatStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
1944  const std::shared_ptr<Analyzer::Expr>& num_repeats)
1946  {operand, num_repeats},
1947  getMinArgs(),
1950 
1951  RepeatStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1953  operands,
1954  getMinArgs(),
1956  getArgNames()) {}
1957 
1958  RepeatStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1959  : StringOper(string_oper) {}
1960 
1961  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1962 
1963  size_t getMinArgs() const override { return 2UL; }
1964 
1965  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
1967  }
1968  std::vector<std::string> getArgNames() const override {
1969  return {"operand", "num_repeats"};
1970  }
1971 };
1972 
1974  public:
1975  ConcatStringOper(const std::shared_ptr<Analyzer::Expr>& left_operand,
1976  const std::shared_ptr<Analyzer::Expr>& right_operand)
1977  : StringOper(
1978  ConcatStringOper::get_concat_ordered_kind({left_operand, right_operand}),
1979  ConcatStringOper::normalize_operands({left_operand, right_operand}),
1980  getMinArgs(),
1983 
1984  ConcatStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
1987  getMinArgs(),
1989  getArgNames()) {}
1990 
1991  ConcatStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
1992  : StringOper(string_oper) {}
1993 
1994  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
1995 
1996  size_t getMinArgs() const override { return 2UL; }
1997 
1998  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2000  }
2001  std::vector<std::string> getArgNames() const override {
2002  return {"left operand", "right operand"};
2003  }
2004 
2005  private:
2007  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
2008 
2009  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
2010  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
2011 };
2012 
2013 class PadStringOper : public StringOper {
2014  public:
2015  PadStringOper(const SqlStringOpKind pad_op_kind,
2016  const std::shared_ptr<Analyzer::Expr>& operand,
2017  const std::shared_ptr<Analyzer::Expr>& padded_length,
2018  const std::shared_ptr<Analyzer::Expr>& padding_str)
2020  {operand, padded_length, padding_str},
2021  getMinArgs(),
2024 
2025  PadStringOper(const SqlStringOpKind pad_op_kind,
2026  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2028  operands,
2029  getMinArgs(),
2031  getArgNames()) {}
2032 
2033  PadStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2034  : StringOper(string_oper) {}
2035 
2036  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2037 
2038  size_t getMinArgs() const override { return 3UL; }
2039 
2040  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2044  }
2045  std::vector<std::string> getArgNames() const override {
2046  return {"operand", "padded length", "padding string"};
2047  }
2048 
2049  private:
2051 };
2052 
2053 class TrimStringOper : public StringOper {
2054  public:
2055  TrimStringOper(const SqlStringOpKind trim_op_kind,
2056  const std::shared_ptr<Analyzer::Expr>& operand,
2057  const std::shared_ptr<Analyzer::Expr>& trim_chars)
2059  {operand, trim_chars},
2060  getMinArgs(),
2063 
2064  TrimStringOper(const SqlStringOpKind trim_op_kind,
2065  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2066  : StringOper(TrimStringOper::get_and_validate_trim_op_kind(trim_op_kind, operands),
2067  TrimStringOper::normalize_operands(operands, trim_op_kind),
2068  getMinArgs(),
2070  getArgNames()) {}
2071 
2072  TrimStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2073  : StringOper(string_oper) {}
2074 
2075  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2076 
2077  size_t getMinArgs() const override { return 2UL; }
2078 
2079  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2081  }
2082  std::vector<std::string> getArgNames() const override {
2083  return {"operand", "trim_chars"};
2084  }
2085 
2086  private:
2088  if (!(trim_op_kind == SqlStringOpKind::TRIM ||
2089  trim_op_kind == SqlStringOpKind::LTRIM ||
2090  trim_op_kind == SqlStringOpKind::RTRIM)) {
2091  // Arguably should CHECK here
2092  throw std::runtime_error("Invalid trim type supplied to TRIM operator");
2093  }
2094  return trim_op_kind;
2095  }
2096 
2098  const SqlStringOpKind trim_op_kind_maybe,
2099  const std::vector<std::shared_ptr<Analyzer::Expr>>& args);
2100 
2101  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
2102  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands,
2103  const SqlStringOpKind string_op_kind);
2104 };
2105 
2107  public:
2108  SubstringStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2109  const std::shared_ptr<Analyzer::Expr>& start_pos)
2111  {operand, start_pos},
2112  getMinArgs(),
2115 
2116  SubstringStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2117  const std::shared_ptr<Analyzer::Expr>& start_pos,
2118  const std::shared_ptr<Analyzer::Expr>& length)
2120  {operand, start_pos, length},
2121  getMinArgs(),
2124 
2125  SubstringStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2127  operands,
2128  getMinArgs(),
2130  getArgNames()) {}
2131 
2132  SubstringStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2133  : StringOper(string_oper) {}
2134 
2135  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2136 
2137  size_t getMinArgs() const override { return 2UL; }
2138 
2139  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2142  OperandTypeFamily::INT_FAMILY};
2143  }
2144  std::vector<std::string> getArgNames() const override {
2145  return {"operand", "start position", "substring length"};
2146  }
2147 };
2148 
2150  public:
2151  OverlayStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2152  const std::shared_ptr<Analyzer::Expr>& replacing_str,
2153  const std::shared_ptr<Analyzer::Expr>& start_pos)
2155  {operand, replacing_str, start_pos},
2156  getMinArgs(),
2159 
2160  OverlayStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2161  const std::shared_ptr<Analyzer::Expr>& replacing_str,
2162  const std::shared_ptr<Analyzer::Expr>& start_pos,
2163  const std::shared_ptr<Analyzer::Expr>& replacing_length)
2165  {operand, replacing_str, start_pos, replacing_length},
2166  getMinArgs(),
2169 
2170  OverlayStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2171  : StringOper(string_oper) {}
2172 
2173  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2174 
2175  OverlayStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2177  operands,
2178  getMinArgs(),
2180  getArgNames()) {}
2181 
2182  size_t getMinArgs() const override { return 3UL; }
2183 
2184  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2188  OperandTypeFamily::INT_FAMILY};
2189  }
2190  std::vector<std::string> getArgNames() const override {
2191  return {"operand", "replacing string", "start position", "replacing length"};
2192  }
2193 };
2194 
2196  public:
2197  ReplaceStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2198  const std::shared_ptr<Analyzer::Expr>& search_pattern,
2199  const std::shared_ptr<Analyzer::Expr>& replacing_str)
2201  {operand, search_pattern, replacing_str},
2202  getMinArgs(),
2205 
2206  ReplaceStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2208  operands,
2209  getMinArgs(),
2211  getArgNames()) {}
2212 
2213  ReplaceStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2214  : StringOper(string_oper) {}
2215 
2216  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2217 
2218  size_t getMinArgs() const override { return 3UL; }
2219 
2220  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2223  OperandTypeFamily::STRING_FAMILY};
2224  }
2225  std::vector<std::string> getArgNames() const override {
2226  return {"operand", "search pattern", "replacing string"};
2227  }
2228 };
2229 
2231  public:
2232  SplitPartStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2233  const std::shared_ptr<Analyzer::Expr>& delimiter,
2234  const std::shared_ptr<Analyzer::Expr>& split_index)
2236  {operand, delimiter, split_index},
2237  getMinArgs(),
2240 
2241  SplitPartStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2243  operands,
2244  getMinArgs(),
2246  getArgNames()) {}
2247 
2248  SplitPartStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2249  : StringOper(string_oper) {}
2250 
2251  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2252 
2253  size_t getMinArgs() const override { return 3UL; }
2254 
2255  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2259  }
2260  std::vector<std::string> getArgNames() const override {
2261  return {"operand", "delimiter", "split index"};
2262  }
2263 };
2264 
2266  public:
2267  RegexpReplaceStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2268  const std::shared_ptr<Analyzer::Expr>& regex_pattern,
2269  const std::shared_ptr<Analyzer::Expr>& replacing_str,
2270  const std::shared_ptr<Analyzer::Expr>& start_pos,
2271  const std::shared_ptr<Analyzer::Expr>& occurrence,
2272  const std::shared_ptr<Analyzer::Expr>& regex_params)
2273  : StringOper(
2275  {operand, regex_pattern, replacing_str, start_pos, occurrence, regex_params},
2276  getMinArgs(),
2279 
2280  RegexpReplaceStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2282  operands,
2283  getMinArgs(),
2285  getArgNames()) {}
2286 
2287  RegexpReplaceStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2288  : StringOper(string_oper) {}
2289 
2290  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2291 
2292  size_t getMinArgs() const override { return 6UL; }
2293 
2294  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2300  OperandTypeFamily::STRING_FAMILY};
2301  }
2302  std::vector<std::string> getArgNames() const override {
2303  return {"operand",
2304  "regex pattern",
2305  "replacing string",
2306  "start position",
2307  "occurrence",
2308  "regex parameters"};
2309  }
2310 };
2311 
2313  public:
2314  RegexpSubstrStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2315  const std::shared_ptr<Analyzer::Expr>& regex_pattern,
2316  const std::shared_ptr<Analyzer::Expr>& start_pos,
2317  const std::shared_ptr<Analyzer::Expr>& occurrence,
2318  const std::shared_ptr<Analyzer::Expr>& regex_params,
2319  const std::shared_ptr<Analyzer::Expr>& sub_match_group_idx)
2321  {operand,
2322  regex_pattern,
2323  start_pos,
2324  occurrence,
2325  regex_params,
2326  sub_match_group_idx},
2327  getMinArgs(),
2330 
2331  RegexpSubstrStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2333  operands,
2334  getMinArgs(),
2336  getArgNames()) {}
2337 
2338  RegexpSubstrStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2339  : StringOper(string_oper) {}
2340 
2341  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2342 
2343  size_t getMinArgs() const override { return 6UL; }
2344 
2345  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2351  OperandTypeFamily::INT_FAMILY};
2352  }
2353  std::vector<std::string> getArgNames() const override {
2354  return {"operand",
2355  "regex pattern",
2356  "start position",
2357  "occurrence",
2358  "regex parameters",
2359  "sub-match group index"};
2360  }
2361 };
2362 
2364  public:
2365  RegexpCountStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2366  const std::shared_ptr<Analyzer::Expr>& regex_pattern,
2367  const std::shared_ptr<Analyzer::Expr>& start_pos,
2368  const std::shared_ptr<Analyzer::Expr>& regex_params)
2371  {operand, regex_pattern, start_pos, regex_params},
2372  getMinArgs(),
2375 
2376  RegexpCountStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2379  operands,
2380  getMinArgs(),
2382  getArgNames()) {}
2383 
2384  RegexpCountStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2385  : StringOper(string_oper) {}
2386 
2387  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2388 
2389  size_t getMinArgs() const override { return 4UL; }
2390 
2391  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2395  OperandTypeFamily::STRING_FAMILY};
2396  }
2397  std::vector<std::string> getArgNames() const override {
2398  return {"operand", "regex pattern", "start position", "regex parameters"};
2399  }
2400 };
2401 
2403  public:
2404  JsonValueStringOper(const std::shared_ptr<Analyzer::Expr>& operand,
2405  const std::shared_ptr<Analyzer::Expr>& json_path)
2407  {operand, json_path},
2408  getMinArgs(),
2411 
2412  JsonValueStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2414  operands,
2415  getMinArgs(),
2417  getArgNames()) {}
2418 
2419  JsonValueStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2420  : StringOper(string_oper) {}
2421 
2422  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2423 
2424  size_t getMinArgs() const override { return 2UL; }
2425 
2426  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2428  }
2429  std::vector<std::string> getArgNames() const override {
2430  return {"operand", "JSON path"};
2431  }
2432 };
2433 
2435  public:
2436  Base64EncodeStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
2438  {operand},
2439  getMinArgs(),
2442 
2443  Base64EncodeStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2445  operands,
2446  getMinArgs(),
2448  getArgNames()) {}
2449 
2450  Base64EncodeStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2451  : StringOper(string_oper) {}
2452 
2453  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2454 
2455  size_t getMinArgs() const override { return 1UL; }
2456 
2457  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2459  }
2460  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2461 };
2462 
2464  public:
2465  Base64DecodeStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
2467  {operand},
2468  getMinArgs(),
2471 
2472  Base64DecodeStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2474  operands,
2475  getMinArgs(),
2477  getArgNames()) {}
2478 
2479  Base64DecodeStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2480  : StringOper(string_oper) {}
2481 
2482  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2483 
2484  size_t getMinArgs() const override { return 1UL; }
2485 
2486  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2488  }
2489  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2490 };
2491 
2493  public:
2494  UrlEncodeStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
2496  {operand},
2497  getMinArgs(),
2500 
2501  UrlEncodeStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2503  operands,
2504  getMinArgs(),
2506  getArgNames()) {}
2507 
2508  UrlEncodeStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2509  : StringOper(string_oper) {}
2510 
2511  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2512 
2513  size_t getMinArgs() const override { return 1u; }
2514 
2515  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2517  }
2518 
2519  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2520 };
2521 
2523  public:
2524  UrlDecodeStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
2526  {operand},
2527  getMinArgs(),
2530 
2531  UrlDecodeStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2533  operands,
2534  getMinArgs(),
2536  getArgNames()) {}
2537 
2538  UrlDecodeStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2539  : StringOper(string_oper) {}
2540 
2541  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2542 
2543  size_t getMinArgs() const override { return 1u; }
2544 
2545  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2547  }
2548 
2549  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2550 };
2551 
2553  public:
2554  TryStringCastOper(const SQLTypeInfo& ti, const std::shared_ptr<Analyzer::Expr>& operand)
2556  ti,
2557  {operand},
2558  getMinArgs(),
2561 
2563  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2565  ti,
2566  operands,
2567  getMinArgs(),
2569  getArgNames()) {}
2570 
2571  TryStringCastOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2572  : StringOper(string_oper) {}
2573 
2574  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2575 
2576  size_t getMinArgs() const override { return 1UL; }
2577 
2578  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2580  }
2581  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2582 };
2583 
2585  public:
2586  PositionStringOper(const std::shared_ptr<Analyzer::Expr>& search_str,
2587  const std::shared_ptr<Analyzer::Expr>& source_str,
2588  const std::shared_ptr<Analyzer::Expr>& start_offset)
2591  {source_str, search_str, start_offset},
2592  getMinArgs(),
2595 
2596  PositionStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2600  getMinArgs(),
2602  getArgNames()) {}
2603 
2604  PositionStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2605  : StringOper(string_oper) {}
2606 
2607  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2608 
2609  size_t getMinArgs() const override { return 2UL; }
2610 
2611  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2615  }
2616  std::vector<std::string> getArgNames() const override {
2617  return {"search string", "source string", "start position"};
2618  }
2619 
2620  private:
2621  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
2622  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
2623 };
2624 
2626  public:
2627  JarowinklerSimilarityStringOper(const std::shared_ptr<Analyzer::Expr>& left_operand,
2628  const std::shared_ptr<Analyzer::Expr>& right_operand)
2632  {left_operand, right_operand}),
2633  getMinArgs(),
2636 
2638  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2642  getMinArgs(),
2644  getArgNames()) {}
2645 
2647  const std::shared_ptr<Analyzer::StringOper>& string_oper)
2648  : StringOper(string_oper) {}
2649 
2650  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2651 
2652  size_t getMinArgs() const override { return 2UL; }
2653 
2654  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2656  }
2657  std::vector<std::string> getArgNames() const override {
2658  return {"left operand", "right operand"};
2659  }
2660 
2661  private:
2662  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
2663  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
2664 };
2665 
2667  public:
2668  LevenshteinDistanceStringOper(const std::shared_ptr<Analyzer::Expr>& left_operand,
2669  const std::shared_ptr<Analyzer::Expr>& right_operand)
2673  {left_operand, right_operand}),
2674  getMinArgs(),
2677 
2679  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2683  getMinArgs(),
2685  getArgNames()) {}
2686 
2687  LevenshteinDistanceStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2688  : StringOper(string_oper) {}
2689 
2690  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2691 
2692  size_t getMinArgs() const override { return 2UL; }
2693 
2694  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2696  }
2697  std::vector<std::string> getArgNames() const override {
2698  return {"left operand", "right operand"};
2699  }
2700 
2701  private:
2702  static std::vector<std::shared_ptr<Analyzer::Expr>> normalize_operands(
2703  const std::vector<std::shared_ptr<Analyzer::Expr>>& operands);
2704 };
2705 
2706 class HashStringOper : public StringOper {
2707  public:
2708  HashStringOper(const std::shared_ptr<Analyzer::Expr>& operand)
2711  {operand},
2712  getMinArgs(),
2715 
2716  HashStringOper(const std::vector<std::shared_ptr<Analyzer::Expr>>& operands)
2719  operands,
2720  getMinArgs(),
2722  getArgNames()) {}
2723 
2724  HashStringOper(const std::shared_ptr<Analyzer::StringOper>& string_oper)
2725  : StringOper(string_oper) {}
2726 
2727  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2728 
2729  size_t getMinArgs() const override { return 1UL; }
2730 
2731  std::vector<OperandTypeFamily> getExpectedTypeFamilies() const override {
2733  }
2734  std::vector<std::string> getArgNames() const override { return {"operand"}; }
2735 };
2736 
2737 class FunctionOper : public Expr {
2738  public:
2740  const std::string& name,
2741  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
2742  : Expr(ti, false), name_(name), args_(args) {}
2743 
2744  std::string getName() const { return name_; }
2745 
2746  size_t getArity() const { return args_.size(); }
2747 
2748  const Analyzer::Expr* getArg(const size_t i) const {
2749  CHECK_LT(i, args_.size());
2750  return args_[i].get();
2751  }
2752 
2753  std::shared_ptr<Analyzer::Expr> getOwnArg(const size_t i) const {
2754  CHECK_LT(i, args_.size());
2755  return args_[i];
2756  }
2757 
2758  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2759  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
2760  void collect_column_var(
2761  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
2762  colvar_set,
2763  bool include_agg) const override;
2764  void find_expr(std::function<bool(const Expr*)> f,
2765  std::list<const Expr*>& expr_list) const override;
2766 
2767  bool operator==(const Expr& rhs) const override;
2768  std::string toString() const override;
2769 
2770  private:
2771  const std::string name_;
2772  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
2773 };
2774 
2776  public:
2778  const SQLTypeInfo& ti,
2779  const std::string& name,
2780  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
2781  : FunctionOper(ti, name, args) {}
2782 
2783  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2784 
2785  bool operator==(const Expr& rhs) const override;
2786 };
2787 
2788 /*
2789  * @type OffsetInFragment
2790  * @brief The offset of a row in the current fragment. To be used by updates.
2791  */
2792 class OffsetInFragment : public Expr {
2793  public:
2795 
2796  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2797 
2798  bool operator==(const Expr& rhs) const override;
2799  std::string toString() const override;
2800 };
2801 
2802 /*
2803  * @type OrderEntry
2804  * @brief represents an entry in ORDER BY clause.
2805  */
2806 struct OrderEntry {
2807  OrderEntry(int t, bool d, bool nf) : tle_no(t), is_desc(d), nulls_first(nf){};
2809  std::string toString() const;
2810  void print() const { std::cout << toString(); }
2811  int tle_no; /* targetlist entry number: 1-based */
2812  bool is_desc; /* true if order is DESC */
2813  bool nulls_first; /* true if nulls are ordered first. otherwise last. */
2814 };
2815 
2816 /*
2817  * @type WindowFrame
2818  * @brief A window frame bound.
2819  */
2820 class WindowFrame : public Expr {
2821  public:
2823  const std::shared_ptr<Analyzer::Expr> bound_expr)
2824  : Expr(SQLTypeInfo(kVOID)), bound_type_(bound_type), bound_expr_(bound_expr) {}
2825 
2827 
2828  const Analyzer::Expr* getBoundExpr() const {
2829  CHECK(bound_expr_);
2830  return bound_expr_.get();
2831  }
2832 
2834  if (bound_expr_) {
2835  const auto bound_ti = bound_expr_->get_type_info();
2836  return bound_ti.is_date() || bound_ti.is_timestamp();
2837  }
2838  return false;
2839  }
2840 
2841  bool isCurrentRowBound() const {
2843  }
2844 
2845  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2846 
2847  bool operator==(const Expr& rhs) const override;
2848 
2849  std::string toString() const override;
2850 
2851  private:
2853  const std::shared_ptr<Analyzer::Expr> bound_expr_;
2854 };
2855 
2856 /*
2857  * @type WindowFunction
2858  * @brief A window function.
2859  */
2860 class WindowFunction : public Expr {
2861  public:
2862  enum class FrameBoundType { NONE, ROW, RANGE };
2863  static constexpr std::array<SqlWindowFunctionKind, 14> FRAMING_ALLOWED_WINDOW_FUNCS{
2878  static constexpr std::array<SqlWindowFunctionKind, 9>
2889  static constexpr std::array<SqlWindowFunctionKind, 2> FILLING_FUNCS_USING_WINDOW{
2892  static constexpr std::array<SqlWindowFunctionKind, 7> REQUIRE_HASH_TABLE_FOR_FRAMING{
2900 
2902  const SqlWindowFunctionKind kind,
2903  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
2904  const std::vector<std::shared_ptr<Analyzer::Expr>>& partition_keys,
2905  const std::vector<std::shared_ptr<Analyzer::Expr>>& order_keys,
2906  const FrameBoundType frame_bound_type,
2907  const std::shared_ptr<Expr> frame_start_bound,
2908  const std::shared_ptr<Expr> frame_end_bound,
2909  const std::vector<OrderEntry>& collation)
2910  : Expr(ti)
2911  , kind_(kind)
2912  , args_(args)
2913  , partition_keys_(partition_keys)
2914  , order_keys_(order_keys)
2915  , frame_bound_type_(frame_bound_type)
2916  , frame_start_bound_(frame_start_bound)
2917  , frame_end_bound_(frame_end_bound)
2918  , collation_(collation){};
2919 
2920  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
2921 
2922  bool operator==(const Expr& rhs) const override;
2923  std::string toString() const override;
2924 
2926 
2927  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs() const { return args_; }
2928 
2929  const std::vector<std::shared_ptr<Analyzer::Expr>>& getPartitionKeys() const {
2930  return partition_keys_;
2931  }
2932 
2933  const std::vector<std::shared_ptr<Analyzer::Expr>>& getOrderKeys() const {
2934  return order_keys_;
2935  }
2936 
2938  std::shared_ptr<WindowFrame> frame_start_bound =
2939  std::dynamic_pointer_cast<WindowFrame>(frame_start_bound_);
2940  CHECK(frame_start_bound);
2941  return frame_start_bound.get();
2942  }
2943 
2945  std::shared_ptr<WindowFrame> frame_end_bound =
2946  std::dynamic_pointer_cast<WindowFrame>(frame_end_bound_);
2947  CHECK(frame_end_bound);
2948  return frame_end_bound.get();
2949  }
2950 
2951  const std::vector<OrderEntry>& getCollation() const { return collation_; }
2952 
2954  return frame_bound_type_;
2955  }
2956 
2958 
2960 
2961  bool hasFraming() const {
2964  }
2965 
2967  return std::any_of(
2970  [kind](SqlWindowFunctionKind target_kind) { return kind == target_kind; });
2971  }
2972 
2974  return std::any_of(
2977  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2978  }
2980  return std::any_of(
2983  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2984  }
2985 
2987  return std::any_of(
2990  [this](SqlWindowFunctionKind target_kind) { return kind_ == target_kind; });
2991  }
2992 
2993  private:
2995  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
2996  const std::vector<std::shared_ptr<Analyzer::Expr>> partition_keys_;
2997  const std::vector<std::shared_ptr<Analyzer::Expr>> order_keys_;
2999  const std::shared_ptr<Analyzer::Expr> frame_start_bound_;
3000  const std::shared_ptr<Analyzer::Expr> frame_end_bound_;
3001  const std::vector<OrderEntry> collation_;
3002 };
3003 
3004 /*
3005  * @type ArrayExpr
3006  * @brief Corresponds to ARRAY[] statements in SQL
3007  */
3008 
3009 class ArrayExpr : public Expr {
3010  public:
3011  ArrayExpr(SQLTypeInfo const& array_ti,
3012  ExpressionPtrVector const& array_exprs,
3013  bool is_null = false,
3014  bool local_alloc = false)
3015  : Expr(array_ti)
3016  , contained_expressions_(array_exprs)
3017  , local_alloc_(local_alloc)
3018  , is_null_(is_null) {}
3019 
3020  Analyzer::ExpressionPtr deep_copy() const override;
3021  std::string toString() const override;
3022  bool operator==(Expr const& rhs) const override;
3023  size_t getElementCount() const { return contained_expressions_.size(); }
3024  bool isLocalAlloc() const { return local_alloc_; }
3025  bool isNull() const { return is_null_; }
3026 
3027  const Analyzer::Expr* getElement(const size_t i) const {
3028  CHECK_LT(i, contained_expressions_.size());
3029  return contained_expressions_[i].get();
3030  }
3031 
3032  void collect_rte_idx(std::set<int>& rte_idx_set) const override;
3033  void collect_column_var(
3034  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
3035  colvar_set,
3036  bool include_agg) const override;
3037 
3038  private:
3041  bool is_null_; // constant is NULL
3042 };
3043 
3044 /*
3045  * @type GeoUOper
3046  * @brief Geo unary operation
3047  */
3048 class GeoUOper : public Expr {
3049  public:
3051  const SQLTypeInfo& ti,
3052  const SQLTypeInfo& ti0,
3053  const std::vector<std::shared_ptr<Analyzer::Expr>>& args)
3054  : Expr(ti), op_(op), ti0_(ti0), args0_(args){};
3055 
3056  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
3057 
3058  bool operator==(const Expr& rhs) const override;
3059  std::string toString() const override;
3060 
3062  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
3063  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
3064 
3065  private:
3067  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
3068  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
3069 };
3070 
3071 /*
3072  * @type GeoBinOper
3073  * @brief Geo binary operation
3074  */
3075 class GeoBinOper : public Expr {
3076  public:
3078  const SQLTypeInfo& ti,
3079  const SQLTypeInfo& ti0,
3080  const SQLTypeInfo& ti1,
3081  const std::vector<std::shared_ptr<Analyzer::Expr>>& args0,
3082  const std::vector<std::shared_ptr<Analyzer::Expr>>& args1)
3083  : Expr(ti), op_(op), ti0_(ti0), ti1_(ti1), args0_(args0), args1_(args1){};
3084 
3085  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
3086 
3087  bool operator==(const Expr& rhs) const override;
3088  std::string toString() const override;
3089 
3091  const SQLTypeInfo getTypeInfo0() const { return ti0_; }
3092  const SQLTypeInfo getTypeInfo1() const { return ti1_; }
3093  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs0() const { return args0_; }
3094  const std::vector<std::shared_ptr<Analyzer::Expr>>& getArgs1() const { return args1_; }
3095 
3096  private:
3098  SQLTypeInfo ti0_; // Type of geo input 0 (or geo output)
3099  SQLTypeInfo ti1_; // Type of geo input 1
3100  const std::vector<std::shared_ptr<Analyzer::Expr>> args0_;
3101  const std::vector<std::shared_ptr<Analyzer::Expr>> args1_;
3102 };
3103 
3104 /*
3105  * @type TargetEntry
3106  * @brief Target list defines a relational projection. It is a list of TargetEntry's.
3107  */
3109  public:
3110  TargetEntry(const std::string& n, std::shared_ptr<Analyzer::Expr> e, bool u)
3111  : resname(n), expr(e), unnest(u) {}
3112  virtual ~TargetEntry() {}
3113  const std::string& get_resname() const { return resname; }
3114  void set_resname(const std::string& name) { resname = name; }
3115  Expr* get_expr() const { return expr.get(); }
3116  std::shared_ptr<Expr> get_own_expr() const { return expr; }
3117  void set_expr(std::shared_ptr<Analyzer::Expr> e) { expr = e; }
3118  bool get_unnest() const { return unnest; }
3119  std::string toString() const;
3120  void print() const { std::cout << toString(); }
3121 
3122  private:
3123  std::string resname; // alias name, e.g., SELECT salary + bonus AS compensation,
3124  std::shared_ptr<Analyzer::Expr> expr; // expression to evaluate for the value
3125  bool unnest; // unnest a collection type
3126 };
3127 
3128 class RangeTableEntry;
3129 
3130 /*
3131  * @type Query
3132  * @brief parse tree for a query
3133  */
3134 class Query {
3135  public:
3137  : is_distinct(false)
3138  , where_predicate(nullptr)
3139  , having_predicate(nullptr)
3140  , order_by(nullptr)
3141  , next_query(nullptr)
3142  , is_unionall(false)
3143  , stmt_type(kSELECT)
3144  , num_aggs(0)
3145  , result_table_id(0)
3146  , limit(0)
3147  , offset(0) {}
3148  virtual ~Query();
3149  bool get_is_distinct() const { return is_distinct; }
3150  int get_num_aggs() const { return num_aggs; }
3151  const std::vector<std::shared_ptr<TargetEntry>>& get_targetlist() const {
3152  return targetlist;
3153  }
3154  std::vector<std::shared_ptr<TargetEntry>>& get_targetlist_nonconst() {
3155  return targetlist;
3156  }
3157  const std::vector<std::vector<std::shared_ptr<TargetEntry>>>& get_values_lists() const {
3158  return values_lists;
3159  }
3160  std::vector<std::vector<std::shared_ptr<TargetEntry>>>& get_values_lists() {
3161  return values_lists;
3162  }
3163  const std::vector<RangeTableEntry*>& get_rangetable() const { return rangetable; }
3164  const Expr* get_where_predicate() const { return where_predicate.get(); }
3165  const std::list<std::shared_ptr<Analyzer::Expr>>& get_group_by() const {
3166  return group_by;
3167  };
3168  const Expr* get_having_predicate() const { return having_predicate.get(); }
3169  const std::list<OrderEntry>* get_order_by() const { return order_by; }
3170  const Query* get_next_query() const { return next_query; }
3172  bool get_is_unionall() const { return is_unionall; }
3173  int get_result_table_id() const { return result_table_id; }
3174  const std::list<int>& get_result_col_list() const { return result_col_list; }
3175  void set_result_col_list(const std::list<int>& col_list) { result_col_list = col_list; }
3176  void set_result_table_id(int id) { result_table_id = id; }
3177  void set_is_distinct(bool d) { is_distinct = d; }
3178  void set_where_predicate(std::shared_ptr<Analyzer::Expr> p) { where_predicate = p; }
3179  void set_group_by(std::list<std::shared_ptr<Analyzer::Expr>>& g) { group_by = g; }
3180  void set_having_predicate(std::shared_ptr<Analyzer::Expr> p) { having_predicate = p; }
3181  void set_order_by(std::list<OrderEntry>* o) { order_by = o; }
3182  void set_next_query(Query* q) { next_query = q; }
3183  void set_is_unionall(bool u) { is_unionall = u; }
3185  void set_num_aggs(int a) { num_aggs = a; }
3186  int get_rte_idx(const std::string& range_var_name) const;
3187  RangeTableEntry* get_rte(int rte_idx) const { return rangetable[rte_idx]; }
3188  void add_rte(RangeTableEntry* rte);
3189  void add_tle(std::shared_ptr<TargetEntry> tle) { targetlist.push_back(tle); }
3190  int64_t get_limit() const { return limit; }
3191  void set_limit(int64_t l) { limit = l; }
3192  int64_t get_offset() const { return offset; }
3193  void set_offset(int64_t o) { offset = o; }
3194 
3195  private:
3196  bool is_distinct; // true only if SELECT DISTINCT
3197  std::vector<std::shared_ptr<TargetEntry>> targetlist; // represents the SELECT clause
3198  std::vector<RangeTableEntry*> rangetable; // represents the FROM clause for SELECT. For
3199  // INSERT, DELETE, UPDATE the result table is
3200  // always the first entry in rangetable.
3201  std::shared_ptr<Analyzer::Expr> where_predicate; // represents the WHERE clause
3202  std::list<std::shared_ptr<Analyzer::Expr>> group_by; // represents the GROUP BY clause
3203  std::shared_ptr<Analyzer::Expr> having_predicate; // represents the HAVING clause
3204  std::list<OrderEntry>* order_by; // represents the ORDER BY clause
3205  Query* next_query; // the next query to UNION
3206  bool is_unionall; // true only if it is UNION ALL
3208  int num_aggs; // number of aggregate functions in query
3209  int result_table_id; // for INSERT statements only
3210  std::list<int> result_col_list; // for INSERT statement only
3211  std::vector<std::vector<std::shared_ptr<TargetEntry>>> values_lists; // for INSERT only
3212  int64_t limit; // row count for LIMIT clause. 0 means ALL
3213  int64_t offset; // offset in OFFSET clause. 0 means no offset.
3214 };
3215 
3216 class GeoExpr : public Expr {
3217  public:
3218  GeoExpr(const SQLTypeInfo& ti) : Expr(ti) {}
3219 
3220  // geo expressions might hide child expressions (e.g. constructors). Centralize logic
3221  // for pulling out child expressions for simplicity in visitors.
3222  virtual std::vector<Analyzer::Expr*> getChildExprs() const { return {}; }
3223 };
3224 
3230 class GeoColumnVar : public ColumnVar {
3231  public:
3233  const shared::ColumnKey& column_key,
3234  const int32_t range_table_index,
3235  const bool with_bounds)
3236  : ColumnVar(ti, column_key, range_table_index), with_bounds_(with_bounds) {}
3237 
3238  GeoColumnVar(const Analyzer::ColumnVar* column_var, const bool with_bounds)
3239  : ColumnVar(column_var->get_type_info(),
3240  column_var->getColumnKey(),
3241  column_var->get_rte_idx())
3242  , with_bounds_(with_bounds) {}
3243 
3244  protected:
3246 };
3247 
3248 class GeoConstant : public GeoExpr {
3249  public:
3250  GeoConstant(std::unique_ptr<Geospatial::GeoBase>&& geo, const SQLTypeInfo& ti);
3251 
3252  std::shared_ptr<Analyzer::Expr> deep_copy() const final;
3253 
3254  std::string toString() const final;
3255 
3256  bool operator==(const Expr&) const final;
3257 
3258  size_t physicalCols() const;
3259 
3260  std::shared_ptr<Analyzer::Constant> makePhysicalConstant(const size_t index) const;
3261 
3262  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) final;
3263 
3264  std::string getWKTString() const;
3265 
3266  private:
3267  std::unique_ptr<Geospatial::GeoBase> geo_;
3268 };
3269 
3274 class GeoOperator : public GeoExpr {
3275  public:
3276  GeoOperator(const SQLTypeInfo& ti,
3277  const std::string& name,
3278  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
3279  const std::optional<int>& output_srid_override = std::nullopt);
3280 
3281  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
3282 
3283  void collect_rte_idx(std::set<int>& rte_idx_set) const final;
3284 
3285  void collect_column_var(
3286  std::set<const ColumnVar*, bool (*)(const ColumnVar*, const ColumnVar*)>&
3287  colvar_set,
3288  bool include_agg) const final;
3289 
3290  std::string toString() const override;
3291 
3292  bool operator==(const Expr&) const override;
3293 
3294  size_t size() const;
3295 
3296  Analyzer::Expr* getOperand(const size_t index) const;
3297 
3298  const std::string& getName() const { return name_; }
3299 
3300  std::vector<std::shared_ptr<Analyzer::Expr>> getArgs() const { return args_; }
3301 
3302  std::vector<Analyzer::Expr*> getChildExprs() const override {
3303  std::vector<Analyzer::Expr*> ret;
3304  ret.reserve(args_.size());
3305  for (const auto& arg : args_) {
3306  ret.push_back(arg.get());
3307  }
3308  return ret;
3309  }
3310 
3311  std::shared_ptr<Analyzer::Expr> add_cast(const SQLTypeInfo& new_type_info) final;
3312 
3314 
3315  protected:
3316  const std::string name_;
3317  const std::vector<std::shared_ptr<Analyzer::Expr>> args_;
3318 
3319  // for legacy geo code, allow passing in a srid to force a transform in the function
3320  std::optional<int> output_srid_override_;
3321 };
3322 
3324  public:
3326  const std::string& name,
3327  const std::vector<std::shared_ptr<Analyzer::Expr>>& args,
3328  const int32_t input_srid,
3329  const int32_t output_srid)
3330  : GeoOperator(ti, name, args), input_srid_(input_srid), output_srid_(output_srid) {}
3331 
3332  std::shared_ptr<Analyzer::Expr> deep_copy() const override;
3333 
3334  std::string toString() const override;
3335 
3336  bool operator==(const Expr&) const override;
3337 
3338  int32_t getInputSRID() const { return input_srid_; }
3339 
3340  int32_t getOutputSRID() const { return output_srid_; }
3341 
3342  private:
3343  const int32_t input_srid_;
3344  const int32_t output_srid_;
3345 };
3346 } // namespace Analyzer
3347 
3348 inline std::shared_ptr<Analyzer::Var> var_ref(const Analyzer::Expr* expr,
3349  const Analyzer::Var::WhichRow which_row,
3350  const int varno) {
3351  const auto col_expr = dynamic_cast<const Analyzer::ColumnVar*>(expr);
3352  const shared::ColumnKey& column_key =
3353  col_expr ? col_expr->getColumnKey() : shared::ColumnKey{0, 0, 0};
3354  const int rte_idx = col_expr ? col_expr->get_rte_idx() : -1;
3355  return makeExpr<Analyzer::Var>(
3356  expr->get_type_info(), column_key, rte_idx, which_row, varno);
3357 }
3358 
3359 // Returns true iff the two expression lists are equal (same size and each element are
3360 // equal).
3361 bool expr_list_match(const std::vector<std::shared_ptr<Analyzer::Expr>>& lhs,
3362  const std::vector<std::shared_ptr<Analyzer::Expr>>& rhs);
3363 
3364 // Remove a cast operator if present.
3365 std::shared_ptr<Analyzer::Expr> remove_cast(const std::shared_ptr<Analyzer::Expr>& expr);
3366 const Analyzer::Expr* remove_cast(const Analyzer::Expr* expr);
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1302
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3904
std::list< ExpressionPtr > ExpressionPtrList
Definition: Analyzer.h:185
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:3077
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1174
Query * next_query
Definition: Analyzer.h:3205
bool hasRangeModeFraming() const
Definition: Analyzer.h:2959
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:1376
InIntegerSet(const std::shared_ptr< const Analyzer::Expr > a, const std::vector< int64_t > &values, const bool not_null)
Definition: Analyzer.cpp:1706
TryStringCastOper(const SQLTypeInfo &ti, const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:2554
SqlWindowFrameBoundType
Definition: sqldefs.h:202
virtual void get_domain(DomainSet &domain_set) const
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2085
bool operator==(const Expr &rhs) const override
Definition: Analyzer.h:621
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:656
WindowFrame(SqlWindowFrameBoundType bound_type, const std::shared_ptr< Analyzer::Expr > bound_expr)
Definition: Analyzer.h:2822
TargetEntry(const std::string &n, std::shared_ptr< Analyzer::Expr > e, bool u)
Definition: Analyzer.h:3110
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2040
std::string toString() const override
Definition: Analyzer.cpp:3000
Query * parsetree
Definition: Analyzer.h:632
bool isCurrentRowBound() const
Definition: Analyzer.h:2841
UrlDecodeStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2538
const std::list< std::shared_ptr< Analyzer::Expr > > & get_value_list() const
Definition: Analyzer.h:350
TrimStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2072
SQLAgg
Definition: sqldefs.h:76
float get_likelihood() const
Definition: Analyzer.h:1269
size_t getMinArgs() const override
Definition: Analyzer.h:1963
std::vector< Analyzer::Expr * > getChildExprs() const override
Definition: Analyzer.h:3302
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2234
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:297
std::shared_ptr< Analyzer::Expr > expr
Definition: Analyzer.h:3124
virtual bool operator==(const Expr &rhs) const =0
std::string toString() const override
Definition: Analyzer.cpp:2922
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:564
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2255
SqlWindowFunctionKind getKind() const
Definition: Analyzer.h:2925
LowerStringOper(const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:1826
std::vector< std::vector< std::shared_ptr< TargetEntry > > > & get_values_lists()
Definition: Analyzer.h:3160
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3300
virtual ~Expr()
Definition: Analyzer.h:77
Expr(SQLTypes t, int d, int s, bool notnull)
Definition: Analyzer.h:73
bool unnest
Definition: Analyzer.h:3125
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:1692
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2697
ConcatStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1991
InValues(std::shared_ptr< Analyzer::Expr > a, const std::list< std::shared_ptr< Analyzer::Expr >> &l)
Definition: Analyzer.cpp:1688
PositionStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2604
const Expr * get_from_expr() const
Definition: Analyzer.h:1432
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:1553
const Expr * get_partition_count() const
Definition: Analyzer.h:1201
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3769
InitCapStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1892
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:814
bool hasNoneEncodedTextArg() const
Definition: Analyzer.h:1743
Constant(const SQLTypeInfo &ti, bool n, Datum v)
Definition: Analyzer.h:335
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1134
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2617
std::string toString() const override
Definition: Analyzer.cpp:2724
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3819
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3799
GeoConstant(std::unique_ptr< Geospatial::GeoBase > &&geo, const SQLTypeInfo &ti)
Definition: Analyzer.cpp:4037
void get_domain(DomainSet &domain_set) const override
Definition: Analyzer.cpp:3625
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2256
std::string toString() const final
Definition: Analyzer.cpp:4052
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2359
bool is_constant_expr() const
Definition: Analyzer.h:1246
const Expr * get_else_expr() const
Definition: Analyzer.h:1387
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:3091
JarowinklerSimilarityStringOper(const std::shared_ptr< Analyzer::Expr > &left_operand, const std::shared_ptr< Analyzer::Expr > &right_operand)
Definition: Analyzer.h:2627
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3699
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2505
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3794
bool hasTimestampTypeFrameBound() const
Definition: Analyzer.h:2833
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.cpp:4545
void set_contains_agg(bool a)
Definition: Analyzer.h:82
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1935
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:256
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs0() const
Definition: Analyzer.h:3093
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3864
const std::vector< int64_t > & get_value_list() const
Definition: Analyzer.h:695
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2486
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2351
HashStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2724
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=false, const bool cols_first_arg_only=true) const
Definition: Analyzer.cpp:4361
bool isFrameNavigateWindowFunction() const
Definition: Analyzer.h:2979
OrderEntry(int t, bool d, bool nf)
Definition: Analyzer.h:2807
const Expr * get_escape_expr() const
Definition: Analyzer.h:1064
virtual std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const
Definition: Analyzer.h:129
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2426
size_t getMinArgs() const override
Definition: Analyzer.h:2077
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:950
std::vector< std::vector< std::shared_ptr< TargetEntry > > > values_lists
Definition: Analyzer.h:3211
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1016
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3311
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2163
std::shared_ptr< Analyzer::Expr > decompress()
Definition: Analyzer.cpp:749
size_t getArity() const
Definition: Analyzer.h:2746
std::optional< int > output_srid_override_
Definition: Analyzer.h:3320
Definition: Analyzer.h:3108
DatediffExpr(const SQLTypeInfo &ti, const DatetruncField f, const std::shared_ptr< Analyzer::Expr > start, const std::shared_ptr< Analyzer::Expr > end)
Definition: Analyzer.h:1519
int32_t getInputSRID() const
Definition: Analyzer.h:3338
std::shared_ptr< Analyzer::Expr > remove_cast(const std::shared_ptr< Analyzer::Expr > &expr)
Definition: Analyzer.cpp:4611
RangeOper(const bool l_inclusive, const bool r_inclusive, std::shared_ptr< Analyzer::Expr > l, std::shared_ptr< Analyzer::Expr > r)
Definition: Analyzer.h:539
size_t getMinArgs() const override
Definition: Analyzer.h:2218
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:2197
static bool colvar_comp(const ColumnVar *l, const ColumnVar *r)
Definition: Analyzer.h:215
bool isMissingValueFillingFunction() const
Definition: Analyzer.h:2986
SQLTypes
Definition: sqltypes.h:65
const std::shared_ptr< Analyzer::Expr > frame_end_bound_
Definition: Analyzer.h:3000
const std::vector< std::vector< std::shared_ptr< TargetEntry > > > & get_values_lists() const
Definition: Analyzer.h:3157
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3784
void add_rte(RangeTableEntry *rte)
Definition: Analyzer.cpp:1506
const SQLTypeInfo getTypeInfo0() const
Definition: Analyzer.h:3062
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2353
std::shared_ptr< Analyzer::Expr > operand
Definition: Analyzer.h:424
virtual void print() const
Definition: Analyzer.h:154
std::list< int > result_col_list
Definition: Analyzer.h:3210
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3734
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2413
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:904
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3809
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:963
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:222
GeoUOper(const Geospatial::GeoBase::GeoOp op, const SQLTypeInfo &ti, const SQLTypeInfo &ti0, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:3050
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:1905
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2220
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:406
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:2314
bool hasAggregateTreeRequiredWindowFunc() const
Definition: Analyzer.h:2973
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2634
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:508
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3684
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3320
const std::shared_ptr< Analyzer::Expr > get_own_arg() const
Definition: Analyzer.h:1268
StringOper(const StringOper &other_string_oper)
Definition: Analyzer.h:1658
void collect_rte_idx(std::set< int > &rte_idx_set) const final
Definition: Analyzer.cpp:4167
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2206
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2457
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:1628
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1144
SQLQualifier
Definition: sqldefs.h:74
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3248
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:968
std::shared_ptr< Analyzer::Expr > right_operand
Definition: Analyzer.h:530
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2079
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3349
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1338
SQLStmtType stmt_type
Definition: Analyzer.h:3207
std::shared_ptr< Analyzer::Expr > escape_expr
Definition: Analyzer.h:1178
const Query * get_parsetree() const
Definition: Analyzer.h:592
bool operator==(Expr const &rhs) const override
Definition: Analyzer.cpp:2669
ExtractField get_field() const
Definition: Analyzer.h:1431
TryStringCastOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2571
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2045
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2026
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:1725
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3515
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:157
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2184
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:301
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:3583
const Expr * get_escape_expr() const
Definition: Analyzer.h:1136
const Expr * get_right_operand() const
Definition: Analyzer.h:456
SQLOps
Definition: sqldefs.h:31
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:1871
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3494
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:3325
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1229
std::string toString() const override
Definition: Analyzer.cpp:3196
std::shared_ptr< Analyzer::Expr > get_shared_ptr()
Definition: Analyzer.h:78
virtual void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
Definition: Analyzer.h:84
shared::ColumnKey column_key_
Definition: Analyzer.h:239
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1074
RepeatStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1951
auto getOutputSridOverride() const
Definition: Analyzer.h:3313
Var(const SQLTypeInfo &ti, WhichRow o, int32_t v)
Definition: Analyzer.h:284
std::map< size_t, std::pair< SQLTypes, Datum >> LiteralArgMap
Definition: Analyzer.h:1769
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3749
SqlWindowFrameBoundType bound_type_
Definition: Analyzer.h:2852
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3450
std::list< std::shared_ptr< Analyzer::Expr > > group_by
Definition: Analyzer.h:3202
MLPredictExpr(const std::shared_ptr< Analyzer::Expr > &model, const std::vector< std::shared_ptr< Analyzer::Expr >> &regressors)
Definition: Analyzer.h:709
static bool isFramingAvailableWindowFunc(SqlWindowFunctionKind kind)
Definition: Analyzer.h:2966
GeoColumnVar(const SQLTypeInfo &ti, const shared::ColumnKey &column_key, const int32_t range_table_index, const bool with_bounds)
Definition: Analyzer.h:3232
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:674
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:87
void print() const
Definition: Analyzer.h:3120
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:3068
SQLTypeInfo ti0_
Definition: Analyzer.h:3098
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:617
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2734
std::shared_ptr< Analyzer::Expr > like_expr
Definition: Analyzer.h:1111
bool get_is_null() const
Definition: Analyzer.h:347
void set_varno(int32_t n)
Definition: Analyzer.h:289
const std::vector< std::shared_ptr< Analyzer::Expr > > args0_
Definition: Analyzer.h:3100
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:1274
std::string toString() const override
Definition: Analyzer.cpp:3895
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1026
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.cpp:3553
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3268
int tle_no
Definition: Analyzer.h:2811
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3277
~OrderEntry()
Definition: Analyzer.h:2808
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:165
std::shared_ptr< Analyzer::Var > var_ref(const Analyzer::Expr *expr, const Analyzer::Var::WhichRow which_row, const int varno)
Definition: Analyzer.h:3348
HashStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2716
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2429
const std::shared_ptr< const Analyzer::Expr > arg
Definition: Analyzer.h:703
const std::shared_ptr< Analyzer::Expr > get_own_operand() const
Definition: Analyzer.h:385
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:230
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:239
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1222
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:499
void cast_from_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1208
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3704
bool get_contains_agg() const
Definition: Analyzer.h:81
SqlStringOpKind
Definition: sqldefs.h:92
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:3620
std::string toString() const override
Definition: Analyzer.cpp:2964
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1460
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3774
size_t getMinArgs() const override
Definition: Analyzer.h:2729
const SQLTypeInfo getTypeInfo1() const
Definition: Analyzer.h:3092
std::shared_ptr< Analyzer::Expr > ExpressionPtr
Definition: Analyzer.h:184
const Geospatial::GeoBase::GeoOp op_
Definition: Analyzer.h:3097
const Expr * get_arg() const
Definition: Analyzer.h:1133
size_t getArity() const
Definition: Analyzer.h:1674
const std::vector< std::shared_ptr< Analyzer::Expr > > order_keys_
Definition: Analyzer.h:2997
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2198
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3832
void set_order_by(std::list< OrderEntry > *o)
Definition: Analyzer.h:3181
Expr * get_arg() const
Definition: Analyzer.h:1330
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2560
DatetruncField get_field() const
Definition: Analyzer.h:1566
std::shared_ptr< Analyzer::Expr > model_value_
Definition: Analyzer.h:774
const std::list< OrderEntry > * get_order_by() const
Definition: Analyzer.h:3169
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:4488
bool requiresPerRowTranslation() const
Definition: Analyzer.h:1704
void set_result_col_list(const std::list< int > &col_list)
Definition: Analyzer.h:3175
const Expr * get_arg() const
Definition: Analyzer.h:1267
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1251
Constants for Builtin SQL Types supported by HEAVY.AI.
void set_which_row(WhichRow r)
Definition: Analyzer.h:287
size_t getMinArgs() const override
Definition: Analyzer.h:2609
size_t getMinArgs() const override
Definition: Analyzer.h:2343
std::shared_ptr< Analyzer::Expr > add_cast(const SQLTypeInfo &new_type_info) override
Definition: Analyzer.cpp:1442
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
const Expr * get_where_predicate() const
Definition: Analyzer.h:3164
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3371
int get_num_aggs() const
Definition: Analyzer.h:3150
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:2267
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:3913
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:4159
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1080
virtual std::vector< OperandTypeFamily > getExpectedTypeFamilies() const
Definition: Analyzer.h:1799
Definition: sqltypes.h:92
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:66
const Analyzer::WindowFrame * getFrameStartBound() const
Definition: Analyzer.h:2937
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2772
const std::vector< std::shared_ptr< Analyzer::Expr > > partition_keys_
Definition: Analyzer.h:2996
static std::vector< std::shared_ptr< Analyzer::Expr > > normalize_operands(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.cpp:4470
void set_constant_expr() const
Definition: Analyzer.h:1245
RegexpCountStringOper(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 > &regex_params)
Definition: Analyzer.h:2365
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2220
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3744
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3508
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2539
void set_offset(int64_t o)
Definition: Analyzer.h:3193
ReplaceStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2206
StringOper(const SqlStringOpKind kind, const SQLTypeInfo &return_ti, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1611
UOper(SQLTypes t, SQLOps o, std::shared_ptr< Analyzer::Expr > p)
Definition: Analyzer.h:379
~Constant() override
Definition: Analyzer.cpp:40
std::shared_ptr< Analyzer::Expr > getOwnArg(const size_t i) const
Definition: Analyzer.h:1693
std::unique_ptr< Geospatial::GeoBase > geo_
Definition: Analyzer.h:3267
size_t getLiteralsArity() const
Definition: Analyzer.h:1676
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3431
SQLQualifier qualifier
Definition: Analyzer.h:527
bool isNull() const
Definition: Analyzer.h:3025
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1252
virtual std::vector< Analyzer::Expr * > getChildExprs() const
Definition: Analyzer.h:3222
const Analyzer::WindowFrame * getFrameEndBound() const
Definition: Analyzer.h:2944
std::string toString() const override
Definition: Analyzer.cpp:3091
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:1906
const std::vector< std::shared_ptr< Analyzer::Expr > > & getOrderKeys() const
Definition: Analyzer.h:2933
std::string toString() const override
Definition: Analyzer.cpp:2786
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:490
SQLTypeInfo type_info
Definition: Analyzer.h:180
const std::vector< OrderEntry > & getCollation() const
Definition: Analyzer.h:2951
const Expr * get_left_operand() const
Definition: Analyzer.h:552
EncodingType get_compression() const
Definition: Analyzer.h:204
std::list< const Expr * > DomainSet
Definition: Analyzer.h:62
virtual void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const
Definition: Analyzer.h:117
void set_constval(Datum d)
Definition: Analyzer.h:349
const Expr * get_arg() const
Definition: Analyzer.h:1061
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:936
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2190
size_t getMinArgs() const override
Definition: Analyzer.h:2513
std::enable_if< std::is_base_of< Analyzer::Expr, Tp >::value, std::shared_ptr< Tp > >::type makeExpr(Args &&...args)
Definition: Analyzer.h:53
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:597
std::string toString() const override
Definition: Analyzer.cpp:2733
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:1538
const std::string & get_resname() const
Definition: Analyzer.h:3113
double get_bound_val(const Analyzer::Expr *bound_expr) const
Definition: Analyzer.cpp:3936
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2192
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1162
RepeatStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:1958
~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:613
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2577
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:889
TrimStringOper(const SqlStringOpKind trim_op_kind, const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &trim_chars)
Definition: Analyzer.h:2055
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1156
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:603
bool operator==(const Expr &) const override
Definition: Analyzer.cpp:4258
int get_rte_idx(const std::string &range_var_name) const
Definition: Analyzer.cpp:1495
void cast_string(const SQLTypeInfo &new_type_info)
Definition: Analyzer.cpp:1197
void set_type_info(const SQLTypeInfo &ti)
Definition: Analyzer.h:80
const std::vector< std::shared_ptr< Analyzer::Expr > > args_
Definition: Analyzer.h:2995
void check_group_by(const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const override
Definition: Analyzer.cpp:3603
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:738
std::string toString() const override
Definition: Analyzer.cpp:2755
JsonValueStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2412
const std::shared_ptr< Analyzer::Expr > get_own_from_expr() const
Definition: Analyzer.h:1568
std::vector< std::shared_ptr< Analyzer::Expr > > chained_string_op_exprs_
Definition: Analyzer.h:1821
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:76
std::string toString() const override
Definition: Analyzer.cpp:2887
size_t getMinArgs() const override
Definition: Analyzer.h:2692
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3754
LikelihoodExpr(std::shared_ptr< Analyzer::Expr > a, float l=0.5)
Definition: Analyzer.h:1265
constexpr double a
Definition: Utm.h:32
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2391
StringOper(const SqlStringOpKind kind, const std::vector< std::shared_ptr< Analyzer::Expr >> &args)
Definition: Analyzer.h:1607
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:435
bool g_enable_string_functions
std::string toString() const override
Definition: Analyzer.cpp:2978
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2302
std::vector< size_t > getLiteralArgIndexes() const
Definition: Analyzer.cpp:4297
std::string toString() const override
Definition: Analyzer.cpp:3009
LevenshteinDistanceStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2687
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:1030
std::string toString() const override
Definition: Analyzer.cpp:2945
bool get_calc_encoded_length() const
Definition: Analyzer.h:870
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2368
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2076
std::string toString() const override
Definition: Analyzer.cpp:3167
DatetruncField field_
Definition: Analyzer.h:1592
std::shared_ptr< Analyzer::Expr > rewrite_with_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2040
std::vector< OperandTypeFamily > getExpectedTypeFamilies() const override
Definition: Analyzer.h:2515
const FrameBoundType frame_bound_type_
Definition: Analyzer.h:2998
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3804
const Geospatial::GeoBase::GeoOp op_
Definition: Analyzer.h:3066
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:1209
std::string toString() const override
Definition: Analyzer.cpp:3116
std::shared_ptr< Analyzer::Expr > rewrite_with_child_targetlist(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.h:825
SQLOps get_optype() const
Definition: Analyzer.h:452
std::shared_ptr< Analyzer::Expr > left_operand
Definition: Analyzer.h:529
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2651
const std::vector< std::shared_ptr< Analyzer::Expr > > args1_
Definition: Analyzer.h:3101
RepeatStringOper(const std::shared_ptr< Analyzer::Expr > &operand, const std::shared_ptr< Analyzer::Expr > &num_repeats)
Definition: Analyzer.h:1943
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3440
std::string toString() const override
Definition: Analyzer.cpp:2869
std::string toString() const
Definition: Analyzer.cpp:3226
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3814
SqlWindowFrameBoundType getBoundType() const
Definition: Analyzer.h:2826
const Query * get_next_query() const
Definition: Analyzer.h:3170
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:2116
const std::shared_ptr< Analyzer::Expr > frame_start_bound_
Definition: Analyzer.h:2999
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:1577
const std::list< std::shared_ptr< Analyzer::Expr > > value_list
Definition: Analyzer.h:676
Base64EncodeStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:2443
EncodingType
Definition: sqltypes.h:240
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:2232
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:190
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:183
static SQLTypeInfo common_string_type(const SQLTypeInfo &type1, const SQLTypeInfo &type2)
Definition: Analyzer.cpp:452
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:234
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.h:479
UpperStringOper(const std::vector< std::shared_ptr< Analyzer::Expr >> &operands)
Definition: Analyzer.h:1862
DatetruncExpr(const SQLTypeInfo &ti, bool has_agg, DatetruncField f, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1561
std::shared_ptr< Analyzer::Expr > right_operand_
Definition: Analyzer.h:577
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:1620
void collect_column_var(std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
Definition: Analyzer.h:483
void set_fixed_encoding_null_val() const
Definition: Analyzer.h:1479
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:199
static SqlStringOpKind validate_trim_op_kind(const SqlStringOpKind trim_op_kind)
Definition: Analyzer.h:2087
bool hasSingleDictEncodedColInput() const
returns whether we have one and only one column involved in this StringOper and all its descendents...
Definition: Analyzer.cpp:4283
std::shared_ptr< Analyzer::Expr > deep_copy() const override
Definition: Analyzer.cpp:3789
RegexpReplaceStringOper(const std::shared_ptr< Analyzer::StringOper > &string_oper)
Definition: Analyzer.h:2287
Expr(const SQLTypeInfo &ti, bool has_agg=false)
Definition: Analyzer.h:75
void find_expr(std::function< bool(const Expr *)> f, std::list< const Expr * > &expr_list) const override
Definition: Analyzer.cpp:3338
std::shared_ptr< Analyzer::Expr > deep_copy() const final
Definition: Analyzer.cpp:4047
LiteralArgMap getLiteralArgs() const
Definition: Analyzer.cpp:4310
std::string toString() const override
Definition: Analyzer.cpp:2850
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2117
std::vector< std::string > getArgNames() const override
Definition: Analyzer.h:2397
UrlDecodeStringOper(const std::shared_ptr< Analyzer::Expr > &operand)
Definition: Analyzer.h:2524
const DatetruncField field_
Definition: Analyzer.h:1550
bool operator==(const Expr &rhs) const override
Definition: Analyzer.cpp:2638
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:1801
const std::vector< std::shared_ptr< Analyzer::Expr > > & getTuple() const
Definition: Analyzer.h:253
CONSTEXPR DEVICE bool is_null(const T &value)
const Expr * get_pc_dimension_value() const
Definition: Analyzer.h:792
void collect_rte_idx(std::set< int > &rte_idx_set) const override
Definition: Analyzer.cpp:3499
std::shared_ptr< Analyzer::Expr > rewrite_agg_to_var(const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
Definition: Analyzer.cpp:2240
const std::vector< std::shared_ptr< Analyzer::Expr > > & getArgs() const
Definition: Analyzer.h:2927