OmniSciDB  eee9fa949c
 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 2886 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2887  {
2888  for (auto p : expr_pair_list) {
2889  p.first->check_group_by(groupby);
2890  p.second->check_group_by(groupby);
2891  }
2892  if (else_expr != nullptr) {
2893  else_expr->check_group_by(groupby);
2894  }
2895 }
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 2848 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2850  {
2851  for (auto p : expr_pair_list) {
2852  p.first->collect_column_var(colvar_set, include_agg);
2853  p.second->collect_column_var(colvar_set, include_agg);
2854  }
2855  if (else_expr != nullptr) {
2856  else_expr->collect_column_var(colvar_set, include_agg);
2857  }
2858 }
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 2820 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2820  {
2821  for (auto p : expr_pair_list) {
2822  p.first->collect_rte_idx(rte_idx_set);
2823  p.second->collect_rte_idx(rte_idx_set);
2824  }
2825  if (else_expr != nullptr) {
2826  else_expr->collect_rte_idx(rte_idx_set);
2827  }
2828 }
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 2767 of file Analyzer.cpp.

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

2768  {
2769  if (f(this)) {
2770  add_unique(expr_list);
2771  return;
2772  }
2773  for (auto p : expr_pair_list) {
2774  p.first->find_expr(f, expr_list);
2775  p.second->find_expr(f, expr_list);
2776  }
2777  if (else_expr != nullptr) {
2778  else_expr->find_expr(f, expr_list);
2779  }
2780 }
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:2647
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 2919 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().

2919  {
2920  for (const auto& p : expr_pair_list) {
2921  const auto c = std::dynamic_pointer_cast<const Constant>(p.second);
2922  if (c != nullptr) {
2923  c->add_unique(domain_set);
2924  } else {
2925  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2926  if (v != nullptr) {
2927  v->add_unique(domain_set);
2928  } else {
2929  const auto cast = std::dynamic_pointer_cast<const UOper>(p.second);
2930  if (cast != nullptr && cast->get_optype() == kCAST) {
2931  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2932  if (c != nullptr) {
2933  cast->add_unique(domain_set);
2934  continue;
2935  } else {
2936  const auto v = std::dynamic_pointer_cast<const ColumnVar>(p.second);
2937  if (v != nullptr) {
2938  v->add_unique(domain_set);
2939  continue;
2940  }
2941  }
2942  }
2943  p.second->get_domain(domain_set);
2944  if (domain_set.empty()) {
2945  return;
2946  }
2947  }
2948  }
2949  }
2950  if (else_expr != nullptr) {
2951  const auto c = std::dynamic_pointer_cast<const Constant>(else_expr);
2952  if (c != nullptr) {
2953  c->add_unique(domain_set);
2954  } else {
2955  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2956  if (v != nullptr) {
2957  v->add_unique(domain_set);
2958  } else {
2959  const auto cast = std::dynamic_pointer_cast<const UOper>(else_expr);
2960  if (cast != nullptr && cast->get_optype() == kCAST) {
2961  const Constant* c = dynamic_cast<const Constant*>(cast->get_operand());
2962  if (c != nullptr) {
2963  c->add_unique(domain_set);
2964  } else {
2965  const auto v = std::dynamic_pointer_cast<const ColumnVar>(else_expr);
2966  if (v != nullptr) {
2967  v->add_unique(domain_set);
2968  }
2969  }
2970  } else {
2971  else_expr->get_domain(domain_set);
2972  }
2973  }
2974  }
2975  }
2976 }
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 2554 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2554  {
2555  std::string str{"CASE "};
2556  for (auto p : expr_pair_list) {
2557  str += "(";
2558  str += p.first->toString();
2559  str += ", ";
2560  str += p.second->toString();
2561  str += ") ";
2562  }
2563  if (else_expr) {
2564  str += "ELSE ";
2565  str += else_expr->toString();
2566  }
2567  str += " END ";
2568  return str;
2569 }
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: