OmniSciDB  a5dc49c757
 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 1374 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 1376 of file Analyzer.h.

1381  : 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:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417

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 1460 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(), SQLTypeInfo::setStringDictKey(), TRANSIENT_DICT, TRANSIENT_DICT_ID, and Analyzer::Expr::type_info.

1460  {
1461  SQLTypeInfo ti = new_type_info;
1462  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1463  new_type_info.getStringDictKey().isTransientDict() && type_info.is_string() &&
1467  auto dict_key = type_info.getStringDictKey();
1468  dict_key.dict_id = TRANSIENT_DICT(dict_key.dict_id);
1469  ti.setStringDictKey(dict_key);
1470  }
1471 
1472  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1473  new_expr_pair_list;
1474  for (auto& p : expr_pair_list) {
1475  new_expr_pair_list.emplace_back(
1476  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1477  }
1478 
1479  if (else_expr != nullptr) {
1480  else_expr = else_expr->add_cast(ti);
1481  }
1482  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1483  expr_pair_list = new_expr_pair_list;
1484 
1485  type_info = ti;
1486  return shared_from_this();
1487 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
#define TRANSIENT_DICT_ID
Definition: DbObjectKeys.h:24
SQLTypeInfo type_info
Definition: Analyzer.h:180
void set_comp_param(int p)
Definition: sqltypes.h:482
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
void setStringDictKey(const shared::StringDictKey &dict_key)
Definition: sqltypes.h:1063
bool isTransientDict() const
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:402
bool is_string() const
Definition: sqltypes.h:561
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:322
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
const shared::StringDictKey & getStringDictKey() const
Definition: sqltypes.h:1057

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

References else_expr, and expr_pair_list.

3593  {
3594  for (auto p : expr_pair_list) {
3595  p.first->check_group_by(groupby);
3596  p.second->check_group_by(groupby);
3597  }
3598  if (else_expr != nullptr) {
3599  else_expr->check_group_by(groupby);
3600  }
3601 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
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 3528 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3530  {
3531  for (auto p : expr_pair_list) {
3532  p.first->collect_column_var(colvar_set, include_agg);
3533  p.second->collect_column_var(colvar_set, include_agg);
3534  }
3535  if (else_expr != nullptr) {
3536  else_expr->collect_column_var(colvar_set, include_agg);
3537  }
3538 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3480 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3480  {
3481  for (auto p : expr_pair_list) {
3482  p.first->collect_rte_idx(rte_idx_set);
3483  p.second->collect_rte_idx(rte_idx_set);
3484  }
3485  if (else_expr != nullptr) {
3486  else_expr->collect_rte_idx(rte_idx_set);
3487  }
3488 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 199 of file Analyzer.cpp.

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

199  {
200  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
201  new_list;
202  for (auto p : expr_pair_list) {
203  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
204  }
205  return makeExpr<CaseExpr>(type_info,
206  contains_agg,
207  new_list,
208  else_expr == nullptr ? nullptr : else_expr->deep_copy());
209 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
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 3416 of file Analyzer.cpp.

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

3417  {
3418  if (f(this)) {
3419  add_unique(expr_list);
3420  return;
3421  }
3422  for (auto p : expr_pair_list) {
3423  p.first->find_expr(f, expr_list);
3424  p.second->find_expr(f, expr_list);
3425  }
3426  if (else_expr != nullptr) {
3427  else_expr->find_expr(f, expr_list);
3428  }
3429 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3248
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417

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

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

3625  {
3626  for (const auto& p : expr_pair_list) {
3627  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3628  if (c != nullptr) {
3629  c->add_unique(domain_set);
3630  } else {
3631  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3632  if (v != nullptr) {
3633  v->add_unique(domain_set);
3634  } else {
3635  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3636  if (cast != nullptr && cast->get_optype() == kCAST) {
3637  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3638  if (c != nullptr) {
3639  cast->add_unique(domain_set);
3640  continue;
3641  } else {
3642  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3643  if (v != nullptr) {
3644  v->add_unique(domain_set);
3645  continue;
3646  }
3647  }
3648  }
3649  p.second->get_domain(domain_set);
3650  if (domain_set.empty()) {
3651  return;
3652  }
3653  }
3654  }
3655  }
3656  if (else_expr != nullptr) {
3657  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3658  if (c != nullptr) {
3659  c->add_unique(domain_set);
3660  } else {
3661  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3662  if (v != nullptr) {
3663  v->add_unique(domain_set);
3664  } else {
3665  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3666  if (cast != nullptr && cast->get_optype() == kCAST) {
3667  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3668  if (c != nullptr) {
3669  c->add_unique(domain_set);
3670  } else {
3671  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3672  if (v != nullptr) {
3673  v->add_unique(domain_set);
3674  }
3675  }
3676  } else {
3677  else_expr->get_domain(domain_set);
3678  }
3679  }
3680  }
3681  }
3682 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
Definition: sqldefs.h:51
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417

+ Here is the call graph for this function:

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

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

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

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

1384  {
1385  return expr_pair_list;
1386  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414

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

References else_expr, and expr_pair_list.

1887  {
1888  std::set<int> rte_idx_set;
1889  for (auto p : expr_pair_list) {
1890  p.first->collect_rte_idx(rte_idx_set);
1891  p.second->collect_rte_idx(rte_idx_set);
1892  }
1893  if (else_expr != nullptr) {
1894  else_expr->collect_rte_idx(rte_idx_set);
1895  }
1896  if (rte_idx_set.size() > 1) {
1897  join_predicates.push_back(this);
1898  } else if (rte_idx_set.size() == 1) {
1899  scan_predicates.push_back(this);
1900  } else {
1901  const_predicates.push_back(this);
1902  }
1903 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2577 of file Analyzer.cpp.

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

2577  {
2578  if (typeid(rhs) != typeid(CaseExpr)) {
2579  return false;
2580  }
2581  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2582  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2583  return false;
2584  }
2585  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2586  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2587  return false;
2588  }
2589  auto it = rhs_ce.get_expr_pair_list().cbegin();
2590  for (auto p : expr_pair_list) {
2591  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2592  return false;
2593  }
2594  ++it;
2595  }
2596  return else_expr == nullptr ||
2597  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2598 }
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:1376
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417

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

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

2221  {
2222  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2223  epair_list;
2224  for (auto p : expr_pair_list) {
2225  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
2226  p.second->rewrite_agg_to_var(tlist));
2227  }
2228  return makeExpr<CaseExpr>(type_info,
2229  contains_agg,
2230  epair_list,
2231  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2232 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
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 2177 of file Analyzer.cpp.

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

2178  {
2179  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2180  epair_list;
2181  for (auto p : expr_pair_list) {
2182  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
2183  p.second->rewrite_with_child_targetlist(tlist));
2184  }
2185  return makeExpr<CaseExpr>(
2186  type_info,
2187  contains_agg,
2188  epair_list,
2189  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
2190 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
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 2134 of file Analyzer.cpp.

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

2135  {
2136  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
2137  epair_list;
2138  for (auto p : expr_pair_list) {
2139  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
2140  p.second->rewrite_with_targetlist(tlist));
2141  }
2142  return makeExpr<CaseExpr>(
2143  type_info,
2144  contains_agg,
2145  epair_list,
2146  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
2147 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
SQLTypeInfo type_info
Definition: Analyzer.h:180
bool contains_agg
Definition: Analyzer.h:181
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 3070 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3070  {
3071  std::string str{"CASE "};
3072  for (auto p : expr_pair_list) {
3073  str += "(";
3074  str += p.first->toString();
3075  str += ", ";
3076  str += p.second->toString();
3077  str += ") ";
3078  }
3079  if (else_expr) {
3080  str += "ELSE ";
3081  str += else_expr->toString();
3082  }
3083  str += " END ";
3084  return str;
3085 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1414
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1417

Member Data Documentation


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