OmniSciDB  b24e664e58
 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
SQLTypeInfoCore< ArrayContextTypeSizer, ExecutorTypePackaging, DateTimeFacilities > SQLTypeInfo
Definition: sqltypes.h:852

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

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

2749  {
2750  if (f(this)) {
2751  add_unique(expr_list);
2752  return;
2753  }
2754  if (arg != nullptr) {
2755  arg->find_expr(f, expr_list);
2756  }
2757 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2639
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{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(), 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{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 1577 of file Analyzer.cpp.

References arg.

1579  {
1580  std::set<int> rte_idx_set;
1581  arg->collect_rte_idx(rte_idx_set);
1582  if (rte_idx_set.size() > 1) {
1583  join_predicates.push_back(this);
1584  } else if (rte_idx_set.size() == 1) {
1585  scan_predicates.push_back(this);
1586  } else {
1587  const_predicates.push_back(this);
1588  }
1589 }
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 2162 of file Analyzer.cpp.

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

2162  {
2163  if (typeid(rhs) != typeid(AggExpr)) {
2164  return false;
2165  }
2166  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2167  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2168  return false;
2169  }
2170  if (arg.get() == rhs_ae.get_arg()) {
2171  return true;
2172  }
2173  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2174  return false;
2175  }
2176  return *arg == *rhs_ae.get_arg();
2177 }
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 1798 of file Analyzer.cpp.

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

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

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

1790  {
1791  return makeExpr<AggExpr>(type_info,
1792  aggtype,
1793  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1794  is_distinct,
1795  error_rate);
1796 }
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 1775 of file Analyzer.cpp.

References deep_copy().

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

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

2509  {
2510  std::string agg;
2511  switch (aggtype) {
2512  case kAVG:
2513  agg = "AVG ";
2514  break;
2515  case kMIN:
2516  agg = "MIN ";
2517  break;
2518  case kMAX:
2519  agg = "MAX ";
2520  break;
2521  case kSUM:
2522  agg = "SUM ";
2523  break;
2524  case kCOUNT:
2525  agg = "COUNT ";
2526  break;
2528  agg = "APPROX_COUNT_DISTINCT";
2529  break;
2530  case kSAMPLE:
2531  agg = "SAMPLE";
2532  break;
2533  }
2534  std::string str{"(" + agg};
2535  if (is_distinct) {
2536  str += "DISTINCT ";
2537  }
2538  if (arg) {
2539  str += arg->toString();
2540  } else {
2541  str += "*";
2542  }
2543  return str + ") ";
2544 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1079
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71
Definition: sqldefs.h:71

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: