OmniSciDB  a575cb28ea
 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:412
#define TRANSIENT_DICT_ID
Definition: sqltypes.h:250
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:319
HOST DEVICE int get_comp_param() const
Definition: sqltypes.h:320
bool is_string() const
Definition: sqltypes.h:478
#define TRANSIENT_DICT(ID)
Definition: sqltypes.h:251
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 3063 of file Analyzer.cpp.

References else_expr, and expr_pair_list.

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

References else_expr, and expr_pair_list.

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

References else_expr, and expr_pair_list.

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

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

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:1179
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: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 3096 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().

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

References else_expr, and expr_pair_list.

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: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: