OmniSciDB  fe05a0c208
 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
tuple d
Definition: test_fsi.py:9
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
tuple d
Definition: test_fsi.py:9
std::shared_ptr< Analyzer::Constant > error_rate
Definition: Analyzer.h:1132
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
char * t

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

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

Referenced by rewrite_with_targetlist().

160  {
161  return makeExpr<AggExpr>(type_info,
162  aggtype,
163  arg == nullptr ? nullptr : arg->deep_copy(),
164  is_distinct,
165  error_rate);
166 }
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 2989 of file Analyzer.cpp.

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

2989  {
2990  if (f(this)) {
2991  add_unique(expr_list);
2992  return;
2993  }
2994  if (arg != nullptr) {
2995  arg->find_expr(f, expr_list);
2996  }
2997 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2870
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1130
char * f

+ 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(), anonymous_namespace{GroupByAndAggregate.cpp}::init_count_distinct_descriptors(), 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 1719 of file Analyzer.cpp.

References arg.

1721  {
1722  std::set<int> rte_idx_set;
1723  arg->collect_rte_idx(rte_idx_set);
1724  if (rte_idx_set.size() > 1) {
1725  join_predicates.push_back(this);
1726  } else if (rte_idx_set.size() == 1) {
1727  scan_predicates.push_back(this);
1728  } else {
1729  const_predicates.push_back(this);
1730  }
1731 }
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 2315 of file Analyzer.cpp.

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

2315  {
2316  if (typeid(rhs) != typeid(AggExpr)) {
2317  return false;
2318  }
2319  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2320  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2321  return false;
2322  }
2323  if (arg.get() == rhs_ae.get_arg()) {
2324  return true;
2325  }
2326  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2327  return false;
2328  }
2329  return *arg == *rhs_ae.get_arg();
2330 }
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 1940 of file Analyzer.cpp.

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

1941  {
1942  int varno = 1;
1943  for (auto tle : tlist) {
1944  const Expr* e = tle->get_expr();
1945  if (typeid(*e) == typeid(AggExpr)) {
1946  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1947  if (*this == *agg_expr) {
1948  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1949  }
1950  }
1951  varno++;
1952  }
1953  throw std::runtime_error(
1954  "Internal error: cannot find AggExpr from having clause in targetlist.");
1955 }
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 1931 of file Analyzer.cpp.

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

1932  {
1933  return makeExpr<AggExpr>(type_info,
1934  aggtype,
1935  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1936  is_distinct,
1937  error_rate);
1938 }
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 1917 of file Analyzer.cpp.

References deep_copy().

1918  {
1919  for (auto tle : tlist) {
1920  const Expr* e = tle->get_expr();
1921  if (typeid(*e) == typeid(AggExpr)) {
1922  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1923  if (*this == *agg) {
1924  return agg->deep_copy();
1925  }
1926  }
1927  }
1928  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1929 }
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 2690 of file Analyzer.cpp.

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

2690  {
2691  std::string agg;
2692  switch (aggtype) {
2693  case kAVG:
2694  agg = "AVG ";
2695  break;
2696  case kMIN:
2697  agg = "MIN ";
2698  break;
2699  case kMAX:
2700  agg = "MAX ";
2701  break;
2702  case kSUM:
2703  agg = "SUM ";
2704  break;
2705  case kCOUNT:
2706  agg = "COUNT ";
2707  break;
2709  agg = "APPROX_COUNT_DISTINCT";
2710  break;
2711  case kAPPROX_MEDIAN:
2712  agg = "APPROX_MEDIAN";
2713  break;
2714  case kSINGLE_VALUE:
2715  agg = "SINGLE_VALUE";
2716  break;
2717  case kSAMPLE:
2718  agg = "SAMPLE";
2719  break;
2720  }
2721  std::string str{"(" + agg};
2722  if (is_distinct) {
2723  str += "DISTINCT ";
2724  }
2725  if (arg) {
2726  str += arg->toString();
2727  } else {
2728  str += "*";
2729  }
2730  return str + ") ";
2731 }
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: