OmniSciDB  340b00dbf6
 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 1139 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 1141 of file Analyzer.h.

1146  : 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:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

1304  {
1305  SQLTypeInfo ti = new_type_info;
1306  if (new_type_info.is_string() && new_type_info.get_compression() == kENCODING_DICT &&
1307  new_type_info.get_comp_param() == TRANSIENT_DICT_ID && type_info.is_string() &&
1311  }
1312 
1313  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1314  new_expr_pair_list;
1315  for (auto& p : expr_pair_list) {
1316  new_expr_pair_list.emplace_back(
1317  std::make_pair(p.first, p.second->deep_copy()->add_cast(ti)));
1318  }
1319 
1320  if (else_expr != nullptr) {
1321  else_expr = else_expr->add_cast(ti);
1322  }
1323  // Replace the current WHEN THEN pair list once we are sure all casts have succeeded
1324  expr_pair_list = new_expr_pair_list;
1325 
1326  type_info = ti;
1327  return shared_from_this();
1328 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
void set_comp_param(int p)
Definition: sqltypes.h:431
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:269
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:338
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:339
bool is_string() const
Definition: sqltypes.h:487
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:270
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

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

References else_expr, and expr_pair_list.

3061  {
3062  for (auto p : expr_pair_list) {
3063  p.first->check_group_by(groupby);
3064  p.second->check_group_by(groupby);
3065  }
3066  if (else_expr != nullptr) {
3067  else_expr->check_group_by(groupby);
3068  }
3069 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 3022 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

3024  {
3025  for (auto p : expr_pair_list) {
3026  p.first->collect_column_var(colvar_set, include_agg);
3027  p.second->collect_column_var(colvar_set, include_agg);
3028  }
3029  if (else_expr != nullptr) {
3030  else_expr->collect_column_var(colvar_set, include_agg);
3031  }
3032 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
void Analyzer::CaseExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 2994 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

2994  {
2995  for (auto p : expr_pair_list) {
2996  p.first->collect_rte_idx(rte_idx_set);
2997  p.second->collect_rte_idx(rte_idx_set);
2998  }
2999  if (else_expr != nullptr) {
3000  else_expr->collect_rte_idx(rte_idx_set);
3001  }
3002 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
std::shared_ptr< Analyzer::Expr > Analyzer::CaseExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 165 of file Analyzer.cpp.

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

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

Reimplemented from Analyzer::Expr.

Definition at line 2941 of file Analyzer.cpp.

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

2942  {
2943  if (f(this)) {
2944  add_unique(expr_list);
2945  return;
2946  }
2947  for (auto p : expr_pair_list) {
2948  p.first->find_expr(f, expr_list);
2949  p.second->find_expr(f, expr_list);
2950  }
2951  if (else_expr != nullptr) {
2952  else_expr->find_expr(f, expr_list);
2953  }
2954 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2812
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182

+ 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 3093 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().

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

+ 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 1152 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().

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

+ 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 1149 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().

1149  {
1150  return expr_pair_list;
1151  }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179

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

References else_expr, and expr_pair_list.

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

Implements Analyzer::Expr.

Definition at line 2277 of file Analyzer.cpp.

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

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

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

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

1989  {
1990  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1991  epair_list;
1992  for (auto p : expr_pair_list) {
1993  epair_list.emplace_back(p.first->rewrite_agg_to_var(tlist),
1994  p.second->rewrite_agg_to_var(tlist));
1995  }
1996  return makeExpr<CaseExpr>(type_info,
1997  contains_agg,
1998  epair_list,
1999  else_expr ? else_expr->rewrite_agg_to_var(tlist) : nullptr);
2000 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 1945 of file Analyzer.cpp.

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

1946  {
1947  std::list<std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>
1948  epair_list;
1949  for (auto p : expr_pair_list) {
1950  epair_list.emplace_back(p.first->rewrite_with_child_targetlist(tlist),
1951  p.second->rewrite_with_child_targetlist(tlist));
1952  }
1953  return makeExpr<CaseExpr>(
1954  type_info,
1955  contains_agg,
1956  epair_list,
1957  else_expr ? else_expr->rewrite_with_child_targetlist(tlist) : nullptr);
1958 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
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 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_with_targetlist(tlist),
1908  p.second->rewrite_with_targetlist(tlist));
1909  }
1910  return makeExpr<CaseExpr>(
1911  type_info,
1912  contains_agg,
1913  epair_list,
1914  else_expr ? else_expr->rewrite_with_targetlist(tlist) : nullptr);
1915 }
std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr > > > expr_pair_list
Definition: Analyzer.h:1179
SQLTypeInfo type_info
Definition: Analyzer.h:176
bool contains_agg
Definition: Analyzer.h:177
std::shared_ptr< Analyzer::Expr > else_expr
Definition: Analyzer.h:1182
std::string Analyzer::CaseExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2675 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

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

Member Data Documentation


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