OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::CaseExpr Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::CaseExpr:
+ Collaboration diagram for Analyzer::CaseExpr:

Public Member Functions

 CaseExpr (const SQLTypeInfo &ti, bool has_agg, const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &w, std::shared_ptr< Analyzer::Expr > e)
 
const std::list< std::pair
< std::shared_ptr
< Analyzer::Expr >
, std::shared_ptr
< Analyzer::Expr > > > & 
get_expr_pair_list () const
 
const Exprget_else_expr () const
 
std::shared_ptr< Analyzer::Exprdeep_copy () const override
 
void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) 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
 
std::shared_ptr< Analyzer::Expradd_cast (const SQLTypeInfo &new_type_info) override
 
void get_domain (DomainSet &domain_set) 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
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 ()
 

Private Attributes

std::list< std::pair
< std::shared_ptr
< Analyzer::Expr >
, std::shared_ptr
< Analyzer::Expr > > > 
expr_pair_list
 
std::shared_ptr< Analyzer::Exprelse_expr
 

Additional Inherited Members

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

Detailed Description

Definition at line 1246 of file Analyzer.h.

Constructor & Destructor Documentation

Analyzer::CaseExpr::CaseExpr ( const SQLTypeInfo ti,
bool  has_agg,
const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &  w,
std::shared_ptr< Analyzer::Expr e 
)
inline

Definition at line 1248 of file Analyzer.h.

1253  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

Member Function Documentation

std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::add_cast ( const SQLTypeInfo new_type_info)
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1375 of file Analyzer.cpp.

References else_expr, expr_pair_list, SQLTypeInfo::get_comp_param(), SQLTypeInfo::get_compression(), SQLTypeInfo::is_string(), kENCODING_DICT, kENCODING_NONE, SQLTypeInfo::set_comp_param(), TRANSIENT_DICT, TRANSIENT_DICT_ID, and Analyzer::Expr::type_info.

