OmniSciDB  a987f07e93
 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::Expr > e)
 
 AggExpr (SQLTypes t, SQLAgg a, Expr *g, bool d, std::shared_ptr< Analyzer::Expr > 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::Exprget_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 (std::function< bool(const Expr *)> f, 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::Exprarg1
 

Additional Inherited Members

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

Detailed Description

Definition at line 1184 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::Expr e 
)
inline

Definition at line 1186 of file Analyzer.h.

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

Definition at line 1192 of file Analyzer.h.

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

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

References arg.

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

Reimplemented from Analyzer::Expr.

Definition at line 1212 of file Analyzer.h.

References arg.

1212  {
1213  if (arg) {
1214  arg->collect_rte_idx(rte_idx_set);
1215  }
1216  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
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:1238
SQLTypeInfo type_info
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1241

+ Here is the caller graph for this function:

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

Reimplemented from Analyzer::Expr.

Definition at line 3236 of file Analyzer.cpp.

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

3237  {
3238  if (f(this)) {
3239  add_unique(expr_list);
3240  return;
3241  }
3242  if (arg != nullptr) {
3243  arg->find_expr(f, expr_list);
3244  }
3245 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3101
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
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 1203 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().

1203 { return aggtype; }

+ Here is the caller graph for this function:

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 1207 of file Analyzer.h.

References arg1.

Referenced by QueryMemoryInitializer::allocateTDigests(), and DeepCopyVisitor::visitAggExpr().

1207 { return arg1; }
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1241

+ Here is the caller graph for this function:

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

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

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

References arg.

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

References arg.

1798  {
1799  std::set<int> rte_idx_set;
1800  arg->collect_rte_idx(rte_idx_set);
1801  if (rte_idx_set.size() > 1) {
1802  join_predicates.push_back(this);
1803  } else if (rte_idx_set.size() == 1) {
1804  scan_predicates.push_back(this);
1805  } else {
1806  const_predicates.push_back(this);
1807  }
1808 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2444 of file Analyzer.cpp.

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

2444  {
2445  if (typeid(rhs) != typeid(AggExpr)) {
2446  return false;
2447  }
2448  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2449  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2450  return false;
2451  }
2452  if (arg.get() == rhs_ae.get_arg()) {
2453  return true;
2454  }
2455  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2456  return false;
2457  }
2458  return *arg == *rhs_ae.get_arg();
2459 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1186

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

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

2045  {
2046  int varno = 1;
2047  for (auto tle : tlist) {
2048  const Expr* e = tle->get_expr();
2049  if (typeid(*e) == typeid(AggExpr)) {
2050  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
2051  if (*this == *agg_expr) {
2052  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
2053  }
2054  }
2055  varno++;
2056  }
2057  throw std::runtime_error(
2058  "Internal error: cannot find AggExpr from having clause in targetlist.");
2059 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1186

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

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

2036  {
2037  return makeExpr<AggExpr>(type_info,
2038  aggtype,
2039  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
2040  is_distinct,
2041  arg1);
2042 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
SQLTypeInfo type_info
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1241
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 2021 of file Analyzer.cpp.

References deep_copy().

2022  {
2023  for (auto tle : tlist) {
2024  const Expr* e = tle->get_expr();
2025  if (typeid(*e) == typeid(AggExpr)) {
2026  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
2027  if (*this == *agg) {
2028  return agg->deep_copy();
2029  }
2030  }
2031  }
2032  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
2033 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1186

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2871 of file Analyzer.cpp.

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

2871  {
2872  std::string agg;
2873  switch (aggtype) {
2874  case kAVG:
2875  agg = "AVG ";
2876  break;
2877  case kMIN:
2878  agg = "MIN ";
2879  break;
2880  case kMAX:
2881  agg = "MAX ";
2882  break;
2883  case kSUM:
2884  agg = "SUM ";
2885  break;
2886  case kCOUNT:
2887  agg = "COUNT ";
2888  break;
2890  agg = "APPROX_COUNT_DISTINCT";
2891  break;
2892  case kAPPROX_QUANTILE:
2893  agg = "APPROX_PERCENTILE";
2894  break;
2895  case kSINGLE_VALUE:
2896  agg = "SINGLE_VALUE";
2897  break;
2898  case kSAMPLE:
2899  agg = "SAMPLE";
2900  break;
2901  case kMODE:
2902  agg = "MODE";
2903  break;
2904  case kCOUNT_IF:
2905  agg = "COUNT_IF";
2906  break;
2907  case kSUM_IF:
2908  agg = "SUM_IF";
2909  break;
2910  default:
2911  UNREACHABLE() << "Unhandled aggtype: " << aggtype;
2912  break;
2913  }
2914  std::string str{"(" + agg};
2915  if (is_distinct) {
2916  str += "DISTINCT ";
2917  }
2918  if (arg) {
2919  str += arg->toString();
2920  } else {
2921  str += "*";
2922  }
2923  return str + ") ";
2924 }
#define UNREACHABLE()
Definition: Logger.h:333
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1238
Definition: sqldefs.h:75
Definition: sqldefs.h:77
Definition: sqldefs.h:78
Definition: sqldefs.h:76
Definition: sqldefs.h:74
Definition: sqldefs.h:83

Member Data Documentation

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

Definition at line 1241 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: