OmniSciDB  1dac507f6e
 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 1088 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 1090 of file Analyzer.h.

1095  : 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:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

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

References else_expr, expr_pair_list, 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.

1231  {
1232  SQLTypeInfo ti = new_type_info;
1233  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1234  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1238  }
1239 
1240  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1241  new_expr_pair_list;
1242  for (auto& p : expr_pair_list) {
1243  new_expr_pair_list.emplace_back(
1244  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1245  }
1246 
1247  if (else_expr != nullptr) {
1248  else_expr = else_expr->add_cast(ti);
1249  }
1250  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1251  expr_pair_list = new_expr_pair_list;
1252 
1253  type_info = ti;
1254  return shared_from_this();
1255 }
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:334
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:335
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
SQLTypeInfo type_info
Definition: Analyzer.h:176
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:189
void set_comp_param(int p)
Definition: sqltypes.h:427
bool is_string() const
Definition: sqltypes.h:477
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:190
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

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

References else_expr, and expr_pair_list.

2879  {
2880  for (auto p : expr_pair_list) {
2881  p.first->check_group_by(groupby);
2882  p.second->check_group_by(groupby);
2883  }
2884  if (else_expr != nullptr) {
2885  else_expr->check_group_by(groupby);
2886  }
2887 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
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 2840 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2842  {
2843  for (auto p : expr_pair_list) {
2844  p.first->collect_column_var(colvar_set, include_agg);
2845  p.second->collect_column_var(colvar_set, include_agg);
2846  }
2847  if (else_expr != nullptr) {
2848  else_expr->collect_column_var(colvar_set, include_agg);
2849  }
2850 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2812 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2812  {
2813  for (auto p : expr_pair_list) {
2814  p.first->collect_rte_idx(rte_idx_set);
2815  p.second->collect_rte_idx(rte_idx_set);
2816  }
2817  if (else_expr != nullptr) {
2818  else_expr->collect_rte_idx(rte_idx_set);
2819  }
2820 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 163 of file Analyzer.cpp.

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

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

Reimplemented from Analyzer::Expr.

Definition at line 2759 of file Analyzer.cpp.

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

2760  {
2761  if (f(this)) {
2762  add_unique(expr_list);
2763  return;
2764  }
2765  for (auto p : expr_pair_list) {
2766  p.first->find_expr(f, expr_list);
2767  p.second->find_expr(f, expr_list);
2768  }
2769  if (else_expr != nullptr) {
2770  else_expr->find_expr(f, expr_list);
2771  }
2772 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2639
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

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

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

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

2911  {
2912  for (const auto& p : expr_pair_list) {
2913  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
2914  if (c != nullptr) {
2915  c->add_unique(domain_set);
2916  } else {
2917  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2918  if (v != nullptr) {
2919  v->add_unique(domain_set);
2920  } else {
2921  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
2922  if (cast != nullptr && cast->get_optype() == kCAST) {
2923  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2924  if (c != nullptr) {
2925  cast->add_unique(domain_set);
2926  continue;
2927  } else {
2928  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2929  if (v != nullptr) {
2930  v->add_unique(domain_set);
2931  continue;
2932  }
2933  }
2934  }
2935  p.second->get_domain(domain_set);
2936  if (domain_set.empty()) {
2937  return;
2938  }
2939  }
2940  }
2941  }
2942  if (else_expr != nullptr) {
2943  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
2944  if (c != nullptr) {
2945  c->add_unique(domain_set);
2946  } else {
2947  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2948  if (v != nullptr) {
2949  v->add_unique(domain_set);
2950  } else {
2951  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
2952  if (cast != nullptr && cast->get_optype() == kCAST) {
2953  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2954  if (c != nullptr) {
2955  c->add_unique(domain_set);
2956  } else {
2957  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2958  if (v != nullptr) {
2959  v->add_unique(domain_set);
2960  }
2961  }
2962  } else {
2963  else_expr->get_domain(domain_set);
2964  }
2965  }
2966  }
2967  }
2968 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
Definition: sqldefs.h:49
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

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

References else_expr.

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

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

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

References expr_pair_list.

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

1098  {
1099  return expr_pair_list;
1100  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128

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

References else_expr, and expr_pair_list.

1593  {
1594  std::set<int> rte_idx_set;
1595  for (auto p : expr_pair_list) {
1596  p.first->collect_rte_idx(rte_idx_set);
1597  p.second->collect_rte_idx(rte_idx_set);
1598  }
1599  if (else_expr != nullptr) {
1600  else_expr->collect_rte_idx(rte_idx_set);
1601  }
1602  if (rte_idx_set.size() > 1) {
1603  join_predicates.push_back(this);
1604  } else if (rte_idx_set.size() == 1) {
1605  scan_predicates.push_back(this);
1606  } else {
1607  const_predicates.push_back(this);
1608  }
1609 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
bool Analyzer::CaseExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2179 of file Analyzer.cpp.

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

2179  {
2180  if (typeid(rhs) != typeid(CaseExpr)) {
2181  return false;
2182  }
2183  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2184  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2185  return false;
2186  }
2187  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2188  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2189  return false;
2190  }
2191  auto it = rhs_ce.get_expr_pair_list().cbegin();
2192  for (auto p : expr_pair_list) {
2193  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2194  return false;
2195  }
2196  ++it;
2197  }
2198  return else_expr == nullptr ||
2199  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2200 }
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:1090
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

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

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

1902  {
1903  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1904  epair_list;
1905  for (auto p : expr_pair_list) {
1906  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
1907  p.second->rewrite_agg_to_var(tlist));
1908  }
1909  return makeExpr<CaseExpr>(type_info,
1910  contains_agg,
1911  epair_list,
1912  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
1913 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
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 1858 of file Analyzer.cpp.

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

1859  {
1860  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1861  epair_list;
1862  for (auto p : expr_pair_list) {
1863  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
1864  p.second->rewrite_with_child_targetlist(tlist));
1865  }
1866  return makeExpr<CaseExpr>(
1867  type_info,
1868  contains_agg,
1869  epair_list,
1870  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
1871 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
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 1815 of file Analyzer.cpp.

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

1816  {
1817  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1818  epair_list;
1819  for (auto p : expr_pair_list) {
1820  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1821  p.second->rewrite_with_targetlist(tlist));
1822  }
1823  return makeExpr<CaseExpr>(
1824  type_info,
1825  contains_agg,
1826  epair_list,
1827  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1828 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2546 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2546  {
2547  std::string str{"CASE "};
2548  for (auto p : expr_pair_list) {
2549  str += "(";
2550  str += p.first->toString();
2551  str += ", ";
2552  str += p.second->toString();
2553  str += ") ";
2554  }
2555  if (else_expr) {
2556  str += "ELSE ";
2557  str += else_expr->toString();
2558  }
2559  str += " END ";
2560  return str;
2561 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1128
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1131

Member Data Documentation


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