OmniSciDB  a5dc49c757
 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 1310 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 1312 of file Analyzer.h.

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

Definition at line 1318 of file Analyzer.h.

1324  : Expr(SQLTypeInfo(t, g == nullptr ? true : g->get_type_info().get_notnull()), true)
1325  , aggtype(a)
1326  , arg(g)
1327  , is_distinct(d)
1328  , arg1(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
constexpr double a
Definition: Utm.h:32
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1367

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

References arg.

1346  {
1347  if (include_agg && arg != nullptr) {
1348  arg->collect_column_var(colvar_set, include_agg);
1349  }
1350  }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
void Analyzer::AggExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1338 of file Analyzer.h.

References arg.

1338  {
1339  if (arg) {
1340  arg->collect_rte_idx(rte_idx_set);
1341  }
1342  };
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
std::shared_ptr< Analyzer::Expr > Analyzer::AggExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 194 of file Analyzer.cpp.

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

Referenced by rewrite_with_targetlist().

194  {
195  return makeExpr<AggExpr>(
196  type_info, aggtype, arg ? arg->deep_copy() : nullptr, is_distinct, arg1);
197 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1367

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

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

3406  {
3407  if (f(this)) {
3408  add_unique(expr_list);
3409  return;
3410  }
3411  if (arg != nullptr) {
3412  arg->find_expr(f, expr_list);
3413  }
3414 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3248
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)

+ Here is the call graph for this function:

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

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

1329 { return aggtype; }

+ Here is the caller graph for this function:

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

Definition at line 1330 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::set< shared::TableKey > >::visitAggExpr().

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

+ Here is the caller graph for this function:

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

Definition at line 1333 of file Analyzer.h.

References arg1.

Referenced by DeepCopyVisitor::visitAggExpr().

1333 { return arg1; }
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1367

+ Here is the caller graph for this function:

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

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

1332 { 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 1331 of file Analyzer.h.

References arg.

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

References arg.

1873  {
1874  std::set<int> rte_idx_set;
1875  arg->collect_rte_idx(rte_idx_set);
1876  if (rte_idx_set.size() > 1) {
1877  join_predicates.push_back(this);
1878  } else if (rte_idx_set.size() == 1) {
1879  scan_predicates.push_back(this);
1880  } else {
1881  const_predicates.push_back(this);
1882  }
1883 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
bool Analyzer::AggExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2560 of file Analyzer.cpp.

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

2560  {
2561  if (typeid(rhs) != typeid(AggExpr)) {
2562  return false;
2563  }
2564  const AggExpr& rhs_ae = dynamic_cast<const AggExpr&>(rhs);
2565  if (aggtype != rhs_ae.get_aggtype() || is_distinct != rhs_ae.get_is_distinct()) {
2566  return false;
2567  }
2568  if (arg.get() == rhs_ae.get_arg()) {
2569  return true;
2570  }
2571  if (arg == nullptr || rhs_ae.get_arg() == nullptr) {
2572  return false;
2573  }
2574  return *arg == *rhs_ae.get_arg();
2575 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1312

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

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

2118  {
2119  int varno = 1;
2120  for (auto tle : tlist) {
2121  const Expr* e = tle->get_expr();
2122  if (typeid(*e) == typeid(AggExpr)) {
2123  const AggExpr* agg_expr = dynamic_cast<const AggExpr*>(e);
2124  if (*this == *agg_expr) {
2125  return makeExpr<Var>(agg_expr->get_type_info(), Var::kINPUT_OUTER, varno);
2126  }
2127  }
2128  varno++;
2129  }
2130  throw std::runtime_error(
2131  "Internal error: cannot find AggExpr from having clause in targetlist.");
2132 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1312

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

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

2109  {
2110  return makeExpr<AggExpr>(type_info,
2111  aggtype,
2112  arg ? arg->rewrite_with_child_targetlist(tlist) : nullptr,
2113  is_distinct,
2114  arg1);
2115 }
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
SQLTypeInfo type_info
Definition: Analyzer.h:180
std::shared_ptr< Analyzer::Expr > arg1
Definition: Analyzer.h:1367
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 2094 of file Analyzer.cpp.

References deep_copy().

2095  {
2096  for (auto tle : tlist) {
2097  const Expr* e = tle->get_expr();
2098  if (typeid(*e) == typeid(AggExpr)) {
2099  const AggExpr* agg = dynamic_cast<const AggExpr*>(e);
2100  if (*this == *agg) {
2101  return agg->deep_copy();
2102  }
2103  }
2104  }
2105  throw std::runtime_error("Internal error: cannot find AggExpr in targetlist.");
2106 }
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
AggExpr(const SQLTypeInfo &ti, SQLAgg a, std::shared_ptr< Analyzer::Expr > g, bool d, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1312

+ Here is the call graph for this function:

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

Implements Analyzer::Expr.

Definition at line 3015 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.

3015  {
3016  std::string agg;
3017  switch (aggtype) {
3018  case kAVG:
3019  agg = "AVG ";
3020  break;
3021  case kMIN:
3022  agg = "MIN ";
3023  break;
3024  case kMAX:
3025  agg = "MAX ";
3026  break;
3027  case kSUM:
3028  agg = "SUM ";
3029  break;
3030  case kCOUNT:
3031  agg = "COUNT ";
3032  break;
3034  agg = "APPROX_COUNT_DISTINCT";
3035  break;
3036  case kAPPROX_QUANTILE:
3037  agg = "APPROX_PERCENTILE";
3038  break;
3039  case kSINGLE_VALUE:
3040  agg = "SINGLE_VALUE";
3041  break;
3042  case kSAMPLE:
3043  agg = "SAMPLE";
3044  break;
3045  case kMODE:
3046  agg = "MODE";
3047  break;
3048  case kCOUNT_IF:
3049  agg = "COUNT_IF";
3050  break;
3051  case kSUM_IF:
3052  agg = "SUM_IF";
3053  break;
3054  default:
3055  UNREACHABLE() << "Unhandled aggtype: " << aggtype;
3056  break;
3057  }
3058  std::string str{"(" + agg};
3059  if (is_distinct) {
3060  str += "DISTINCT ";
3061  }
3062  if (arg) {
3063  str += arg->toString();
3064  } else {
3065  str += "*";
3066  }
3067  return str + ") ";
3068 }
#define UNREACHABLE()
Definition: Logger.h:338
std::shared_ptr< Analyzer::Expr > arg
Definition: Analyzer.h:1364
Definition: sqldefs.h:78
Definition: sqldefs.h:80
Definition: sqldefs.h:81
Definition: sqldefs.h:79
Definition: sqldefs.h:77
Definition: sqldefs.h:86

Member Data Documentation

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

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