OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_arg1 () 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 size_t get_num_column_vars (const bool include_agg) 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
arg1
 

Additional Inherited Members

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

Detailed Description

Definition at line 1183 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 1185 of file Analyzer.h.

1190  : Expr(ti, true), aggtype(a), arg(g), is_distinct(d), arg1(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
constexpr double a
Definition: Utm.h:32
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1240
Analyzer::AggExpr::AggExpr ( SQLTypes  t,
SQLAgg  a,
Expr g,
bool  d,
std::shared_ptr< Analyzer::Constant e,
int  idx 
)
inline

Definition at line 1191 of file Analyzer.h.

1197  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1198  , aggtype(a)
1199  , arg(g)
1200  , is_distinct(d)
1201  , arg1(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
constexpr double a
Definition: Utm.h:32
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1240

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

References arg.

1219  {
1220  if (include_agg && arg != nullptr) {
1221  arg->collect_column_var(colvar_set, include_agg);
1222  }
1223  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1211 of file Analyzer.h.

References arg.

1211  {
1212  if (arg) {
1213  arg->collect_rte_idx(rte_idx_set);
1214  }
1215  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 177 of file Analyzer.cpp.

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

Referenced by rewrite_with_targetlist().

177  {
178  return makeExpr<AggExpr>(
179  type_info, aggtype, arg ? arg->deep_copy() : nullptr, is_distinct, arg1);
180 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
SQLTypeInfo type_info
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1240

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

References Analyzer::Expr::add_unique(), arg, and anonymous_namespace{Utm.h}::f.

3206  {
3207  if (f(this)) {
3208  add_unique(expr_list);
3209  return;
3210  }
3211  if (arg != nullptr) {
3212  arg->find_expr(f, expr_list);
3213  }
3214 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3073
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
constexpr double f
Definition: Utm.h:31

+ Here is the call graph for this function:

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

Definition at line 1202 of file Analyzer.h.

References aggtype.

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

1202 { return aggtype; }

+ Here is the caller graph for this function:

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 1206 of file Analyzer.h.

References arg1.

Referenced by DeepCopyVisitor::visitAggExpr().

1206 { return arg1; }
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1240

+ Here is the caller graph for this function:

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

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

1205 { 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 1204 of file Analyzer.h.

References arg.

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

References arg.

1782  {
1783  std::set<int> rte_idx_set;
1784  arg->collect_rte_idx(rte_idx_set);
1785  if (rte_idx_set.size() > 1) {
1786  join_predicates.push_back(this);
1787  } else if (rte_idx_set.size() == 1) {
1788  scan_predicates.push_back(this);
1789  } else {
1790  const_predicates.push_back(this);
1791  }
1792 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2428 of file Analyzer.cpp.

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

2428  {
2429  if (typeid(rhs) != typeid(AggExpr)) {
2430  return false;
2431  }
2432  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2433  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2434  return false;
2435  }
2436  if (arg.get() == rhs_ae.get_arg()) {
2437  return true;
2438  }
2439  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2440  return false;
2441  }
2442  return *arg == *rhs_ae.get_arg();
2443 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1185

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

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

2029  {
2030  int varno = 1;
2031  for (auto tle : tlist) {
2032  const Expr* e = tle->get_expr();
2033  if (typeid(*e) == typeid(AggExpr)) {
2034  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
2035  if (*this == *agg_expr) {
2036  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
2037  }
2038  }
2039  varno++;
2040  }
2041  throw std::runtime_error(
2042  "Internal error: cannot find AggExpr from having clause in targetlist.");
2043 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1185

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

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

2020  {
2021  return makeExpr<AggExpr>(type_info,
2022  aggtype,
2023  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
2024  is_distinct,
2025  arg1);
2026 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
SQLTypeInfo type_info
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1240
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 2005 of file Analyzer.cpp.

References deep_copy().

2006  {
2007  for (auto tle : tlist) {
2008  const Expr* e = tle->get_expr();
2009  if (typeid(*e) == typeid(AggExpr)) {
2010  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
2011  if (*this == *agg) {
2012  return agg->deep_copy();
2013  }
2014  }
2015  }
2016  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
2017 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1185

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2855 of file Analyzer.cpp.

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

2855  {
2856  std::string agg;
2857  switch (aggtype) {
2858  case kAVG:
2859  agg = "AVG ";
2860  break;
2861  case kMIN:
2862  agg = "MIN ";
2863  break;
2864  case kMAX:
2865  agg = "MAX ";
2866  break;
2867  case kSUM:
2868  agg = "SUM ";
2869  break;
2870  case kCOUNT:
2871  agg = "COUNT ";
2872  break;
2874  agg = "APPROX_COUNT_DISTINCT";
2875  break;
2876  case kAPPROX_QUANTILE:
2877  agg = "APPROX_PERCENTILE";
2878  break;
2879  case kSINGLE_VALUE:
2880  agg = "SINGLE_VALUE";
2881  break;
2882  case kSAMPLE:
2883  agg = "SAMPLE";
2884  break;
2885  }
2886  std::string str{"(" + agg};
2887  if (is_distinct) {
2888  str += "DISTINCT ";
2889  }
2890  if (arg) {
2891  str += arg->toString();
2892  } else {
2893  str += "*";
2894  }
2895  return str + ") ";
2896 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1237
Definition: sqldefs.h:74
Definition: sqldefs.h:76
Definition: sqldefs.h:77
Definition: sqldefs.h:75
Definition: sqldefs.h:73

Member Data Documentation

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

Definition at line 1240 of file Analyzer.h.

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


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