OmniSciDB  a987f07e93
 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 (std::function< bool(const Expr *)> f, 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 1248 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 1250 of file Analyzer.h.

1255  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:74
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

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 1420 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.

1420  {
1421  SQLTypeInfo ti = new_type_info;
1422  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1423  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1427  }
1428 
1429  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1430  new_expr_pair_list;
1431  for (auto& p : expr_pair_list) {
1432  new_expr_pair_list.emplace_back(
1433  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1434  }
1435 
1436  if (else_expr != nullptr) {
1437  else_expr = else_expr->add_cast(ti);
1438  }
1439  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1440  expr_pair_list = new_expr_pair_list;
1441 
1442  type_info = ti;
1443  return shared_from_this();
1444 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
SQLTypeInfo type_info
Definition: Analyzer.h:184
void set_comp_param(int p)
Definition: sqltypes.h:502
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:310
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:388
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:389
bool is_string() const
Definition: sqltypes.h:576
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:311
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

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

References else_expr, and expr_pair_list.

3424  {
3425  for (auto p : expr_pair_list) {
3426  p.first->check_group_by(groupby);
3427  p.second->check_group_by(groupby);
3428  }
3429  if (else_expr != nullptr) {
3430  else_expr->check_group_by(groupby);
3431  }
3432 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
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 3359 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3361  {
3362  for (auto p : expr_pair_list) {
3363  p.first->collect_column_var(colvar_set, include_agg);
3364  p.second->collect_column_var(colvar_set, include_agg);
3365  }
3366  if (else_expr != nullptr) {
3367  else_expr->collect_column_var(colvar_set, include_agg);
3368  }
3369 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3311 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3311  {
3312  for (auto p : expr_pair_list) {
3313  p.first->collect_rte_idx(rte_idx_set);
3314  p.second->collect_rte_idx(rte_idx_set);
3315  }
3316  if (else_expr != nullptr) {
3317  else_expr->collect_rte_idx(rte_idx_set);
3318  }
3319 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 182 of file Analyzer.cpp.

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

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

Reimplemented from Analyzer::Expr.

Definition at line 3247 of file Analyzer.cpp.

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

3248  {
3249  if (f(this)) {
3250  add_unique(expr_list);
3251  return;
3252  }
3253  for (auto p : expr_pair_list) {
3254  p.first->find_expr(f, expr_list);
3255  p.second->find_expr(f, expr_list);
3256  }
3257  if (else_expr != nullptr) {
3258  else_expr->find_expr(f, expr_list);
3259  }
3260 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3101
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

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

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

3456  {
3457  for (const auto& p : expr_pair_list) {
3458  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3459  if (c != nullptr) {
3460  c->add_unique(domain_set);
3461  } else {
3462  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3463  if (v != nullptr) {
3464  v->add_unique(domain_set);
3465  } else {
3466  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3467  if (cast != nullptr && cast->get_optype() == kCAST) {
3468  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3469  if (c != nullptr) {
3470  cast->add_unique(domain_set);
3471  continue;
3472  } else {
3473  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3474  if (v != nullptr) {
3475  v->add_unique(domain_set);
3476  continue;
3477  }
3478  }
3479  }
3480  p.second->get_domain(domain_set);
3481  if (domain_set.empty()) {
3482  return;
3483  }
3484  }
3485  }
3486  }
3487  if (else_expr != nullptr) {
3488  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3489  if (c != nullptr) {
3490  c->add_unique(domain_set);
3491  } else {
3492  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3493  if (v != nullptr) {
3494  v->add_unique(domain_set);
3495  } else {
3496  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3497  if (cast != nullptr && cast->get_optype() == kCAST) {
3498  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3499  if (c != nullptr) {
3500  c->add_unique(domain_set);
3501  } else {
3502  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3503  if (v != nullptr) {
3504  v->add_unique(domain_set);
3505  }
3506  }
3507  } else {
3508  else_expr->get_domain(domain_set);
3509  }
3510  }
3511  }
3512  }
3513 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
Definition: sqldefs.h:48
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

+ Here is the call graph for this function:

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

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

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

+ 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 1258 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().

1258  {
1259  return expr_pair_list;
1260  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288

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

References else_expr, and expr_pair_list.

1812  {
1813  std::set<int> rte_idx_set;
1814  for (auto p : expr_pair_list) {
1815  p.first->collect_rte_idx(rte_idx_set);
1816  p.second->collect_rte_idx(rte_idx_set);
1817  }
1818  if (else_expr != nullptr) {
1819  else_expr->collect_rte_idx(rte_idx_set);
1820  }
1821  if (rte_idx_set.size() > 1) {
1822  join_predicates.push_back(this);
1823  } else if (rte_idx_set.size() == 1) {
1824  scan_predicates.push_back(this);
1825  } else {
1826  const_predicates.push_back(this);
1827  }
1828 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2461 of file Analyzer.cpp.

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

2461  {
2462  if (typeid(rhs) != typeid(CaseExpr)) {
2463  return false;
2464  }
2465  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2466  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2467  return false;
2468  }
2469  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2470  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2471  return false;
2472  }
2473  auto it = rhs_ce.get_expr_pair_list().cbegin();
2474  for (auto p : expr_pair_list) {
2475  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2476  return false;
2477  }
2478  ++it;
2479  }
2480  return else_expr == nullptr ||
2481  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2482 }
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:1250
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

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

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

2148  {
2149  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2150  epair_list;
2151  for (auto p : expr_pair_list) {
2152  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2153  p.second->rewrite_agg_to_var(tlist));
2154  }
2155  return makeExpr<CaseExpr>(type_info,
2156  contains_agg,
2157  epair_list,
2158  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2159 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool contains_agg
Definition: Analyzer.h:185
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
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 2104 of file Analyzer.cpp.

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

2105  {
2106  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2107  epair_list;
2108  for (auto p : expr_pair_list) {
2109  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2110  p.second->rewrite_with_child_targetlist(tlist));
2111  }
2112  return makeExpr<CaseExpr>(
2113  type_info,
2114  contains_agg,
2115  epair_list,
2116  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2117 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool contains_agg
Definition: Analyzer.h:185
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
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 2061 of file Analyzer.cpp.

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

2062  {
2063  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2064  epair_list;
2065  for (auto p : expr_pair_list) {
2066  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2067  p.second->rewrite_with_targetlist(tlist));
2068  }
2069  return makeExpr<CaseExpr>(
2070  type_info,
2071  contains_agg,
2072  epair_list,
2073  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
2074 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
SQLTypeInfo type_info
Definition: Analyzer.h:184
bool contains_agg
Definition: Analyzer.h:185
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2926 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2926  {
2927  std::string str{"CASE "};
2928  for (auto p : expr_pair_list) {
2929  str += "(";
2930  str += p.first->toString();
2931  str += ", ";
2932  str += p.second->toString();
2933  str += ") ";
2934  }
2935  if (else_expr) {
2936  str += "ELSE ";
2937  str += else_expr->toString();
2938  }
2939  str += " END ";
2940  return str;
2941 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1288
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1291

Member Data Documentation


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