1375  {
1376  SQLTypeInfo ti = new_type_info;
1377  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1378  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1382  }
1383 
1384  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1385  new_expr_pair_list;
1386  for (auto& p : expr_pair_list) {
1387  new_expr_pair_list.emplace_back(
1388  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1389  }
1390 
1391  if (else_expr != nullptr) {
1392  else_expr = else_expr->add_cast(ti);
1393  }
1394  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1395  expr_pair_list = new_expr_pair_list;
1396 
1397  type_info = ti;
1398  return shared_from_this();
1399 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
SQLTypeInfo type_info
Definition: Analyzer.h:182
void set_comp_param(int p)
Definition: sqltypes.h:441
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:259
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:338
bool is_string() const
Definition: sqltypes.h:510
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:260
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

+ Here is the call graph for this function:

void Analyzer::CaseExpr::check_group_by ( const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3296 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3297  {
3298  for (auto p : expr_pair_list) {
3299  p.first->check_group_by(groupby);
3300  p.second->check_group_by(groupby);
3301  }
3302  if (else_expr != nullptr) {
3303  else_expr->check_group_by(groupby);
3304  }
3305 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
void Analyzer::CaseExpr::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3232 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3234  {
3235  for (auto p : expr_pair_list) {
3236  p.first->collect_column_var(colvar_set, include_agg);
3237  p.second->collect_column_var(colvar_set, include_agg);
3238  }
3239  if (else_expr != nullptr) {
3240  else_expr->collect_column_var(colvar_set, include_agg);
3241  }
3242 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3184 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3184  {
3185  for (auto p : expr_pair_list) {
3186  p.first->collect_rte_idx(rte_idx_set);
3187  p.second->collect_rte_idx(rte_idx_set);
3188  }
3189  if (else_expr != nullptr) {
3190  else_expr->collect_rte_idx(rte_idx_set);
3191  }
3192 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 184 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, else_expr, expr_pair_list, and Analyzer::Expr::type_info.

184  {
185  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
186  new_list;
187  for (auto p : expr_pair_list) {
188  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
189  }
190  return makeExpr<CaseExpr>(type_info,
191  contains_agg,
192  new_list,
193  else_expr == nullptr ? nullptr : else_expr->deep_copy());
194 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool contains_agg
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
void Analyzer::CaseExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3131 of file Analyzer.cpp.

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

3132  {
3133  if (f(this)) {
3134  add_unique(expr_list);
3135  return;
3136  }
3137  for (auto p : expr_pair_list) {
3138  p.first->find_expr(f, expr_list);
3139  p.second->find_expr(f, expr_list);
3140  }
3141  if (else_expr != nullptr) {
3142  else_expr->find_expr(f, expr_list);
3143  }
3144 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2988
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

+ Here is the call graph for this function:

void Analyzer::CaseExpr::get_domain ( DomainSet domain_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3329 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), else_expr, expr_pair_list, and kCAST.

3329  {
3330  for (const auto& p : expr_pair_list) {
3331  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3332  if (c != nullptr) {
3333  c->add_unique(domain_set);
3334  } else {
3335  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3336  if (v != nullptr) {
3337  v->add_unique(domain_set);
3338  } else {
3339  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3340  if (cast != nullptr && cast->get_optype() == kCAST) {
3341  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3342  if (c != nullptr) {
3343  cast->add_unique(domain_set);
3344  continue;
3345  } else {
3346  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3347  if (v != nullptr) {
3348  v->add_unique(domain_set);
3349  continue;
3350  }
3351  }
3352  }
3353  p.second->get_domain(domain_set);
3354  if (domain_set.empty()) {
3355  return;
3356  }
3357  }
3358  }
3359  }
3360  if (else_expr != nullptr) {
3361  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3362  if (c != nullptr) {
3363  c->add_unique(domain_set);
3364  } else {
3365  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3366  if (v != nullptr) {
3367  v->add_unique(domain_set);
3368  } else {
3369  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3370  if (cast != nullptr && cast->get_optype() == kCAST) {
3371  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3372  if (c != nullptr) {
3373  c->add_unique(domain_set);
3374  } else {
3375  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3376  if (v != nullptr) {
3377  v->add_unique(domain_set);
3378  }
3379  }
3380  } else {
3381  else_expr->get_domain(domain_set);
3382  }
3383  }
3384  }
3385  }
3386 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
Definition: sqldefs.h:49
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

+ Here is the call graph for this function:

const Expr* Analyzer::CaseExpr::get_else_expr ( ) const
inline

Definition at line 1259 of file Analyzer.h.

References else_expr.

Referenced by CodeGenerator::codegen(), getExpressionRange(), anonymous_namespace{WindowExpressionRewrite.cpp}::matches_else_null(), operator==(), ScalarExprToSql::visitCaseExpr(), DeepCopyVisitor::visitCaseExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitCaseExpr().

1259 { return else_expr.get(); }
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

+ Here is the caller graph for this function:

const std::list< std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr> > >& Analyzer::CaseExpr::get_expr_pair_list ( ) const
inline

Definition at line 1256 of file Analyzer.h.

References expr_pair_list.

Referenced by CodeGenerator::codegenCase(), getExpressionRange(), operator==(), rewrite_sum_window(), ScalarExprToSql::visitCaseExpr(), DeepCopyVisitor::visitCaseExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitCaseExpr().

1256  {
1257  return expr_pair_list;
1258  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286

+ Here is the caller graph for this function:

void Analyzer::CaseExpr::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 1765 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

1767  {
1768  std::set<int> rte_idx_set;
1769  for (auto p : expr_pair_list) {
1770  p.first->collect_rte_idx(rte_idx_set);
1771  p.second->collect_rte_idx(rte_idx_set);
1772  }
1773  if (else_expr != nullptr) {
1774  else_expr->collect_rte_idx(rte_idx_set);
1775  }
1776  if (rte_idx_set.size() > 1) {
1777  join_predicates.push_back(this);
1778  } else if (rte_idx_set.size() == 1) {
1779  scan_predicates.push_back(this);
1780  } else {
1781  const_predicates.push_back(this);
1782  }
1783 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2414 of file Analyzer.cpp.

References else_expr, expr_pair_list, get_else_expr(), and get_expr_pair_list().

2414  {
2415  if (typeid(rhs) != typeid(CaseExpr)) {
2416  return false;
2417  }
2418  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2419  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2420  return false;
2421  }
2422  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2423  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2424  return false;
2425  }
2426  auto it = rhs_ce.get_expr_pair_list().cbegin();
2427  for (auto p : expr_pair_list) {
2428  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2429  return false;
2430  }
2431  ++it;
2432  }
2433  return else_expr == nullptr ||
2434  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2435 }
CaseExpr(const SQLTypeInfo &ti, bool has_agg, const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &w, std::shared_ptr< Analyzer::Expr > e)
Definition: Analyzer.h:1248
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

+ Here is the call graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2102 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, else_expr, expr_pair_list, and Analyzer::Expr::type_info.

2103  {
2104  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2105  epair_list;
2106  for (auto p : expr_pair_list) {
2107  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2108  p.second->rewrite_agg_to_var(tlist));
2109  }
2110  return makeExpr<CaseExpr>(type_info,
2111  contains_agg,
2112  epair_list,
2113  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2114 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool contains_agg
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2059 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, else_expr, expr_pair_list, and Analyzer::Expr::type_info.

2060  {
2061  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2062  epair_list;
2063  for (auto p : expr_pair_list) {
2064  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2065  p.second->rewrite_with_child_targetlist(tlist));
2066  }
2067  return makeExpr<CaseExpr>(
2068  type_info,
2069  contains_agg,
2070  epair_list,
2071  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2072 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool contains_agg
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2016 of file Analyzer.cpp.

References Analyzer::Expr::contains_agg, else_expr, expr_pair_list, and Analyzer::Expr::type_info.

2017  {
2018  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2019  epair_list;
2020  for (auto p : expr_pair_list) {
2021  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2022  p.second->rewrite_with_targetlist(tlist));
2023  }
2024  return makeExpr<CaseExpr>(
2025  type_info,
2026  contains_agg,
2027  epair_list,
2028  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
2029 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
SQLTypeInfo type_info
Definition: Analyzer.h:182
bool contains_agg
Definition: Analyzer.h:183
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2851 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2851  {
2852  std::string str{"CASE "};
2853  for (auto p : expr_pair_list) {
2854  str += "(";
2855  str += p.first->toString();
2856  str += ", ";
2857  str += p.second->toString();
2858  str += ") ";
2859  }
2860  if (else_expr) {
2861  str += "ELSE ";
2862  str += else_expr->toString();
2863  }
2864  str += " END ";
2865  return str;
2866 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1286
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1289

Member Data Documentation


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