OmniSciDB  6686921089
 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 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 1294 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 1296 of file Analyzer.h.

1301  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:68
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

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

1369  {
1370  SQLTypeInfo ti = new_type_info;
1371  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1372  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1376  }
1377 
1378  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1379  new_expr_pair_list;
1380  for (auto& p : expr_pair_list) {
1381  new_expr_pair_list.emplace_back(
1382  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1383  }
1384 
1385  if (else_expr != nullptr) {
1386  else_expr = else_expr->add_cast(ti);
1387  }
1388  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1389  expr_pair_list = new_expr_pair_list;
1390 
1391  type_info = ti;
1392  return shared_from_this();
1393 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
SQLTypeInfo type_info
Definition: Analyzer.h:175
void set_comp_param(int p)
Definition: sqltypes.h:430
#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:509
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:260
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

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

References else_expr, and expr_pair_list.

3258  {
3259  for (auto p : expr_pair_list) {
3260  p.first->check_group_by(groupby);
3261  p.second->check_group_by(groupby);
3262  }
3263  if (else_expr != nullptr) {
3264  else_expr->check_group_by(groupby);
3265  }
3266 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
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 3201 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3203  {
3204  for (auto p : expr_pair_list) {
3205  p.first->collect_column_var(colvar_set, include_agg);
3206  p.second->collect_column_var(colvar_set, include_agg);
3207  }
3208  if (else_expr != nullptr) {
3209  else_expr->collect_column_var(colvar_set, include_agg);
3210  }
3211 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3159 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3159  {
3160  for (auto p : expr_pair_list) {
3161  p.first->collect_rte_idx(rte_idx_set);
3162  p.second->collect_rte_idx(rte_idx_set);
3163  }
3164  if (else_expr != nullptr) {
3165  else_expr->collect_rte_idx(rte_idx_set);
3166  }
3167 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 180 of file Analyzer.cpp.

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

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

Reimplemented from Analyzer::Expr.

Definition at line 3106 of file Analyzer.cpp.

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

3107  {
3108  if (f(this)) {
3109  add_unique(expr_list);
3110  return;
3111  }
3112  for (auto p : expr_pair_list) {
3113  p.first->find_expr(f, expr_list);
3114  p.second->find_expr(f, expr_list);
3115  }
3116  if (else_expr != nullptr) {
3117  else_expr->find_expr(f, expr_list);
3118  }
3119 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2965
char * f
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

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

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

3290  {
3291  for (const auto& p : expr_pair_list) {
3292  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3293  if (c != nullptr) {
3294  c->add_unique(domain_set);
3295  } else {
3296  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3297  if (v != nullptr) {
3298  v->add_unique(domain_set);
3299  } else {
3300  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3301  if (cast != nullptr && cast->get_optype() == kCAST) {
3302  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3303  if (c != nullptr) {
3304  cast->add_unique(domain_set);
3305  continue;
3306  } else {
3307  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3308  if (v != nullptr) {
3309  v->add_unique(domain_set);
3310  continue;
3311  }
3312  }
3313  }
3314  p.second->get_domain(domain_set);
3315  if (domain_set.empty()) {
3316  return;
3317  }
3318  }
3319  }
3320  }
3321  if (else_expr != nullptr) {
3322  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3323  if (c != nullptr) {
3324  c->add_unique(domain_set);
3325  } else {
3326  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3327  if (v != nullptr) {
3328  v->add_unique(domain_set);
3329  } else {
3330  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3331  if (cast != nullptr && cast->get_optype() == kCAST) {
3332  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3333  if (c != nullptr) {
3334  c->add_unique(domain_set);
3335  } else {
3336  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3337  if (v != nullptr) {
3338  v->add_unique(domain_set);
3339  }
3340  }
3341  } else {
3342  else_expr->get_domain(domain_set);
3343  }
3344  }
3345  }
3346  }
3347 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
Definition: sqldefs.h:49
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

+ Here is the call graph for this function:

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

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

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

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

1304  {
1305  return expr_pair_list;
1306  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334

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

References else_expr, and expr_pair_list.

1759  {
1760  std::set<int> rte_idx_set;
1761  for (auto p : expr_pair_list) {
1762  p.first->collect_rte_idx(rte_idx_set);
1763  p.second->collect_rte_idx(rte_idx_set);
1764  }
1765  if (else_expr != nullptr) {
1766  else_expr->collect_rte_idx(rte_idx_set);
1767  }
1768  if (rte_idx_set.size() > 1) {
1769  join_predicates.push_back(this);
1770  } else if (rte_idx_set.size() == 1) {
1771  scan_predicates.push_back(this);
1772  } else {
1773  const_predicates.push_back(this);
1774  }
1775 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2387 of file Analyzer.cpp.

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

2387  {
2388  if (typeid(rhs) != typeid(CaseExpr)) {
2389  return false;
2390  }
2391  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2392  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2393  return false;
2394  }
2395  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2396  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2397  return false;
2398  }
2399  auto it = rhs_ce.get_expr_pair_list().cbegin();
2400  for (auto p : expr_pair_list) {
2401  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2402  return false;
2403  }
2404  ++it;
2405  }
2406  return else_expr == nullptr ||
2407  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2408 }
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:1296
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

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

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

2068  {
2069  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2070  epair_list;
2071  for (auto p : expr_pair_list) {
2072  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2073  p.second->rewrite_agg_to_var(tlist));
2074  }
2075  return makeExpr<CaseExpr>(type_info,
2076  contains_agg,
2077  epair_list,
2078  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2079 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
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 2024 of file Analyzer.cpp.

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

2025  {
2026  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2027  epair_list;
2028  for (auto p : expr_pair_list) {
2029  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2030  p.second->rewrite_with_child_targetlist(tlist));
2031  }
2032  return makeExpr<CaseExpr>(
2033  type_info,
2034  contains_agg,
2035  epair_list,
2036  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2037 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
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 1981 of file Analyzer.cpp.

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

1982  {
1983  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1984  epair_list;
1985  for (auto p : expr_pair_list) {
1986  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1987  p.second->rewrite_with_targetlist(tlist));
1988  }
1989  return makeExpr<CaseExpr>(
1990  type_info,
1991  contains_agg,
1992  epair_list,
1993  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1994 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2828 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2828  {
2829  std::string str{"CASE "};
2830  for (auto p : expr_pair_list) {
2831  str += "(";
2832  str += p.first->toString();
2833  str += ", ";
2834  str += p.second->toString();
2835  str += ") ";
2836  }
2837  if (else_expr) {
2838  str += "ELSE ";
2839  str += else_expr->toString();
2840  }
2841  str += " END ";
2842  return str;
2843 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1334
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1337

Member Data Documentation


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