OmniSciDB  5ade3759e0
Analyzer::AggExpr Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::AggExpr:
+ Collaboration diagram for Analyzer::AggExpr:

Public Member Functions

 AggExpr (const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
 
 AggExpr (SQLTypes t, SQLAgg a, Expr *g, bool d, std::shared_ptr< Analyzer::Constant > e, int idx)
 
SQLAgg get_aggtype () const
 
Exprget_arg () const
 
std::shared_ptr< Analyzer::Exprget_own_arg () const
 
bool get_is_distinct () const
 
std::shared_ptr< Analyzer::Constantget_error_rate () const
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
void group_predicates (std::list< const Expr *> &scan_predicates, std::list< const Expr *> &join_predicates, std::list< const Expr *> &const_predicates) const override
 
void collect_rte_idx (std::set< int > &rte_idx_set) const override
 
void collect_column_var (std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &colvar_set, bool include_agg) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_with_child_targetlist (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
std::shared_ptr< Analyzer::Exprrewrite_agg_to_var (const std::vector< std::shared_ptr< TargetEntry >> &tlist) const override
 
bool operator== (const Expr &rhs) const override
 
std::string toString () const override
 
void find_expr (bool(*f)(const Expr *), std::list< const Expr *> &expr_list) const override
 
- Public Member Functions inherited from Analyzer::Expr
 Expr (SQLTypes t, bool notnull)
 
 Expr (SQLTypes t, int d, bool notnull)
 
 Expr (SQLTypes t, int d, int s, bool notnull)
 
 Expr (const SQLTypeInfo &ti, bool has_agg=false)
 
virtual ~Expr ()
 
const SQLTypeInfoget_type_info () const
 
void set_type_info (const SQLTypeInfo &ti)
 
bool get_contains_agg () const
 
void set_contains_agg (bool a)
 
virtual std::shared_ptr< Analyzer::Expradd_cast (const SQLTypeInfo &new_type_info)
 
virtual void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
 
virtual std::shared_ptr< Analyzer::Exprnormalize_simple_predicate (int &rte_idx) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr *> &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Private Attributes

SQLAgg aggtype
 
std::shared_ptr< Analyzer::Exprarg
 
bool is_distinct
 
std::shared_ptr< Analyzer::Constanterror_rate
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 968 of file Analyzer.h.

Constructor & Destructor Documentation

◆ AggExpr() [1/2]

Analyzer::AggExpr::AggExpr ( const SQLTypeInfo ti,
SQLAgg  a,
std::shared_ptr< Analyzer::Expr g,
bool  d,
std::shared_ptr< Analyzer::Constant e 
)
inline

Definition at line 970 of file Analyzer.h.

975  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), error_rate(e) {}
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
T g(const TargetValue &r)
Definition: TestHelpers.h:118
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1024
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022

◆ AggExpr() [2/2]

Analyzer::AggExpr::AggExpr ( SQLTypes  t,
SQLAgg  a,
Expr g,
bool  d,
std::shared_ptr< Analyzer::Constant e,
int  idx 
)
inline

Definition at line 976 of file Analyzer.h.

982  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
983  , aggtype(a)
984  , arg(g)
985  , is_distinct(d)
986  , error_rate(e) {}
void d(const SQLTypes expected_type, const std::string &str)
Definition: ImportTest.cpp:268
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
T g(const TargetValue &r)
Definition: TestHelpers.h:118
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1024
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:823

Member Function Documentation

◆ collect_column_var()

void Analyzer::AggExpr::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1001 of file Analyzer.h.

References operator==().

1004  {
1005  if (include_agg && arg != nullptr) {
1006  arg->collect_column_var(colvar_set, include_agg);
1007  }
1008  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
+ Here is the call graph for this function:

◆ collect_rte_idx()

void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 996 of file Analyzer.h.

996  {
997  if (arg) {
998  arg->collect_rte_idx(rte_idx_set);
999  }
1000  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022

◆ deep_copy()

std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 151 of file Analyzer.cpp.

References anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), and Analyzer::Expr::type_info.

Referenced by rewrite_with_targetlist().

151  {
152  return makeExpr<AggExpr>(type_info,
153  aggtype,
154  arg == nullptr ? nullptr : arg->deep_copy(),
155  is_distinct,
156  error_rate);
157 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1024
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
SQLTypeInfo type_info
Definition: Analyzer.h:175
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_expr()

void Analyzer::AggExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr *> &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2686 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), and Analyzer::InIntegerSet::arg.

2686  {
2687  if (f(this)) {
2688  add_unique(expr_list);
2689  return;
2690  }
2691  if (arg != nullptr) {
2692  arg->find_expr(f, expr_list);
2693  }
2694 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
virtual void add_unique(std::list< const Expr *> &expr_list) const
Definition: Analyzer.cpp:2585
+ Here is the call graph for this function:

◆ get_aggtype()

SQLAgg Analyzer::AggExpr::get_aggtype ( ) const
inline

Definition at line 987 of file Analyzer.h.

Referenced by anonymous_namespace{NativeCodegen.cpp}::get_agg_fnames(), operator==(), and DeepCopyVisitor::visitAggExpr().

987 { return aggtype; }
+ Here is the caller graph for this function:

◆ get_arg()

Expr* Analyzer::AggExpr::get_arg ( ) const
inline

Definition at line 988 of file Analyzer.h.

Referenced by agg_arg(), GroupByAndAggregate::gpuCanHandleOrderEntries(), GroupByAndAggregate::initCountDistinctDescriptors(), operator==(), DeepCopyVisitor::visitAggExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitAggExpr().

988 { return arg.get(); }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
+ Here is the caller graph for this function:

◆ get_error_rate()

std::shared_ptr<Analyzer::Constant> Analyzer::AggExpr::get_error_rate ( ) const
inline

Definition at line 991 of file Analyzer.h.

Referenced by DeepCopyVisitor::visitAggExpr().

991 { return error_rate; }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1024
+ Here is the caller graph for this function:

◆ get_is_distinct()

bool Analyzer::AggExpr::get_is_distinct ( ) const
inline

Definition at line 990 of file Analyzer.h.

References anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct().

Referenced by anonymous_namespace{RelAlgExecutor.cpp}::is_count_distinct(), operator==(), and DeepCopyVisitor::visitAggExpr().

990 { return is_distinct; }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_own_arg()

std::shared_ptr<Analyzer::Expr> Analyzer::AggExpr::get_own_arg ( ) const
inline

Definition at line 989 of file Analyzer.h.

989 { return arg; }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022

◆ group_predicates()

void Analyzer::AggExpr::group_predicates ( std::list< const Expr *> &  scan_predicates,
std::list< const Expr *> &  join_predicates,
std::list< const Expr *> &  const_predicates 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1555 of file Analyzer.cpp.

References Analyzer::InIntegerSet::arg.

1557  {
1558  std::set<int> rte_idx_set;
1559  arg->collect_rte_idx(rte_idx_set);
1560  if (rte_idx_set.size() > 1) {
1561  join_predicates.push_back(this);
1562  } else if (rte_idx_set.size() == 1) {
1563  scan_predicates.push_back(this);
1564  } else {
1565  const_predicates.push_back(this);
1566  }
1567 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022

◆ operator==()

bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2132 of file Analyzer.cpp.

References Analyzer::InIntegerSet::arg, get_aggtype(), get_arg(), get_is_distinct(), and anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct().

2132  {
2133  if (typeid(rhs) != typeid(AggExpr)) {
2134  return false;
2135  }
2136  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2137  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2138  return false;
2139  }
2140  if (arg.get() == rhs_ae.get_arg()) {
2141  return true;
2142  }
2143  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2144  return false;
2145  }
2146  return *arg == *rhs_ae.get_arg();
2147 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:970
+ Here is the call graph for this function:

◆ rewrite_agg_to_var()

std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1776 of file Analyzer.cpp.

References Analyzer::Expr::get_type_info(), and Analyzer::Var::kINPUT_OUTER.

1777  {
1778  int varno = 1;
1779  for (auto tle : tlist) {
1780  const Expr* e = tle->get_expr();
1781  if (typeid(*e) == typeid(AggExpr)) {
1782  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1783  if (*this == *agg_expr) {
1784  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1785  }
1786  }
1787  varno++;
1788  }
1789  throw std::runtime_error(
1790  "Internal error: cannot find AggExpr from having clause in targetlist.");
1791 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:970
+ Here is the call graph for this function:

◆ rewrite_with_child_targetlist()

std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1767 of file Analyzer.cpp.

References Analyzer::InIntegerSet::arg, anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), and Analyzer::Expr::type_info.

1768  {
1769  return makeExpr<AggExpr>(type_info,
1770  aggtype,
1771  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1772  is_distinct,
1773  error_rate);
1774 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1024
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
SQLTypeInfo type_info
Definition: Analyzer.h:175
+ Here is the call graph for this function:

◆ rewrite_with_targetlist()

std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1753 of file Analyzer.cpp.

References deep_copy().

1754  {
1755  for (auto tle : tlist) {
1756  const Expr* e = tle->get_expr();
1757  if (typeid(*e) == typeid(AggExpr)) {
1758  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1759  if (*this == *agg) {
1760  return agg->deep_copy();
1761  }
1762  }
1763  }
1764  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1765 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:970
+ Here is the call graph for this function:

◆ toString()

std::string Analyzer::AggExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2464 of file Analyzer.cpp.

References Analyzer::InIntegerSet::arg, anonymous_namespace{RelAlgOptimizer.cpp}::is_distinct(), kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, and kSUM.

2464  {
2465  std::string agg;
2466  switch (aggtype) {
2467  case kAVG:
2468  agg = "AVG ";
2469  break;
2470  case kMIN:
2471  agg = "MIN ";
2472  break;
2473  case kMAX:
2474  agg = "MAX ";
2475  break;
2476  case kSUM:
2477  agg = "SUM ";
2478  break;
2479  case kCOUNT:
2480  agg = "COUNT ";
2481  break;
2483  agg = "APPROX_COUNT_DISTINCT";
2484  break;
2485  case kSAMPLE:
2486  agg = "SAMPLE";
2487  break;
2488  }
2489  std::string str{"(" + agg};
2490  if (is_distinct) {
2491  str += "DISTINCT ";
2492  }
2493  if (arg) {
2494  str += arg->toString();
2495  } else {
2496  str += "*";
2497  }
2498  return str + ") ";
2499 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1022
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
+ Here is the call graph for this function:

Member Data Documentation

◆ aggtype

SQLAgg Analyzer::AggExpr::aggtype
private

Definition at line 1021 of file Analyzer.h.

◆ arg

std::shared_ptr<Analyzer::Expr> Analyzer::AggExpr::arg
private

Definition at line 1022 of file Analyzer.h.

◆ error_rate

std::shared_ptr<Analyzer::Constant> Analyzer::AggExpr::error_rate
private

Definition at line 1024 of file Analyzer.h.

◆ is_distinct

bool Analyzer::AggExpr::is_distinct
private

Definition at line 1023 of file Analyzer.h.


The documentation for this class was generated from the following files: