OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Analyzer::WidthBucketExpr Class Reference

#include <Analyzer.h>

+ Inheritance diagram for Analyzer::WidthBucketExpr:
+ Collaboration diagram for Analyzer::WidthBucketExpr:

Public Member Functions

 WidthBucketExpr (const std::shared_ptr< Analyzer::Expr > target_value, const std::shared_ptr< Analyzer::Expr > lower_bound, const std::shared_ptr< Analyzer::Expr > upper_bound, const std::shared_ptr< Analyzer::Expr > partition_count)
 
const Exprget_target_value () const
 
const Exprget_lower_bound () const
 
const Exprget_upper_bound () const
 
const Exprget_partition_count () const
 
std::shared_ptr< Analyzer::Exprdeep_copy () 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
 
double get_bound_val (const Analyzer::Expr *bound_expr) const
 
int32_t get_partition_count_val () const
 
template<typename T >
int32_t compute_bucket (T target_const_val, SQLTypeInfo &ti) const
 
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
 
bool can_skip_out_of_bound_check () const
 
void skip_out_of_bound_check () const
 
void set_constant_expr () const
 
bool is_constant_expr () const
 
- 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
add_cast (const SQLTypeInfo &new_type_info)
 
virtual void check_group_by (const std::list< std::shared_ptr< Analyzer::Expr >> &groupby) const
 
virtual std::shared_ptr
< Analyzer::Expr
normalize_simple_predicate (int &rte_idx) const
 
virtual size_t get_num_column_vars (const bool include_agg) const
 
virtual void print () const
 
virtual void add_unique (std::list< const Expr * > &expr_list) const
 
std::shared_ptr< Analyzer::Exprdecompress ()
 
virtual void get_domain (DomainSet &domain_set) const
 

Private Attributes

std::shared_ptr< Analyzer::Exprtarget_value_
 
std::shared_ptr< Analyzer::Exprlower_bound_
 
std::shared_ptr< Analyzer::Exprupper_bound_
 
std::shared_ptr< Analyzer::Exprpartition_count_
 
bool constant_expr_
 
bool skip_out_of_bound_check_
 

Additional Inherited Members

- Protected Attributes inherited from Analyzer::Expr
SQLTypeInfo type_info
 
bool contains_agg
 

Detailed Description

Definition at line 1027 of file Analyzer.h.

Constructor & Destructor Documentation

Analyzer::WidthBucketExpr::WidthBucketExpr ( const std::shared_ptr< Analyzer::Expr target_value,
const std::shared_ptr< Analyzer::Expr lower_bound,
const std::shared_ptr< Analyzer::Expr upper_bound,
const std::shared_ptr< Analyzer::Expr partition_count 
)
inline

Definition at line 1029 of file Analyzer.h.

1033  : Expr(kINT, target_value->get_type_info().get_notnull())
1034  , target_value_(target_value)
1037  , partition_count_(partition_count)
1038  , constant_expr_(false)
1039  , skip_out_of_bound_check_(false) {}
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
Expr(SQLTypes t, bool notnull)
Definition: Analyzer.h:72
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
Definition: sqltypes.h:45
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121

Member Function Documentation

bool Analyzer::WidthBucketExpr::can_skip_out_of_bound_check ( ) const
inline

Definition at line 1115 of file Analyzer.h.

References skip_out_of_bound_check_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), and CodeGenerator::codegenWidthBucketExpr().

1115 { return skip_out_of_bound_check_; }

+ Here is the caller graph for this function:

void Analyzer::WidthBucketExpr::collect_column_var ( std::set< const ColumnVar *, bool(*)(const ColumnVar *, const ColumnVar *)> &  colvar_set,
bool  include_agg 
) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1051 of file Analyzer.h.

References target_value_.

1054  {
1055  target_value_->collect_column_var(colvar_set, include_agg);
1056  }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
void Analyzer::WidthBucketExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1048 of file Analyzer.h.

References target_value_.

1048  {
1049  target_value_->collect_rte_idx(rte_idx_set);
1050  }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
template<typename T >
int32_t Analyzer::WidthBucketExpr::compute_bucket ( target_const_val,
SQLTypeInfo ti 
) const
inline

Definition at line 1081 of file Analyzer.h.

References get_bound_val(), get_partition_count_val(), inline_fp_null_val(), inline_int_null_val(), SQLTypeInfo::is_integer(), lower_bound_, run_benchmark_import::res, heavydb.dtypes::T, and upper_bound_.

Referenced by getExpressionRange().

