OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 1139 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 1141 of file Analyzer.h.

1146  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:69
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

1359  {
1360  SQLTypeInfo ti = new_type_info;
1361  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1362  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1366  }
1367 
1368  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1369  new_expr_pair_list;
1370  for (auto& p : expr_pair_list) {
1371  new_expr_pair_list.emplace_back(
1372  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1373  }
1374 
1375  if (else_expr != nullptr) {
1376  else_expr = else_expr->add_cast(ti);
1377  }
1378  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1379  expr_pair_list = new_expr_pair_list;
1380 
1381  type_info = ti;
1382  return shared_from_this();
1383 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
void set_comp_param(int p)
Definition: sqltypes.h:415
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:253
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:322
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:323
bool is_string() const
Definition: sqltypes.h:489
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:254
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

References else_expr, and expr_pair_list.

3135  {
3136  for (auto p : expr_pair_list) {
3137  p.first->check_group_by(groupby);
3138  p.second->check_group_by(groupby);
3139  }
3140  if (else_expr != nullptr) {
3141  else_expr->check_group_by(groupby);
3142  }
3143 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 3087 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3089  {
3090  for (auto p : expr_pair_list) {
3091  p.first->collect_column_var(colvar_set, include_agg);
3092  p.second->collect_column_var(colvar_set, include_agg);
3093  }
3094  if (else_expr != nullptr) {
3095  else_expr->collect_column_var(colvar_set, include_agg);
3096  }
3097 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3052 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3052  {
3053  for (auto p : expr_pair_list) {
3054  p.first->collect_rte_idx(rte_idx_set);
3055  p.second->collect_rte_idx(rte_idx_set);
3056  }
3057  if (else_expr != nullptr) {
3058  else_expr->collect_rte_idx(rte_idx_set);
3059  }
3060 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 168 of file Analyzer.cpp.

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

168  {
169  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
170  new_list;
171  for (auto p : expr_pair_list) {
172  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
173  }
174  return makeExpr<CaseExpr>(type_info,
175  contains_agg,
176  new_list,
177  else_expr == nullptr ? nullptr : else_expr->deep_copy());
178 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
void Analyzer::CaseExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2999 of file Analyzer.cpp.

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

3000  {
3001  if (f(this)) {
3002  add_unique(expr_list);
3003  return;
3004  }
3005  for (auto p : expr_pair_list) {
3006  p.first->find_expr(f, expr_list);
3007  p.second->find_expr(f, expr_list);
3008  }
3009  if (else_expr != nullptr) {
3010  else_expr->find_expr(f, expr_list);
3011  }
3012 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2870
char * f
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

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

Referenced by anonymous_namespace{Execute.cpp}::add_transient_string_literals_for_expression().

3167  {
3168  for (const auto& p : expr_pair_list) {
3169  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3170  if (c != nullptr) {
3171  c->add_unique(domain_set);
3172  } else {
3173  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3174  if (v != nullptr) {
3175  v->add_unique(domain_set);
3176  } else {
3177  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3178  if (cast != nullptr && cast->get_optype() == kCAST) {
3179  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3180  if (c != nullptr) {
3181  cast->add_unique(domain_set);
3182  continue;
3183  } else {
3184  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3185  if (v != nullptr) {
3186  v->add_unique(domain_set);
3187  continue;
3188  }
3189  }
3190  }
3191  p.second->get_domain(domain_set);
3192  if (domain_set.empty()) {
3193  return;
3194  }
3195  }
3196  }
3197  }
3198  if (else_expr != nullptr) {
3199  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3200  if (c != nullptr) {
3201  c->add_unique(domain_set);
3202  } else {
3203  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3204  if (v != nullptr) {
3205  v->add_unique(domain_set);
3206  } else {
3207  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3208  if (cast != nullptr && cast->get_optype() == kCAST) {
3209  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3210  if (c != nullptr) {
3211  c->add_unique(domain_set);
3212  } else {
3213  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3214  if (v != nullptr) {
3215  v->add_unique(domain_set);
3216  }
3217  }
3218  } else {
3219  else_expr->get_domain(domain_set);
3220  }
3221  }
3222  }
3223  }
3224 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
Definition: sqldefs.h:49
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

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

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

1149  {
1150  return expr_pair_list;
1151  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179

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

References else_expr, and expr_pair_list.

1735  {
1736  std::set<int> rte_idx_set;
1737  for (auto p : expr_pair_list) {
1738  p.first->collect_rte_idx(rte_idx_set);
1739  p.second->collect_rte_idx(rte_idx_set);
1740  }
1741  if (else_expr != nullptr) {
1742  else_expr->collect_rte_idx(rte_idx_set);
1743  }
1744  if (rte_idx_set.size() > 1) {
1745  join_predicates.push_back(this);
1746  } else if (rte_idx_set.size() == 1) {
1747  scan_predicates.push_back(this);
1748  } else {
1749  const_predicates.push_back(this);
1750  }
1751 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2332 of file Analyzer.cpp.

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

2332  {
2333  if (typeid(rhs) != typeid(CaseExpr)) {
2334  return false;
2335  }
2336  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2337  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2338  return false;
2339  }
2340  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2341  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2342  return false;
2343  }
2344  auto it = rhs_ce.get_expr_pair_list().cbegin();
2345  for (auto p : expr_pair_list) {
2346  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2347  return false;
2348  }
2349  ++it;
2350  }
2351  return else_expr == nullptr ||
2352  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2353 }
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:1141
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

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

2044  {
2045  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2046  epair_list;
2047  for (auto p : expr_pair_list) {
2048  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2049  p.second->rewrite_agg_to_var(tlist));
2050  }
2051  return makeExpr<CaseExpr>(type_info,
2052  contains_agg,
2053  epair_list,
2054  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2055 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 2000 of file Analyzer.cpp.

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

2001  {
2002  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2003  epair_list;
2004  for (auto p : expr_pair_list) {
2005  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2006  p.second->rewrite_with_child_targetlist(tlist));
2007  }
2008  return makeExpr<CaseExpr>(
2009  type_info,
2010  contains_agg,
2011  epair_list,
2012  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2013 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 1957 of file Analyzer.cpp.

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

1958  {
1959  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1960  epair_list;
1961  for (auto p : expr_pair_list) {
1962  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1963  p.second->rewrite_with_targetlist(tlist));
1964  }
1965  return makeExpr<CaseExpr>(
1966  type_info,
1967  contains_agg,
1968  epair_list,
1969  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1970 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2733 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2733  {
2734  std::string str{"CASE "};
2735  for (auto p : expr_pair_list) {
2736  str += "(";
2737  str += p.first->toString();
2738  str += ", ";
2739  str += p.second->toString();
2740  str += ") ";
2741  }
2742  if (else_expr) {
2743  str += "ELSE ";
2744  str += else_expr->toString();
2745  }
2746  str += " END ";
2747  return str;
2748 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

Member Data Documentation


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