OmniSciDB  91042dcc5b
 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 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 1230 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 1232 of file Analyzer.h.

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

Definition at line 1238 of file Analyzer.h.

1244  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1245  , aggtype(a)
1246  , arg(g)
1247  , is_distinct(d)
1248  , arg1(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
constexpr double a
Definition: Utm.h:32
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1287
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 1263 of file Analyzer.h.

References arg.

1266  {
1267  if (include_agg && arg != nullptr) {
1268  arg->collect_column_var(colvar_set, include_agg);
1269  }
1270  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1258 of file Analyzer.h.

References arg.

1258  {
1259  if (arg) {
1260  arg->collect_rte_idx(rte_idx_set);
1261  }
1262  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 175 of file Analyzer.cpp.

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

Referenced by rewrite_with_targetlist().

175  {
176  return makeExpr<AggExpr>(
177  type_info, aggtype, arg ? arg->deep_copy() : nullptr, is_distinct, arg1);
178 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1287

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

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

3096  {
3097  if (f(this)) {
3098  add_unique(expr_list);
3099  return;
3100  }
3101  if (arg != nullptr) {
3102  arg->find_expr(f, expr_list);
3103  }
3104 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2965
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
char * f

+ Here is the call graph for this function:

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

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

1249 { return aggtype; }

+ Here is the caller graph for this function:

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 1253 of file Analyzer.h.

References arg1.

Referenced by DeepCopyVisitor::visitAggExpr().

1253 { return arg1; }
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1287

+ Here is the caller graph for this function:

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

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

1252 { 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 1251 of file Analyzer.h.

References arg.

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

References arg.

1745  {
1746  std::set<int> rte_idx_set;
1747  arg->collect_rte_idx(rte_idx_set);
1748  if (rte_idx_set.size() > 1) {
1749  join_predicates.push_back(this);
1750  } else if (rte_idx_set.size() == 1) {
1751  scan_predicates.push_back(this);
1752  } else {
1753  const_predicates.push_back(this);
1754  }
1755 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2370 of file Analyzer.cpp.

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

2370  {
2371  if (typeid(rhs) != typeid(AggExpr)) {
2372  return false;
2373  }
2374  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2375  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2376  return false;
2377  }
2378  if (arg.get() == rhs_ae.get_arg()) {
2379  return true;
2380  }
2381  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2382  return false;
2383  }
2384  return *arg == *rhs_ae.get_arg();
2385 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1232

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

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

1965  {
1966  int varno = 1;
1967  for (auto tle : tlist) {
1968  const Expr* e = tle->get_expr();
1969  if (typeid(*e) == typeid(AggExpr)) {
1970  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
1971  if (*this == *agg_expr) {
1972  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
1973  }
1974  }
1975  varno++;
1976  }
1977  throw std::runtime_error(
1978  "Internal error: cannot find AggExpr from having clause in targetlist.");
1979 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1232

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

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

1956  {
1957  return makeExpr<AggExpr>(type_info,
1958  aggtype,
1959  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
1960  is_distinct,
1961  arg1);
1962 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
SQLTypeInfo type_info
Definition: Analyzer.h:175
std::shared_ptr< Analyzer::Constant > arg1
Definition: Analyzer.h:1287
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 1941 of file Analyzer.cpp.

References deep_copy().

1942  {
1943  for (auto tle : tlist) {
1944  const Expr* e = tle->get_expr();
1945  if (typeid(*e) == typeid(AggExpr)) {
1946  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
1947  if (*this == *agg) {
1948  return agg->deep_copy();
1949  }
1950  }
1951  }
1952  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
1953 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Constant > e)
Definition: Analyzer.h:1232

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 2785 of file Analyzer.cpp.

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

2785  {
2786  std::string agg;
2787  switch (aggtype) {
2788  case kAVG:
2789  agg = "AVG ";
2790  break;
2791  case kMIN:
2792  agg = "MIN ";
2793  break;
2794  case kMAX:
2795  agg = "MAX ";
2796  break;
2797  case kSUM:
2798  agg = "SUM ";
2799  break;
2800  case kCOUNT:
2801  agg = "COUNT ";
2802  break;
2804  agg = "APPROX_COUNT_DISTINCT";
2805  break;
2806  case kAPPROX_QUANTILE:
2807  agg = "APPROX_PERCENTILE";
2808  break;
2809  case kSINGLE_VALUE:
2810  agg = "SINGLE_VALUE";
2811  break;
2812  case kSAMPLE:
2813  agg = "SAMPLE";
2814  break;
2815  }
2816  std::string str{"(" + agg};
2817  if (is_distinct) {
2818  str += "DISTINCT ";
2819  }
2820  if (arg) {
2821  str += arg->toString();
2822  } else {
2823  str += "*";
2824  }
2825  return str + ") ";
2826 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1284
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::arg1
private

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