1081  {
1082  // this utility function is useful for optimizing expression range decision
1083  // for an expression depending on width_bucket expr
1084  T null_val = ti.is_integer() ? inline_int_null_val(ti) : inline_fp_null_val(ti);
1085  double lower_bound_val = get_bound_val(lower_bound_.get());
1086  double upper_bound_val = get_bound_val(upper_bound_.get());
1087  auto partition_count_val = get_partition_count_val();
1088  if (target_const_val == null_val) {
1089  return INT32_MIN;
1090  }
1091  float res;
1092  if (lower_bound_val < upper_bound_val) {
1093  if (target_const_val < lower_bound_val) {
1094  return 0;
1095  } else if (target_const_val >= upper_bound_val) {
1096  return partition_count_val + 1;
1097  }
1098  double dividend = upper_bound_val - lower_bound_val;
1099  res = ((partition_count_val * (target_const_val - lower_bound_val)) / dividend) + 1;
1100  } else {
1101  if (target_const_val > lower_bound_val) {
1102  return 0;
1103  } else if (target_const_val <= upper_bound_val) {
1104  return partition_count_val + 1;
1105  }
1106  double dividend = lower_bound_val - upper_bound_val;
1107  res = ((partition_count_val * (lower_bound_val - target_const_val)) / dividend) + 1;
1108  }
1109  return res;
1110  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
double get_bound_val(const Analyzer::Expr *bound_expr) const
Definition: Analyzer.cpp:3583
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
bool is_integer() const
Definition: sqltypes.h:512
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3593
int64_t inline_int_null_val(const SQL_TYPE_INFO &ti)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::shared_ptr< Analyzer::Expr > Analyzer::WidthBucketExpr::deep_copy ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 168 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

168  {
169  return makeExpr<WidthBucketExpr>(target_value_->deep_copy(),
170  lower_bound_->deep_copy(),
171  upper_bound_->deep_copy(),
172  partition_count_->deep_copy());
173 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
void Analyzer::WidthBucketExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3100 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), anonymous_namespace{Utm.h}::f, lower_bound_, partition_count_, target_value_, and upper_bound_.

3101  {
3102  if (f(this)) {
3103  add_unique(expr_list);
3104  return;
3105  }
3106  target_value_->find_expr(f, expr_list);
3107  lower_bound_->find_expr(f, expr_list);
3108  upper_bound_->find_expr(f, expr_list);
3109  partition_count_->find_expr(f, expr_list);
3110 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2988
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121

+ Here is the call graph for this function:

double Analyzer::WidthBucketExpr::get_bound_val ( const Analyzer::Expr bound_expr) const

Definition at line 3583 of file Analyzer.cpp.

References CHECK, Analyzer::Expr::deep_copy(), and kDOUBLE.

Referenced by CodeGenerator::codegenConstantWidthBucketExpr(), and compute_bucket().

3583  {
3584  CHECK(bound_expr);
3585  auto copied_expr = bound_expr->deep_copy();
3586  auto casted_expr = copied_expr->add_cast(SQLTypeInfo(kDOUBLE, false));
3587  CHECK(casted_expr);
3588  auto casted_constant = std::dynamic_pointer_cast<const Analyzer::Constant>(casted_expr);
3589  CHECK(casted_constant);
3590  return casted_constant->get_constval().doubleval;
3591 }
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Expr* Analyzer::WidthBucketExpr::get_lower_bound ( ) const
inline

Definition at line 1041 of file Analyzer.h.

References lower_bound_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), CodeGenerator::codegenWidthBucketExpr(), operator==(), DeepCopyVisitor::visitWidthBucket(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWidthBucket().

1041 { return lower_bound_.get(); }
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122

+ Here is the caller graph for this function:

const Expr* Analyzer::WidthBucketExpr::get_partition_count ( ) const
inline

Definition at line 1043 of file Analyzer.h.

References partition_count_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), CodeGenerator::codegenWidthBucketExpr(), getExpressionRange(), operator==(), DeepCopyVisitor::visitWidthBucket(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWidthBucket().

1043 { return partition_count_.get(); }
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124

+ Here is the caller graph for this function:

int32_t Analyzer::WidthBucketExpr::get_partition_count_val ( ) const

Definition at line 3593 of file Analyzer.cpp.

References Analyzer::Constant::get_constval(), kBIGINT, kINT, kSMALLINT, kTINYINT, and partition_count_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), compute_bucket(), and getExpressionRange().

3593  {
3594  auto const_partition_count_expr =
3595  dynamic_cast<const Analyzer::Constant*>(partition_count_.get());
3596  if (!const_partition_count_expr) {
3597  return -1;
3598  }
3599  auto d = const_partition_count_expr->get_constval();
3600  switch (const_partition_count_expr->get_type_info().get_type()) {
3601  case kTINYINT:
3602  return d.tinyintval;
3603  case kSMALLINT:
3604  return d.smallintval;
3605  case kINT:
3606  return d.intval;
3607  case kBIGINT: {
3608  auto bi = d.bigintval;
3609  if (bi < 1 || bi > INT32_MAX) {
3610  return -1;
3611  }
3612  return bi;
3613  }
3614  default:
3615  return -1;
3616  }
3617 }
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
Datum get_constval() const
Definition: Analyzer.h:342
Definition: sqltypes.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Expr* Analyzer::WidthBucketExpr::get_target_value ( ) const
inline

Definition at line 1040 of file Analyzer.h.

References target_value_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), CodeGenerator::codegenWidthBucketExpr(), getExpressionRange(), operator==(), DeepCopyVisitor::visitWidthBucket(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWidthBucket().

1040 { return target_value_.get(); }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121

+ Here is the caller graph for this function:

const Expr* Analyzer::WidthBucketExpr::get_upper_bound ( ) const
inline

Definition at line 1042 of file Analyzer.h.

References upper_bound_.

Referenced by CodeGenerator::codegen(), CodeGenerator::codegenConstantWidthBucketExpr(), CodeGenerator::codegenWidthBucketExpr(), operator==(), DeepCopyVisitor::visitWidthBucket(), and ScalarExprVisitor< std::unordered_set< InputColDescriptor > >::visitWidthBucket().

1042 { return upper_bound_.get(); }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123

+ Here is the caller graph for this function:

void Analyzer::WidthBucketExpr::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 1723 of file Analyzer.cpp.

References target_value_.

1725  {
1726  std::set<int> rte_idx_set;
1727  target_value_->collect_rte_idx(rte_idx_set);
1728  if (rte_idx_set.size() > 1) {
1729  join_predicates.push_back(this);
1730  } else if (rte_idx_set.size() == 1) {
1731  scan_predicates.push_back(this);
1732  } else {
1733  const_predicates.push_back(this);
1734  }
1735 }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
bool Analyzer::WidthBucketExpr::is_constant_expr ( ) const
inline

Definition at line 1118 of file Analyzer.h.

References constant_expr_.

Referenced by CodeGenerator::codegen(), and getExpressionRange().

1118 { return constant_expr_; }

+ Here is the caller graph for this function:

bool Analyzer::WidthBucketExpr::operator== ( const Expr rhs) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2342 of file Analyzer.cpp.

References get_lower_bound(), get_partition_count(), get_target_value(), get_upper_bound(), lower_bound_, partition_count_, target_value_, and upper_bound_.

2342  {
2343  if (typeid(rhs) != typeid(WidthBucketExpr)) {
2344  return false;
2345  }
2346  const WidthBucketExpr& rhs_l = dynamic_cast<const WidthBucketExpr&>(rhs);
2347  if (!(*target_value_ == *rhs_l.get_target_value())) {
2348  return false;
2349  }
2350  if (!(*lower_bound_ == *rhs_l.get_lower_bound())) {
2351  return false;
2352  }
2353  if (!(*upper_bound_ == *rhs_l.get_upper_bound())) {
2354  return false;
2355  }
2356  if (!(*partition_count_ == *rhs_l.get_partition_count())) {
2357  return false;
2358  }
2359  return true;
2360 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
WidthBucketExpr(const std::shared_ptr< Analyzer::Expr > target_value, const std::shared_ptr< Analyzer::Expr > lower_bound, const std::shared_ptr< Analyzer::Expr > upper_bound, const std::shared_ptr< Analyzer::Expr > partition_count)
Definition: Analyzer.h:1029
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121

+ Here is the call graph for this function:

std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::rewrite_agg_to_var ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1071 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1072  {
1073  return makeExpr<WidthBucketExpr>(target_value_->rewrite_agg_to_var(tlist),
1074  lower_bound_,
1075  upper_bound_,
1077  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::rewrite_with_child_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1064 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1065  {
1066  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_child_targetlist(tlist),
1067  lower_bound_,
1068  upper_bound_,
1070  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::rewrite_with_targetlist ( const std::vector< std::shared_ptr< TargetEntry >> &  tlist) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1057 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1058  {
1059  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_targetlist(tlist),
1060  lower_bound_,
1061  upper_bound_,
1063  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121
void Analyzer::WidthBucketExpr::set_constant_expr ( ) const
inline

Definition at line 1117 of file Analyzer.h.

References constant_expr_.

Referenced by CodeGenerator::codegen().

1117 { constant_expr_ = true; }

+ Here is the caller graph for this function:

void Analyzer::WidthBucketExpr::skip_out_of_bound_check ( ) const
inline

Definition at line 1116 of file Analyzer.h.

References skip_out_of_bound_check_.

Referenced by CodeGenerator::codegen().

1116 { skip_out_of_bound_check_ = true; }

+ Here is the caller graph for this function:

std::string Analyzer::WidthBucketExpr::toString ( ) const
overridevirtual

Implements Analyzer::Expr.

Definition at line 2793 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

2793  {
2794  std::string str{"(WIDTH_BUCKET "};
2795  str += target_value_->toString();
2796  str += lower_bound_->toString();
2797  str += upper_bound_->toString();
2798  str += partition_count_->toString();
2799  return str + ") ";
2800 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1122
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1121

Member Data Documentation

bool Analyzer::WidthBucketExpr::constant_expr_
mutableprivate

Definition at line 1126 of file Analyzer.h.

Referenced by is_constant_expr(), and set_constant_expr().

std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::lower_bound_
private
std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::partition_count_
private
bool Analyzer::WidthBucketExpr::skip_out_of_bound_check_
mutableprivate

Definition at line 1128 of file Analyzer.h.

Referenced by can_skip_out_of_bound_check(), and skip_out_of_bound_check().

std::shared_ptr<Analyzer::Expr> Analyzer::WidthBucketExpr::upper_bound_
private

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