OmniSciDB  c0231cc57d
 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 1247 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 1249 of file Analyzer.h.

1254  : Expr(ti, has_agg), expr_pair_list(w), else_expr(e) {}
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:73
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

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

1404  {
1405  SQLTypeInfo ti = new_type_info;
1406  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1407  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1411  }
1412 
1413  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1414  new_expr_pair_list;
1415  for (auto& p : expr_pair_list) {
1416  new_expr_pair_list.emplace_back(
1417  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1418  }
1419 
1420  if (else_expr != nullptr) {
1421  else_expr = else_expr->add_cast(ti);
1422  }
1423  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1424  expr_pair_list = new_expr_pair_list;
1425 
1426  type_info = ti;
1427  return shared_from_this();
1428 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
SQLTypeInfo type_info
Definition: Analyzer.h:183
void set_comp_param(int p)
Definition: sqltypes.h:526
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:334
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:412
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:413
bool is_string() const
Definition: sqltypes.h:600
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:335
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

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

References else_expr, and expr_pair_list.

3382  {
3383  for (auto p : expr_pair_list) {
3384  p.first->check_group_by(groupby);
3385  p.second->check_group_by(groupby);
3386  }
3387  if (else_expr != nullptr) {
3388  else_expr->check_group_by(groupby);
3389  }
3390 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
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 3317 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3319  {
3320  for (auto p : expr_pair_list) {
3321  p.first->collect_column_var(colvar_set, include_agg);
3322  p.second->collect_column_var(colvar_set, include_agg);
3323  }
3324  if (else_expr != nullptr) {
3325  else_expr->collect_column_var(colvar_set, include_agg);
3326  }
3327 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3269 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3269  {
3270  for (auto p : expr_pair_list) {
3271  p.first->collect_rte_idx(rte_idx_set);
3272  p.second->collect_rte_idx(rte_idx_set);
3273  }
3274  if (else_expr != nullptr) {
3275  else_expr->collect_rte_idx(rte_idx_set);
3276  }
3277 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
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:1287
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool contains_agg
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
void Analyzer::CaseExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3216 of file Analyzer.cpp.

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

3217  {
3218  if (f(this)) {
3219  add_unique(expr_list);
3220  return;
3221  }
3222  for (auto p : expr_pair_list) {
3223  p.first->find_expr(f, expr_list);
3224  p.second->find_expr(f, expr_list);
3225  }
3226  if (else_expr != nullptr) {
3227  else_expr->find_expr(f, expr_list);
3228  }
3229 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3073
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

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

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

3414  {
3415  for (const auto& p : expr_pair_list) {
3416  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3417  if (c != nullptr) {
3418  c->add_unique(domain_set);
3419  } else {
3420  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3421  if (v != nullptr) {
3422  v->add_unique(domain_set);
3423  } else {
3424  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3425  if (cast != nullptr && cast->get_optype() == kCAST) {
3426  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3427  if (c != nullptr) {
3428  cast->add_unique(domain_set);
3429  continue;
3430  } else {
3431  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3432  if (v != nullptr) {
3433  v->add_unique(domain_set);
3434  continue;
3435  }
3436  }
3437  }
3438  p.second->get_domain(domain_set);
3439  if (domain_set.empty()) {
3440  return;
3441  }
3442  }
3443  }
3444  }
3445  if (else_expr != nullptr) {
3446  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3447  if (c != nullptr) {
3448  c->add_unique(domain_set);
3449  } else {
3450  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3451  if (v != nullptr) {
3452  v->add_unique(domain_set);
3453  } else {
3454  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3455  if (cast != nullptr && cast->get_optype() == kCAST) {
3456  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3457  if (c != nullptr) {
3458  c->add_unique(domain_set);
3459  } else {
3460  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3461  if (v != nullptr) {
3462  v->add_unique(domain_set);
3463  }
3464  }
3465  } else {
3466  else_expr->get_domain(domain_set);
3467  }
3468  }
3469  }
3470  }
3471 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
Definition: sqldefs.h:48
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

+ Here is the call graph for this function:

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

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

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

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

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

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

References else_expr, and expr_pair_list.

1796  {
1797  std::set<int> rte_idx_set;
1798  for (auto p : expr_pair_list) {
1799  p.first->collect_rte_idx(rte_idx_set);
1800  p.second->collect_rte_idx(rte_idx_set);
1801  }
1802  if (else_expr != nullptr) {
1803  else_expr->collect_rte_idx(rte_idx_set);
1804  }
1805  if (rte_idx_set.size() > 1) {
1806  join_predicates.push_back(this);
1807  } else if (rte_idx_set.size() == 1) {
1808  scan_predicates.push_back(this);
1809  } else {
1810  const_predicates.push_back(this);
1811  }
1812 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2445 of file Analyzer.cpp.

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

2445  {
2446  if (typeid(rhs) != typeid(CaseExpr)) {
2447  return false;
2448  }
2449  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2450  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2451  return false;
2452  }
2453  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2454  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2455  return false;
2456  }
2457  auto it = rhs_ce.get_expr_pair_list().cbegin();
2458  for (auto p : expr_pair_list) {
2459  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2460  return false;
2461  }
2462  ++it;
2463  }
2464  return else_expr == nullptr ||
2465  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2466 }
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:1249
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

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

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

2132  {
2133  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2134  epair_list;
2135  for (auto p : expr_pair_list) {
2136  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2137  p.second->rewrite_agg_to_var(tlist));
2138  }
2139  return makeExpr<CaseExpr>(type_info,
2140  contains_agg,
2141  epair_list,
2142  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2143 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool contains_agg
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
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 2088 of file Analyzer.cpp.

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

2089  {
2090  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2091  epair_list;
2092  for (auto p : expr_pair_list) {
2093  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2094  p.second->rewrite_with_child_targetlist(tlist));
2095  }
2096  return makeExpr<CaseExpr>(
2097  type_info,
2098  contains_agg,
2099  epair_list,
2100  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2101 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool contains_agg
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
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 2045 of file Analyzer.cpp.

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

2046  {
2047  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2048  epair_list;
2049  for (auto p : expr_pair_list) {
2050  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2051  p.second->rewrite_with_targetlist(tlist));
2052  }
2053  return makeExpr<CaseExpr>(
2054  type_info,
2055  contains_agg,
2056  epair_list,
2057  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
2058 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
SQLTypeInfo type_info
Definition: Analyzer.h:183
bool contains_agg
Definition: Analyzer.h:184
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2898 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2898  {
2899  std::string str{"CASE "};
2900  for (auto p : expr_pair_list) {
2901  str += "(";
2902  str += p.first->toString();
2903  str += ", ";
2904  str += p.second->toString();
2905  str += ") ";
2906  }
2907  if (else_expr) {
2908  str += "ELSE ";
2909  str += else_expr->toString();
2910  }
2911  str += " END ";
2912  return str;
2913 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1287
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1290

Member Data Documentation


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