OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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::Constant
get_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::Expr
add_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::Expr
normalize_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::Constant
error_rate
 

Additional Inherited Members

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

Detailed Description

Definition at line 1025 of file Analyzer.h.

Constructor & Destructor Documentation

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

1032  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), error_rate(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
Analyzer::AggExpr::AggExpr ( SQLTypes  t,
SQLAgg  a,
Expr g,
bool  d,
std::shared_ptr< Analyzer::Constant e,
int  idx 
)
inline

Definition at line 1033 of file Analyzer.h.

1039  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1040  , aggtype(a)
1041  , arg(g)
1042  , is_distinct(d)
1043  , error_rate(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079

Member Function Documentation

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

References arg.

1061  {
1062  if (include_agg && arg != nullptr) {
1063  arg->collect_column_var(colvar_set, include_agg);
1064  }
1065  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1053 of file Analyzer.h.

References arg.

1053  {
1054  if (arg) {
1055  arg->collect_rte_idx(rte_idx_set);
1056  }
1057  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 155 of file Analyzer.cpp.

References aggtype, arg, error_rate, is_distinct, and Analyzer::Expr::type_info.

Referenced by rewrite_with_targetlist().

155  {
156  return makeExpr<AggExpr>(type_info,
157  aggtype,
158  arg == nullptr ? nullptr : arg->deep_copy(),
159  is_distinct,
160  error_rate);
161 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
SQLTypeInfo type_info
Definition: Analyzer.h:176

+ Here is the caller graph for this function:

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

Reimplemented from Analyzer::Expr.

Definition at line 2758 of file Analyzer.cpp.

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

2758  {
2759  if (f(this)) {
2760  add_unique(expr_list);
2761  return;
2762  }
2763  if (arg != nullptr) {
2764  arg->find_expr(f, expr_list);
2765  }
2766 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2648
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079

+ Here is the call graph for this function:

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

Definition at line 1044 of file Analyzer.h.

References aggtype.

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

1044 { return aggtype; }

+ Here is the caller graph for this function:

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

Definition at line 1045 of file Analyzer.h.

References arg.

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().

1045 { return arg.get(); }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079

+ Here is the caller graph for this function:

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

Definition at line 1048 of file Analyzer.h.

References error_rate.

Referenced by DeepCopyVisitor::visitAggExpr().

1048 { return error_rate; }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081

+ Here is the caller graph for this function:

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

Definition at line 1047 of file Analyzer.h.

References is_distinct.

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

1047 { return is_distinct; }

+ Here is the caller graph for this function:

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

Definition at line 1046 of file Analyzer.h.

References arg.

1046 { return arg; }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
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 1578 of file Analyzer.cpp.

References arg.

1580  {
1581  std::set<int> rte_idx_set;
1582  arg->collect_rte_idx(rte_idx_set);
1583  if (rte_idx_set.size() > 1) {
1584  join_predicates.push_back(this);
1585  } else if (rte_idx_set.size() == 1) {
1586  scan_predicates.push_back(this);
1587  } else {
1588  const_predicates.push_back(this);
1589  }
1590 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2163 of file Analyzer.cpp.

References aggtype, arg, get_aggtype(), get_arg(), get_is_distinct(), and is_distinct.

2163  {
2164  if (typeid(rhs) != typeid(AggExpr)) {
2165  return false;
2166  }
2167  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2168  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2169  return false;
2170  }
2171  if (arg.get() == rhs_ae.get_arg()) {
2172  return true;
2173  }
2174  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2175  return false;
2176  }
2177  return *arg == *rhs_ae.get_arg();
2178 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1027

+ Here is the call graph for this function:

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

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

1800  {
1801  int varno = 1;
1802  for (auto tle : tlist) {
1803  const Expr* e = tle->get_expr();
1804  if (typeid(*e) == typeid(AggExpr)) {
1805  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1806  if (*this == *agg_expr) {
1807  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1808  }
1809  }
1810  varno++;
1811  }
1812  throw std::runtime_error(
1813  "Internal error: cannot find AggExpr from having clause in targetlist.");
1814 }
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:1027

+ Here is the call graph for this function:

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

References aggtype, arg, error_rate, is_distinct, and Analyzer::Expr::type_info.

1791  {
1792  return makeExpr<AggExpr>(type_info,
1793  aggtype,
1794  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1795  is_distinct,
1796  error_rate);
1797 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1081
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
SQLTypeInfo type_info
Definition: Analyzer.h:176
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 1776 of file Analyzer.cpp.

References deep_copy().

1777  {
1778  for (auto tle : tlist) {
1779  const Expr* e = tle->get_expr();
1780  if (typeid(*e) == typeid(AggExpr)) {
1781  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1782  if (*this == *agg) {
1783  return agg->deep_copy();
1784  }
1785  }
1786  }
1787  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1788 }
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:1027

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2515 of file Analyzer.cpp.

References aggtype, arg, is_distinct, kAPPROX_COUNT_DISTINCT, kAVG, kCOUNT, kMAX, kMIN, kSAMPLE, kSINGLE_VALUE, and kSUM.

2515  {
2516  std::string agg;
2517  switch (aggtype) {
2518  case kAVG:
2519  agg = "AVG ";
2520  break;
2521  case kMIN:
2522  agg = "MIN ";
2523  break;
2524  case kMAX:
2525  agg = "MAX ";
2526  break;
2527  case kSUM:
2528  agg = "SUM ";
2529  break;
2530  case kCOUNT:
2531  agg = "COUNT ";
2532  break;
2534  agg = "APPROX_COUNT_DISTINCT";
2535  break;
2536  case kSINGLE_VALUE:
2537  agg = "SINGLE_VALUE";
2538  break;
2539  case kSAMPLE:
2540  agg = "SAMPLE";
2541  break;
2542  }
2543  std::string str{"(" + agg};
2544  if (is_distinct) {
2545  str += "DISTINCT ";
2546  }
2547  if (arg) {
2548  str += arg->toString();
2549  } else {
2550  str += "*";
2551  }
2552  return str + ") ";
2553 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
Definition: sqldefs.h:73
Definition: sqldefs.h:75
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:72

Member Data Documentation

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

Definition at line 1081 of file Analyzer.h.

Referenced by deep_copy(), get_error_rate(), and rewrite_with_child_targetlist().

bool Analyzer::AggExpr::is_distinct
private

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