OmniSciDB  c1a53651b2
 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 1252 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 1254 of file Analyzer.h.

1259  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:70
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295

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

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

1436  {
1437  SQLTypeInfo ti = new_type_info;
1438  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1439  new_type_info.getStringDictKey().isTransientDict() && type_info.is_string() &&
1443  }
1444 
1445  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1446  new_expr_pair_list;
1447  for (auto& p : expr_pair_list) {
1448  new_expr_pair_list.emplace_back(
1449  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1450  }
1451 
1452  if (else_expr != nullptr) {
1453  else_expr = else_expr->add_cast(ti);
1454  }
1455  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1456  expr_pair_list = new_expr_pair_list;
1457 
1458  type_info = ti;
1459  return shared_from_this();
1460 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
#define TRANSIENT_DICT_ID
Definition: DbObjectKeys.h:24
SQLTypeInfo type_info
Definition: Analyzer.h:180
void set_comp_param(int p)
Definition: sqltypes.h:505
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:389
bool isTransientDict() const
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:392
bool is_string() const
Definition: sqltypes.h:580
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:312
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1021

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

References else_expr, and expr_pair_list.

3439  {
3440  for (auto p : expr_pair_list) {
3441  p.first->check_group_by(groupby);
3442  p.second->check_group_by(groupby);
3443  }
3444  if (else_expr != nullptr) {
3445  else_expr->check_group_by(groupby);
3446  }
3447 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
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 3374 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3376  {
3377  for (auto p : expr_pair_list) {
3378  p.first->collect_column_var(colvar_set, include_agg);
3379  p.second->collect_column_var(colvar_set, include_agg);
3380  }
3381  if (else_expr != nullptr) {
3382  else_expr->collect_column_var(colvar_set, include_agg);
3383  }
3384 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3326 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3326  {
3327  for (auto p : expr_pair_list) {
3328  p.first->collect_rte_idx(rte_idx_set);
3329  p.second->collect_rte_idx(rte_idx_set);
3330  }
3331  if (else_expr != nullptr) {
3332  else_expr->collect_rte_idx(rte_idx_set);
3333  }
3334 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
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:1292
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
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 3262 of file Analyzer.cpp.

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

3263  {
3264  if (f(this)) {
3265  add_unique(expr_list);
3266  return;
3267  }
3268  for (auto p : expr_pair_list) {
3269  p.first->find_expr(f, expr_list);
3270  p.second->find_expr(f, expr_list);
3271  }
3272  if (else_expr != nullptr) {
3273  else_expr->find_expr(f, expr_list);
3274  }
3275 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3116
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295

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

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

3471  {
3472  for (const auto& p : expr_pair_list) {
3473  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3474  if (c != nullptr) {
3475  c->add_unique(domain_set);
3476  } else {
3477  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3478  if (v != nullptr) {
3479  v->add_unique(domain_set);
3480  } else {
3481  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3482  if (cast != nullptr && cast->get_optype() == kCAST) {
3483  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3484  if (c != nullptr) {
3485  cast->add_unique(domain_set);
3486  continue;
3487  } else {
3488  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3489  if (v != nullptr) {
3490  v->add_unique(domain_set);
3491  continue;
3492  }
3493  }
3494  }
3495  p.second->get_domain(domain_set);
3496  if (domain_set.empty()) {
3497  return;
3498  }
3499  }
3500  }
3501  }
3502  if (else_expr != nullptr) {
3503  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3504  if (c != nullptr) {
3505  c->add_unique(domain_set);
3506  } else {
3507  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3508  if (v != nullptr) {
3509  v->add_unique(domain_set);
3510  } else {
3511  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3512  if (cast != nullptr && cast->get_optype() == kCAST) {
3513  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3514  if (c != nullptr) {
3515  c->add_unique(domain_set);
3516  } else {
3517  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3518  if (v != nullptr) {
3519  v->add_unique(domain_set);
3520  }
3521  }
3522  } else {
3523  else_expr->get_domain(domain_set);
3524  }
3525  }
3526  }
3527  }
3528 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
Definition: sqldefs.h:48
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295

+ Here is the call graph for this function:

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

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

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

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

References expr_pair_list.

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

1262  {
1263  return expr_pair_list;
1264  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292

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

References else_expr, and expr_pair_list.

1828  {
1829  std::set<int> rte_idx_set;
1830  for (auto p : expr_pair_list) {
1831  p.first->collect_rte_idx(rte_idx_set);
1832  p.second->collect_rte_idx(rte_idx_set);
1833  }
1834  if (else_expr != nullptr) {
1835  else_expr->collect_rte_idx(rte_idx_set);
1836  }
1837  if (rte_idx_set.size() > 1) {
1838  join_predicates.push_back(this);
1839  } else if (rte_idx_set.size() == 1) {
1840  scan_predicates.push_back(this);
1841  } else {
1842  const_predicates.push_back(this);
1843  }
1844 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2474 of file Analyzer.cpp.

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

2474  {
2475  if (typeid(rhs) != typeid(CaseExpr)) {
2476  return false;
2477  }
2478  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2479  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2480  return false;
2481  }
2482  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2483  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2484  return false;
2485  }
2486  auto it = rhs_ce.get_expr_pair_list().cbegin();
2487  for (auto p : expr_pair_list) {
2488  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2489  return false;
2490  }
2491  ++it;
2492  }
2493  return else_expr == nullptr ||
2494  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2495 }
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:1254
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295

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

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

2162  {
2163  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2164  epair_list;
2165  for (auto p : expr_pair_list) {
2166  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2167  p.second->rewrite_agg_to_var(tlist));
2168  }
2169  return makeExpr<CaseExpr>(type_info,
2170  contains_agg,
2171  epair_list,
2172  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2173 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
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 2118 of file Analyzer.cpp.

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

2119  {
2120  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2121  epair_list;
2122  for (auto p : expr_pair_list) {
2123  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2124  p.second->rewrite_with_child_targetlist(tlist));
2125  }
2126  return makeExpr<CaseExpr>(
2127  type_info,
2128  contains_agg,
2129  epair_list,
2130  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2131 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
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 2075 of file Analyzer.cpp.

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

2076  {
2077  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2078  epair_list;
2079  for (auto p : expr_pair_list) {
2080  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2081  p.second->rewrite_with_targetlist(tlist));
2082  }
2083  return makeExpr<CaseExpr>(
2084  type_info,
2085  contains_agg,
2086  epair_list,
2087  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
2088 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2941 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2941  {
2942  std::string str{"CASE "};
2943  for (auto p : expr_pair_list) {
2944  str += "(";
2945  str += p.first->toString();
2946  str += ", ";
2947  str += p.second->toString();
2948  str += ") ";
2949  }
2950  if (else_expr) {
2951  str += "ELSE ";
2952  str += else_expr->toString();
2953  }
2954  str += " END ";
2955  return str;
2956 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1292
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1295

Member Data Documentation


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