OmniSciDB  a987f07e93
 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 (std::function< bool(const Expr *)> f, 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 1029 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 1031 of file Analyzer.h.

1035  : Expr(kINT, target_value->get_type_info().get_notnull())
1036  , target_value_(target_value)
1039  , partition_count_(partition_count)
1040  , constant_expr_(false)
1041  , 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:74
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
Definition: sqltypes.h:60
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123

Member Function Documentation

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

Definition at line 1117 of file Analyzer.h.

References skip_out_of_bound_check_.

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

1117 { 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 1053 of file Analyzer.h.

References target_value_.

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

Reimplemented from Analyzer::Expr.

Definition at line 1050 of file Analyzer.h.

References target_value_.

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

Definition at line 1083 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().

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

References lower_bound_, partition_count_, target_value_, and upper_bound_.

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

Reimplemented from Analyzer::Expr.

Definition at line 3215 of file Analyzer.cpp.

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

3216  {
3217  if (f(this)) {
3218  add_unique(expr_list);
3219  return;
3220  }
3221  target_value_->find_expr(f, expr_list);
3222  lower_bound_->find_expr(f, expr_list);
3223  upper_bound_->find_expr(f, expr_list);
3224  partition_count_->find_expr(f, expr_list);
3225 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3101
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123

+ Here is the call graph for this function:

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

Definition at line 3737 of file Analyzer.cpp.

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

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

3737  {
3738  CHECK(bound_expr);
3739  auto copied_expr = bound_expr->deep_copy();
3740  auto casted_expr = copied_expr->add_cast(SQLTypeInfo(kDOUBLE, false));
3741  CHECK(casted_expr);
3742  auto casted_constant = std::dynamic_pointer_cast<const Analyzer::Constant>(casted_expr);
3743  CHECK(casted_constant);
3744  return casted_constant->get_constval().doubleval;
3745 }
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
#define CHECK(condition)
Definition: Logger.h:289

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

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

+ Here is the caller graph for this function:

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

Definition at line 1045 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().

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

+ Here is the caller graph for this function:

int32_t Analyzer::WidthBucketExpr::get_partition_count_val ( ) const

Definition at line 3747 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().

3747  {
3748  auto const_partition_count_expr =
3749  dynamic_cast<const Analyzer::Constant*>(partition_count_.get());
3750  if (!const_partition_count_expr) {
3751  return -1;
3752  }
3753  auto d = const_partition_count_expr->get_constval();
3754  switch (const_partition_count_expr->get_type_info().get_type()) {
3755  case kTINYINT:
3756  return d.tinyintval;
3757  case kSMALLINT:
3758  return d.smallintval;
3759  case kINT:
3760  return d.intval;
3761  case kBIGINT: {
3762  auto bi = d.bigintval;
3763  if (bi < 1 || bi > INT32_MAX) {
3764  return -1;
3765  }
3766  return bi;
3767  }
3768  default:
3769  return -1;
3770  }
3771 }
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
Datum get_constval() const
Definition: Analyzer.h:344
Definition: sqltypes.h:60

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

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

+ Here is the caller graph for this function:

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

Definition at line 1044 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().

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

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

References target_value_.

1770  {
1771  std::set<int> rte_idx_set;
1772  target_value_->collect_rte_idx(rte_idx_set);
1773  if (rte_idx_set.size() > 1) {
1774  join_predicates.push_back(this);
1775  } else if (rte_idx_set.size() == 1) {
1776  scan_predicates.push_back(this);
1777  } else {
1778  const_predicates.push_back(this);
1779  }
1780 }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123
bool Analyzer::WidthBucketExpr::is_constant_expr ( ) const
inline

Definition at line 1120 of file Analyzer.h.

References constant_expr_.

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

1120 { 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 2389 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_.

2389  {
2390  if (typeid(rhs) != typeid(WidthBucketExpr)) {
2391  return false;
2392  }
2393  const WidthBucketExpr& rhs_l = dynamic_cast<const WidthBucketExpr&>(rhs);
2394  if (!(*target_value_ == *rhs_l.get_target_value())) {
2395  return false;
2396  }
2397  if (!(*lower_bound_ == *rhs_l.get_lower_bound())) {
2398  return false;
2399  }
2400  if (!(*upper_bound_ == *rhs_l.get_upper_bound())) {
2401  return false;
2402  }
2403  if (!(*partition_count_ == *rhs_l.get_partition_count())) {
2404  return false;
2405  }
2406  return true;
2407 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
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:1031
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123

+ 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 1073 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1074  {
1075  return makeExpr<WidthBucketExpr>(target_value_->rewrite_agg_to_var(tlist),
1076  lower_bound_,
1077  upper_bound_,
1079  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123
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 1066 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1067  {
1068  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_child_targetlist(tlist),
1069  lower_bound_,
1070  upper_bound_,
1072  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123
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 1059 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

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

Definition at line 1119 of file Analyzer.h.

References constant_expr_.

Referenced by CodeGenerator::codegen().

1119 { constant_expr_ = true; }

+ Here is the caller graph for this function:

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

Definition at line 1118 of file Analyzer.h.

References skip_out_of_bound_check_.

Referenced by CodeGenerator::codegen().

1118 { 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 2856 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

2856  {
2857  std::string str{"(WIDTH_BUCKET "};
2858  str += target_value_->toString();
2859  str += lower_bound_->toString();
2860  str += upper_bound_->toString();
2861  str += partition_count_->toString();
2862  return str + ") ";
2863 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1126
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1123

Member Data Documentation

bool Analyzer::WidthBucketExpr::constant_expr_
mutableprivate

Definition at line 1128 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 1130 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: