OmniSciDB  340b00dbf6
 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 1076 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 1078 of file Analyzer.h.

1083  : 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:1132
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
Analyzer::AggExpr::AggExpr ( SQLTypes  t,
SQLAgg  a,
Expr g,
bool  d,
std::shared_ptr< Analyzer::Constant e,
int  idx 
)
inline

Definition at line 1084 of file Analyzer.h.

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

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

References arg.

1112  {
1113  if (include_agg && arg != nullptr) {
1114  arg->collect_column_var(colvar_set, include_agg);
1115  }
1116  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1104 of file Analyzer.h.

References arg.

1104  {
1105  if (arg) {
1106  arg->collect_rte_idx(rte_idx_set);
1107  }
1108  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 157 of file Analyzer.cpp.

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

Referenced by rewrite_with_targetlist().

157  {
158  return makeExpr<AggExpr>(type_info,
159  aggtype,
160  arg == nullptr ? nullptr : arg->deep_copy(),
161  is_distinct,
162  error_rate);
163 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1132
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
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 2931 of file Analyzer.cpp.

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

2931  {
2932  if (f(this)) {
2933  add_unique(expr_list);
2934  return;
2935  }
2936  if (arg != nullptr) {
2937  arg->find_expr(f, expr_list);
2938  }
2939 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2812
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130

+ Here is the call graph for this function:

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

Definition at line 1095 of file Analyzer.h.

References aggtype.

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

1095 { return aggtype; }

+ Here is the caller graph for this function:

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

Definition at line 1096 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().

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

+ Here is the caller graph for this function:

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

Definition at line 1099 of file Analyzer.h.

References error_rate.

Referenced by DeepCopyVisitor::visitAggExpr().

1099 { return error_rate; }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1132

+ Here is the caller graph for this function:

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

Definition at line 1098 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().

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

References arg.

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

References arg.

1666  {
1667  std::set<int> rte_idx_set;
1668  arg->collect_rte_idx(rte_idx_set);
1669  if (rte_idx_set.size() > 1) {
1670  join_predicates.push_back(this);
1671  } else if (rte_idx_set.size() == 1) {
1672  scan_predicates.push_back(this);
1673  } else {
1674  const_predicates.push_back(this);
1675  }
1676 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2260 of file Analyzer.cpp.

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

2260  {
2261  if (typeid(rhs) != typeid(AggExpr)) {
2262  return false;
2263  }
2264  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2265  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2266  return false;
2267  }
2268  if (arg.get() == rhs_ae.get_arg()) {
2269  return true;
2270  }
2271  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2272  return false;
2273  }
2274  return *arg == *rhs_ae.get_arg();
2275 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1078

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

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

1886  {
1887  int varno = 1;
1888  for (auto tle : tlist) {
1889  const Expr* e = tle->get_expr();
1890  if (typeid(*e) == typeid(AggExpr)) {
1891  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1892  if (*this == *agg_expr) {
1893  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1894  }
1895  }
1896  varno++;
1897  }
1898  throw std::runtime_error(
1899  "Internal error: cannot find AggExpr from having clause in targetlist.");
1900 }
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:1078

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

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

1877  {
1878  return makeExpr<AggExpr>(type_info,
1879  aggtype,
1880  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1881  is_distinct,
1882  error_rate);
1883 }
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1132
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
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 1862 of file Analyzer.cpp.

References deep_copy().

1863  {
1864  for (auto tle : tlist) {
1865  const Expr* e = tle->get_expr();
1866  if (typeid(*e) == typeid(AggExpr)) {
1867  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1868  if (*this == *agg) {
1869  return agg->deep_copy();
1870  }
1871  }
1872  }
1873  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1874 }
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:1078

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2635 of file Analyzer.cpp.

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

2635  {
2636  std::string agg;
2637  switch (aggtype) {
2638  case kAVG:
2639  agg = "AVG ";
2640  break;
2641  case kMIN:
2642  agg = "MIN ";
2643  break;
2644  case kMAX:
2645  agg = "MAX ";
2646  break;
2647  case kSUM:
2648  agg = "SUM ";
2649  break;
2650  case kCOUNT:
2651  agg = "COUNT ";
2652  break;
2654  agg = "APPROX_COUNT_DISTINCT";
2655  break;
2656  case kSINGLE_VALUE:
2657  agg = "SINGLE_VALUE";
2658  break;
2659  case kSAMPLE:
2660  agg = "SAMPLE";
2661  break;
2662  }
2663  std::string str{"(" + agg};
2664  if (is_distinct) {
2665  str += "DISTINCT ";
2666  }
2667  if (arg) {
2668  str += arg->toString();
2669  } else {
2670  str += "*";
2671  }
2672  return str + ") ";
2673 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
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 1132 of file Analyzer.h.

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


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