OmniSciDB  8a228a1076
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::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 1140 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 1142 of file Analyzer.h.

1147  : 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:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

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

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

1306  {
1307  SQLTypeInfo ti = new_type_info;
1308  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1309  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1313  }
1314 
1315  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1316  new_expr_pair_list;
1317  for (auto& p : expr_pair_list) {
1318  new_expr_pair_list.emplace_back(
1319  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1320  }
1321 
1322  if (else_expr != nullptr) {
1323  else_expr = else_expr->add_cast(ti);
1324  }
1325  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1326  expr_pair_list = new_expr_pair_list;
1327 
1328  type_info = ti;
1329  return shared_from_this();
1330 }
bool is_string() const
Definition: sqltypes.h:416
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:268
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:267
SQLTypeInfo type_info
Definition: Analyzer.h:177
void set_comp_param(int p)
Definition: sqltypes.h:360
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:198
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:199
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
+ 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 3063 of file Analyzer.cpp.

3064  {
3065  for (auto p : expr_pair_list) {
3066  p.first->check_group_by(groupby);
3067  p.second->check_group_by(groupby);
3068  }
3069  if (else_expr != nullptr) {
3070  else_expr->check_group_by(groupby);
3071  }
3072 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

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

3027  {
3028  for (auto p : expr_pair_list) {
3029  p.first->collect_column_var(colvar_set, include_agg);
3030  p.second->collect_column_var(colvar_set, include_agg);
3031  }
3032  if (else_expr != nullptr) {
3033  else_expr->collect_column_var(colvar_set, include_agg);
3034  }
3035 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

◆ collect_rte_idx()

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

Reimplemented from Analyzer::Expr.

Definition at line 2997 of file Analyzer.cpp.

2997  {
2998  for (auto p : expr_pair_list) {
2999  p.first->collect_rte_idx(rte_idx_set);
3000  p.second->collect_rte_idx(rte_idx_set);
3001  }
3002  if (else_expr != nullptr) {
3003  else_expr->collect_rte_idx(rte_idx_set);
3004  }
3005 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

◆ deep_copy()

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

Implements Analyzer::Expr.

Definition at line 167 of file Analyzer.cpp.

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

167  {
168  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
169  new_list;
170  for (auto p : expr_pair_list) {
171  new_list.emplace_back(p.first->deep_copy(), p.second->deep_copy());
172  }
173  return makeExpr<CaseExpr>(type_info,
174  contains_agg,
175  new_list,
176  else_expr == nullptr ? nullptr : else_expr->deep_copy());
177 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool contains_agg
Definition: Analyzer.h:178
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

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

References Analyzer::Expr::add_unique().

2945  {
2946  if (f(this)) {
2947  add_unique(expr_list);
2948  return;
2949  }
2950  for (auto p : expr_pair_list) {
2951  p.first->find_expr(f, expr_list);
2952  p.second->find_expr(f, expr_list);
2953  }
2954  if (else_expr != nullptr) {
2955  else_expr->find_expr(f, expr_list);
2956  }
2957 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
virtual void add_unique(std::list< const Expr *> &expr_list) const
Definition: Analyzer.cpp:2815
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
+ 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 3096 of file Analyzer.cpp.

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

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

3096  {
3097  for (const auto& p : expr_pair_list) {
3098  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
3099  if (c != nullptr) {
3100  c->add_unique(domain_set);
3101  } else {
3102  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3103  if (v != nullptr) {
3104  v->add_unique(domain_set);
3105  } else {
3106  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
3107  if (cast != nullptr && cast->get_optype() == kCAST) {
3108  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3109  if (c != nullptr) {
3110  cast->add_unique(domain_set);
3111  continue;
3112  } else {
3113  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
3114  if (v != nullptr) {
3115  v->add_unique(domain_set);
3116  continue;
3117  }
3118  }
3119  }
3120  p.second->get_domain(domain_set);
3121  if (domain_set.empty()) {
3122  return;
3123  }
3124  }
3125  }
3126  }
3127  if (else_expr != nullptr) {
3128  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
3129  if (c != nullptr) {
3130  c->add_unique(domain_set);
3131  } else {
3132  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3133  if (v != nullptr) {
3134  v->add_unique(domain_set);
3135  } else {
3136  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
3137  if (cast != nullptr && cast->get_optype() == kCAST) {
3138  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
3139  if (c != nullptr) {
3140  c->add_unique(domain_set);
3141  } else {
3142  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
3143  if (v != nullptr) {
3144  v->add_unique(domain_set);
3145  }
3146  }
3147  } else {
3148  else_expr->get_domain(domain_set);
3149  }
3150  }
3151  }
3152  }
3153 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
Definition: sqldefs.h:49
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
+ 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 1153 of file Analyzer.h.

References operator==().

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

1153 { return else_expr.get(); }
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
+ 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 1150 of file Analyzer.h.

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

1150  {
1151  return expr_pair_list;
1152  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
+ 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 1680 of file Analyzer.cpp.

1682  {
1683  std::set<int> rte_idx_set;
1684  for (auto p : expr_pair_list) {
1685  p.first->collect_rte_idx(rte_idx_set);
1686  p.second->collect_rte_idx(rte_idx_set);
1687  }
1688  if (else_expr != nullptr) {
1689  else_expr->collect_rte_idx(rte_idx_set);
1690  }
1691  if (rte_idx_set.size() > 1) {
1692  join_predicates.push_back(this);
1693  } else if (rte_idx_set.size() == 1) {
1694  scan_predicates.push_back(this);
1695  } else {
1696  const_predicates.push_back(this);
1697  }
1698 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

◆ operator==()

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

Implements Analyzer::Expr.

Definition at line 2279 of file Analyzer.cpp.

References get_else_expr(), and get_expr_pair_list().

2279  {
2280  if (typeid(rhs) != typeid(CaseExpr)) {
2281  return false;
2282  }
2283  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2284  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2285  return false;
2286  }
2287  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2288  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2289  return false;
2290  }
2291  auto it = rhs_ce.get_expr_pair_list().cbegin();
2292  for (auto p : expr_pair_list) {
2293  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2294  return false;
2295  }
2296  ++it;
2297  }
2298  return else_expr == nullptr ||
2299  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2300 }
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:1142
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183
+ 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 1990 of file Analyzer.cpp.

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

1991  {
1992  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1993  epair_list;
1994  for (auto p : expr_pair_list) {
1995  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
1996  p.second->rewrite_agg_to_var(tlist));
1997  }
1998  return makeExpr<CaseExpr>(type_info,
1999  contains_agg,
2000  epair_list,
2001  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2002 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool contains_agg
Definition: Analyzer.h:178
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

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

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

1948  {
1949  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1950  epair_list;
1951  for (auto p : expr_pair_list) {
1952  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
1953  p.second->rewrite_with_child_targetlist(tlist));
1954  }
1955  return makeExpr<CaseExpr>(
1956  type_info,
1957  contains_agg,
1958  epair_list,
1959  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
1960 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool contains_agg
Definition: Analyzer.h:178
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

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

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

1905  {
1906  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1907  epair_list;
1908  for (auto p : expr_pair_list) {
1909  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1910  p.second->rewrite_with_targetlist(tlist));
1911  }
1912  return makeExpr<CaseExpr>(
1913  type_info,
1914  contains_agg,
1915  epair_list,
1916  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1917 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
SQLTypeInfo type_info
Definition: Analyzer.h:177
bool contains_agg
Definition: Analyzer.h:178
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

◆ toString()

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

Implements Analyzer::Expr.

Definition at line 2678 of file Analyzer.cpp.

2678  {
2679  std::string str{"CASE "};
2680  for (auto p : expr_pair_list) {
2681  str += "(";
2682  str += p.first->toString();
2683  str += ", ";
2684  str += p.second->toString();
2685  str += ") ";
2686  }
2687  if (else_expr) {
2688  str += "ELSE ";
2689  str += else_expr->toString();
2690  }
2691  str += " END ";
2692  return str;
2693 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1180
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1183

Member Data Documentation

◆ else_expr

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

Definition at line 1183 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 1180 of file Analyzer.h.


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