OmniSciDB  c07336695a
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 ()
 
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::Exprnormalize_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 1031 of file Analyzer.h.

Constructor & Destructor Documentation

◆ CaseExpr()

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

1038  : 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:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

Member Function Documentation

◆ add_cast()

std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::add_cast ( const SQLTypeInfo new_type_info)
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1223 of file Analyzer.cpp.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_comp_param(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_compression(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_string(), kENCODING_DICT, kENCODING_NONE, SQLTypeInfoCore< TYPE_FACET_PACK >::set_comp_param(), TRANSIENT_DICT, TRANSIENT_DICT_ID, and Analyzer::Expr::type_info.

1223  {
1224  SQLTypeInfo ti = new_type_info;
1225  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1226  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1230  }
1231 
1232  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1233  new_expr_pair_list;
1234  for (auto& p : expr_pair_list) {
1235  new_expr_pair_list.emplace_back(
1236  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1237  }
1238 
1239  if (else_expr != nullptr) {
1240  else_expr = else_expr->add_cast(ti);
1241  }
1242  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1243  expr_pair_list = new_expr_pair_list;
1244 
1245  type_info = ti;
1246  return shared_from_this();
1247 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:327
SQLTypeInfo type_info
Definition: Analyzer.h:175
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:187
void set_comp_param(int p)
Definition: sqltypes.h:420
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:328
bool is_string() const
Definition: sqltypes.h:446
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:188
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074
+ Here is the call graph for this function:

◆ check_group_by()

void Analyzer::CaseExpr::check_group_by ( const std::list< std::shared_ptr< Analyzer::Expr >> &  groupby) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2815 of file Analyzer.cpp.

2816  {
2817  for (auto p : expr_pair_list) {
2818  p.first->check_group_by(groupby);
2819  p.second->check_group_by(groupby);
2820  }
2821  if (else_expr != nullptr) {
2822  else_expr->check_group_by(groupby);
2823  }
2824 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ collect_column_var()

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

2779  {
2780  for (auto p : expr_pair_list) {
2781  p.first->collect_column_var(colvar_set, include_agg);
2782  p.second->collect_column_var(colvar_set, include_agg);
2783  }
2784  if (else_expr != nullptr) {
2785  else_expr->collect_column_var(colvar_set, include_agg);
2786  }
2787 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ collect_rte_idx()

void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2749 of file Analyzer.cpp.

2749  {
2750  for (auto p : expr_pair_list) {
2751  p.first->collect_rte_idx(rte_idx_set);
2752  p.second->collect_rte_idx(rte_idx_set);
2753  }
2754  if (else_expr != nullptr) {
2755  else_expr->collect_rte_idx(rte_idx_set);
2756  }
2757 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ deep_copy()

std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 159 of file Analyzer.cpp.

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

159  {
160  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
161  new_list;
162  for (auto p : expr_pair_list) {
163  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
164  }
165  return makeExpr<CaseExpr>(type_info,
166  contains_agg,
167  new_list,
168  else_expr == nullptr ? nullptr : else_expr->deep_copy());
169 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ find_expr()

void Analyzer::CaseExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr *> &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2696 of file Analyzer.cpp.

References Analyzer::Expr::add_unique().

2697  {
2698  if (f(this)) {
2699  add_unique(expr_list);
2700  return;
2701  }
2702  for (auto p : expr_pair_list) {
2703  p.first->find_expr(f, expr_list);
2704  p.second->find_expr(f, expr_list);
2705  }
2706  if (else_expr != nullptr) {
2707  else_expr->find_expr(f, expr_list);
2708  }
2709 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
virtual void add_unique(std::list< const Expr *> &expr_list) const
Definition: Analyzer.cpp:2585
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074
+ Here is the call graph for this function:

◆ get_domain()

void Analyzer::CaseExpr::get_domain ( DomainSet domain_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2848 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), anonymous_namespace{ExecuteTest.cpp}::c(), kCAST, and v().

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

2848  {
2849  for (const auto& p : expr_pair_list) {
2850  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
2851  if (c != nullptr) {
2852  c->add_unique(domain_set);
2853  } else {
2854  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2855  if (v != nullptr) {
2856  v->add_unique(domain_set);
2857  } else {
2858  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
2859  if (cast != nullptr && cast->get_optype() == kCAST) {
2860  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2861  if (c != nullptr) {
2862  cast->add_unique(domain_set);
2863  continue;
2864  } else {
2865  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2866  if (v != nullptr) {
2867  v->add_unique(domain_set);
2868  continue;
2869  }
2870  }
2871  }
2872  p.second->get_domain(domain_set);
2873  if (domain_set.empty()) {
2874  return;
2875  }
2876  }
2877  }
2878  }
2879  if (else_expr != nullptr) {
2880  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
2881  if (c != nullptr) {
2882  c->add_unique(domain_set);
2883  } else {
2884  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2885  if (v != nullptr) {
2886  v->add_unique(domain_set);
2887  } else {
2888  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
2889  if (cast != nullptr && cast->get_optype() == kCAST) {
2890  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2891  if (c != nullptr) {
2892  c->add_unique(domain_set);
2893  } else {
2894  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2895  if (v != nullptr) {
2896  v->add_unique(domain_set);
2897  }
2898  }
2899  } else {
2900  else_expr->get_domain(domain_set);
2901  }
2902  }
2903  }
2904  }
2905 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
void c(const std::string &query_string, const ExecutorDeviceType device_type)
Definition: sqldefs.h:49
T v(const TargetValue &r)
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_else_expr()

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

Definition at line 1044 of file Analyzer.h.

References operator==().

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenCase(), getExpressionRange(), anonymous_namespace{WindowExpressionRewrite.cpp}::matches_else_null(), operator==(), DeepCopyVisitor::visitCaseExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitCaseExpr().

1044 { return else_expr.get(); }
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_expr_pair_list()

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

Referenced by CodeGenerator::codegenCase(), getExpressionRange(), operator==(), rewrite_sum_window(), DeepCopyVisitor::visitCaseExpr(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitCaseExpr().

1041  {
1042  return expr_pair_list;
1043  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
+ Here is the caller graph for this function:

◆ group_predicates()

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

1571  {
1572  std::set<int> rte_idx_set;
1573  for (auto p : expr_pair_list) {
1574  p.first->collect_rte_idx(rte_idx_set);
1575  p.second->collect_rte_idx(rte_idx_set);
1576  }
1577  if (else_expr != nullptr) {
1578  else_expr->collect_rte_idx(rte_idx_set);
1579  }
1580  if (rte_idx_set.size() > 1) {
1581  join_predicates.push_back(this);
1582  } else if (rte_idx_set.size() == 1) {
1583  scan_predicates.push_back(this);
1584  } else {
1585  const_predicates.push_back(this);
1586  }
1587 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ operator==()

bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2149 of file Analyzer.cpp.

References get_else_expr(), and get_expr_pair_list().

2149  {
2150  if (typeid(rhs) != typeid(CaseExpr)) {
2151  return false;
2152  }
2153  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2154  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2155  return false;
2156  }
2157  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2158  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2159  return false;
2160  }
2161  auto it = rhs_ce.get_expr_pair_list().cbegin();
2162  for (auto p : expr_pair_list) {
2163  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2164  return false;
2165  }
2166  ++it;
2167  }
2168  return else_expr == nullptr ||
2169  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2170 }
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:1033
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074
+ Here is the call graph for this function:

◆ rewrite_agg_to_var()

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

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

1880  {
1881  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1882  epair_list;
1883  for (auto p : expr_pair_list) {
1884  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
1885  p.second->rewrite_agg_to_var(tlist));
1886  }
1887  return makeExpr<CaseExpr>(type_info,
1888  contains_agg,
1889  epair_list,
1890  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
1891 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ rewrite_with_child_targetlist()

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

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

1837  {
1838  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1839  epair_list;
1840  for (auto p : expr_pair_list) {
1841  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
1842  p.second->rewrite_with_child_targetlist(tlist));
1843  }
1844  return makeExpr<CaseExpr>(
1845  type_info,
1846  contains_agg,
1847  epair_list,
1848  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
1849 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ rewrite_with_targetlist()

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

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

1794  {
1795  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1796  epair_list;
1797  for (auto p : expr_pair_list) {
1798  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1799  p.second->rewrite_with_targetlist(tlist));
1800  }
1801  return makeExpr<CaseExpr>(
1802  type_info,
1803  contains_agg,
1804  epair_list,
1805  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1806 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
SQLTypeInfo type_info
Definition: Analyzer.h:175
bool contains_agg
Definition: Analyzer.h:176
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

◆ toString()

std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2501 of file Analyzer.cpp.

2501  {
2502  std::string str{"CASE "};
2503  for (auto p : expr_pair_list) {
2504  str += "(";
2505  str += p.first->toString();
2506  str += ", ";
2507  str += p.second->toString();
2508  str += ") ";
2509  }
2510  if (else_expr) {
2511  str += "ELSE ";
2512  str += else_expr->toString();
2513  }
2514  str += " END ";
2515  return str;
2516 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1071
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1074

Member Data Documentation

◆ else_expr

std::shared_ptr<Analyzer::Expr> Analyzer::CaseExpr::else_expr
private

Definition at line 1074 of file Analyzer.h.

◆ expr_pair_list

std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr> > > Analyzer::CaseExpr::expr_pair_list
private

Definition at line 1071 of file Analyzer.h.


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