OmniSciDB  7bf56492aa
 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 1232 of file Analyzer.cpp.

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

1232  {
1233  SQLTypeInfo ti = new_type_info;
1234  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1235  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1239  }
1240 
1241  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1242  new_expr_pair_list;
1243  for (auto& p : expr_pair_list) {
1244  new_expr_pair_list.emplace_back(
1245  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1246  }
1247 
1248  if (else_expr != nullptr) {
1249  else_expr = else_expr->add_cast(ti);
1250  }
1251  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1252  expr_pair_list = new_expr_pair_list;
1253 
1254  type_info = ti;
1255  return shared_from_this();
1256 }
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
void set_comp_param(int p)
Definition: sqltypes.h:349
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:187
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:256
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:257
bool is_string() const
Definition: sqltypes.h:399
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:188
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 2887 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

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

References else_expr, and expr_pair_list.

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

References else_expr, and expr_pair_list.

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

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

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

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

References else_expr, and expr_pair_list.

1594  {
1595  std::set<int> rte_idx_set;
1596  for (auto p : expr_pair_list) {
1597  p.first->collect_rte_idx(rte_idx_set);
1598  p.second->collect_rte_idx(rte_idx_set);
1599  }
1600  if (else_expr != nullptr) {
1601  else_expr->collect_rte_idx(rte_idx_set);
1602  }
1603  if (rte_idx_set.size() > 1) {
1604  join_predicates.push_back(this);
1605  } else if (rte_idx_set.size() == 1) {
1606  scan_predicates.push_back(this);
1607  } else {
1608  const_predicates.push_back(this);
1609  }
1610 }
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 2180 of file Analyzer.cpp.

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

2180  {
2181  if (typeid(rhs) != typeid(CaseExpr)) {
2182  return false;
2183  }
2184  const CaseExpr& rhs_ce = dynamic_cast<const CaseExpr&>(rhs);
2185  if (expr_pair_list.size() != rhs_ce.get_expr_pair_list().size()) {
2186  return false;
2187  }
2188  if ((else_expr == nullptr && rhs_ce.get_else_expr() != nullptr) ||
2189  (else_expr != nullptr && rhs_ce.get_else_expr() == nullptr)) {
2190  return false;
2191  }
2192  auto it = rhs_ce.get_expr_pair_list().cbegin();
2193  for (auto p : expr_pair_list) {
2194  if (!(*p.first == *it->first) || !(*p.second == *it->second)) {
2195  return false;
2196  }
2197  ++it;
2198  }
2199  return else_expr == nullptr ||
2200  (else_expr != nullptr && *else_expr == *rhs_ce.get_else_expr());
2201 }
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 1902 of file Analyzer.cpp.

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

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

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

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

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

1817  {
1818  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1819  epair_list;
1820  for (auto p : expr_pair_list) {
1821  epair_list.emplace_back(p.first->rewrite_with_targetlist(tlist),
1822  p.second->rewrite_with_targetlist(tlist));
1823  }
1824  return makeExpr<CaseExpr>(
1825  type_info,
1826  contains_agg,
1827  epair_list,
1828  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1829 }
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 2555 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

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