OmniSciDB  8a228a1076
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 ()
 
std::shared_ptr< Analyzer::Exprget_shared_ptr ()
 
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 1077 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 1079 of file Analyzer.h.

1084  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), error_rate(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1133
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131

◆ 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 1085 of file Analyzer.h.

1091  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1092  , aggtype(a)
1093  , arg(g)
1094  , is_distinct(d)
1095  , error_rate(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1133
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131

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 1110 of file Analyzer.h.

References operator==().

1113  {
1114  if (include_agg && arg != nullptr) {
1115  arg->collect_column_var(colvar_set, include_agg);
1116  }
1117  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
+ 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 1105 of file Analyzer.h.

1105  {
1106  if (arg) {
1107  arg->collect_rte_idx(rte_idx_set);
1108  }
1109  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131

◆ deep_copy()

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

Implements Analyzer::Expr.

Definition at line 159 of file Analyzer.cpp.

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

Referenced by rewrite_with_targetlist().

159  {
160  return makeExpr<AggExpr>(type_info,
161  aggtype,
162  arg == nullptr ? nullptr : arg->deep_copy(),
163  is_distinct,
164  error_rate);
165 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1133
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
SQLTypeInfo type_info
Definition: Analyzer.h:177
+ 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 2934 of file Analyzer.cpp.

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

2934  {
2935  if (f(this)) {
2936  add_unique(expr_list);
2937  return;
2938  }
2939  if (arg != nullptr) {
2940  arg->find_expr(f, expr_list);
2941  }
2942 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
virtual void add_unique(std::list< const Expr *> &expr_list) const
Definition: Analyzer.cpp:2815
+ Here is the call graph for this function:

◆ get_aggtype()

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

Definition at line 1096 of file Analyzer.h.

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

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

◆ get_arg()

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

Definition at line 1097 of file Analyzer.h.

Referenced by agg_arg(), anonymous_namespace{SerializeToSql.cpp}::agg_to_string(), GroupByAndAggregate::gpuCanHandleOrderEntries(), GroupByAndAggregate::initCountDistinctDescriptors(), operator==(), DeepCopyVisitor::visitAggExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitAggExpr().

1097 { return arg.get(); }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
+ 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 1100 of file Analyzer.h.

Referenced by DeepCopyVisitor::visitAggExpr().

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

◆ get_is_distinct()

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

Definition at line 1099 of file Analyzer.h.

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

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

1099 { 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 1098 of file Analyzer.h.

1098 { return arg; }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131

◆ 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 1666 of file Analyzer.cpp.

References Analyzer::InIntegerSet::arg.

1668  {
1669  std::set<int> rte_idx_set;
1670  arg->collect_rte_idx(rte_idx_set);
1671  if (rte_idx_set.size() > 1) {
1672  join_predicates.push_back(this);
1673  } else if (rte_idx_set.size() == 1) {
1674  scan_predicates.push_back(this);
1675  } else {
1676  const_predicates.push_back(this);
1677  }
1678 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131

◆ operator==()

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

Implements Analyzer::Expr.

Definition at line 2262 of file Analyzer.cpp.

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

2262  {
2263  if (typeid(rhs) != typeid(AggExpr)) {
2264  return false;
2265  }
2266  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2267  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2268  return false;
2269  }
2270  if (arg.get() == rhs_ae.get_arg()) {
2271  return true;
2272  }
2273  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2274  return false;
2275  }
2276  return *arg == *rhs_ae.get_arg();
2277 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1079
+ 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 1887 of file Analyzer.cpp.

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

1888  {
1889  int varno = 1;
1890  for (auto tle : tlist) {
1891  const Expr* e = tle->get_expr();
1892  if (typeid(*e) == typeid(AggExpr)) {
1893  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1894  if (*this == *agg_expr) {
1895  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1896  }
1897  }
1898  varno++;
1899  }
1900  throw std::runtime_error(
1901  "Internal error: cannot find AggExpr from having clause in targetlist.");
1902 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1079
+ 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 1878 of file Analyzer.cpp.

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

1879  {
1880  return makeExpr<AggExpr>(type_info,
1881  aggtype,
1882  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1883  is_distinct,
1884  error_rate);
1885 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1133
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
SQLTypeInfo type_info
Definition: Analyzer.h:177
+ 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 1864 of file Analyzer.cpp.

References deep_copy().

1865  {
1866  for (auto tle : tlist) {
1867  const Expr* e = tle->get_expr();
1868  if (typeid(*e) == typeid(AggExpr)) {
1869  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1870  if (*this == *agg) {
1871  return agg->deep_copy();
1872  }
1873  }
1874  }
1875  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1876 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1079
+ Here is the call graph for this function:

◆ toString()

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

Implements Analyzer::Expr.

Definition at line 2638 of file Analyzer.cpp.

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

2638  {
2639  std::string agg;
2640  switch (aggtype) {
2641  case kAVG:
2642  agg = "AVG ";
2643  break;
2644  case kMIN:
2645  agg = "MIN ";
2646  break;
2647  case kMAX:
2648  agg = "MAX ";
2649  break;
2650  case kSUM:
2651  agg = "SUM ";
2652  break;
2653  case kCOUNT:
2654  agg = "COUNT ";
2655  break;
2657  agg = "APPROX_COUNT_DISTINCT";
2658  break;
2659  case kSINGLE_VALUE:
2660  agg = "SINGLE_VALUE";
2661  break;
2662  case kSAMPLE:
2663  agg = "SAMPLE";
2664  break;
2665  }
2666  std::string str{"(" + agg};
2667  if (is_distinct) {
2668  str += "DISTINCT ";
2669  }
2670  if (arg) {
2671  str += arg->toString();
2672  } else {
2673  str += "*";
2674  }
2675  return str + ") ";
2676 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1131
Definition: sqldefs.h:73
Definition: sqldefs.h:75
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:72
+ Here is the call graph for this function:

Member Data Documentation

◆ aggtype

SQLAgg Analyzer::AggExpr::aggtype
private

Definition at line 1130 of file Analyzer.h.

◆ arg

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

Definition at line 1131 of file Analyzer.h.

◆ error_rate

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

Definition at line 1133 of file Analyzer.h.

◆ is_distinct

bool Analyzer::AggExpr::is_distinct
private

Definition at line 1132 of file Analyzer.h.


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