OmniSciDB  c0231cc57d
 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 1028 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 1030 of file Analyzer.h.

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

Member Function Documentation

bool Analyzer::WidthBucketExpr::can_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(), CodeGenerator::codegenConstantWidthBucketExpr(), and CodeGenerator::codegenWidthBucketExpr().

1116 { 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 1052 of file Analyzer.h.

References target_value_.

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

Reimplemented from Analyzer::Expr.

Definition at line 1049 of file Analyzer.h.

References target_value_.

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

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

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

Reimplemented from Analyzer::Expr.

Definition at line 3185 of file Analyzer.cpp.

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

3186  {
3187  if (f(this)) {
3188  add_unique(expr_list);
3189  return;
3190  }
3191  target_value_->find_expr(f, expr_list);
3192  lower_bound_->find_expr(f, expr_list);
3193  upper_bound_->find_expr(f, expr_list);
3194  partition_count_->find_expr(f, expr_list);
3195 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:3073
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1125
constexpr double f
Definition: Utm.h:31
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1122

+ Here is the call graph for this function:

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

Definition at line 3683 of file Analyzer.cpp.

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

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

3683  {
3684  CHECK(bound_expr);
3685  auto copied_expr = bound_expr->deep_copy();
3686  auto casted_expr = copied_expr->add_cast(SQLTypeInfo(kDOUBLE, false));
3687  CHECK(casted_expr);
3688  auto casted_constant = std::dynamic_pointer_cast<const Analyzer::Constant>(casted_expr);
3689  CHECK(casted_constant);
3690  return casted_constant->get_constval().doubleval;
3691 }
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
#define CHECK(condition)
Definition: Logger.h:222

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

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

+ Here is the caller graph for this function:

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

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

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

+ Here is the caller graph for this function:

int32_t Analyzer::WidthBucketExpr::get_partition_count_val ( ) const

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

3693  {
3694  auto const_partition_count_expr =
3695  dynamic_cast<const Analyzer::Constant*>(partition_count_.get());
3696  if (!const_partition_count_expr) {
3697  return -1;
3698  }
3699  auto d = const_partition_count_expr->get_constval();
3700  switch (const_partition_count_expr->get_type_info().get_type()) {
3701  case kTINYINT:
3702  return d.tinyintval;
3703  case kSMALLINT:
3704  return d.smallintval;
3705  case kINT:
3706  return d.intval;
3707  case kBIGINT: {
3708  auto bi = d.bigintval;
3709  if (bi < 1 || bi > INT32_MAX) {
3710  return -1;
3711  }
3712  return bi;
3713  }
3714  default:
3715  return -1;
3716  }
3717 }
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1125
Datum get_constval() const
Definition: Analyzer.h:343
Definition: sqltypes.h:59

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

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

+ Here is the caller graph for this function:

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

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

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

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

References target_value_.

1754  {
1755  std::set<int> rte_idx_set;
1756  target_value_->collect_rte_idx(rte_idx_set);
1757  if (rte_idx_set.size() > 1) {
1758  join_predicates.push_back(this);
1759  } else if (rte_idx_set.size() == 1) {
1760  scan_predicates.push_back(this);
1761  } else {
1762  const_predicates.push_back(this);
1763  }
1764 }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1122
bool Analyzer::WidthBucketExpr::is_constant_expr ( ) const
inline

Definition at line 1119 of file Analyzer.h.

References constant_expr_.

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

1119 { 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 2373 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_.

2373  {
2374  if (typeid(rhs) != typeid(WidthBucketExpr)) {
2375  return false;
2376  }
2377  const WidthBucketExpr& rhs_l = dynamic_cast<const WidthBucketExpr&>(rhs);
2378  if (!(*target_value_ == *rhs_l.get_target_value())) {
2379  return false;
2380  }
2381  if (!(*lower_bound_ == *rhs_l.get_lower_bound())) {
2382  return false;
2383  }
2384  if (!(*upper_bound_ == *rhs_l.get_upper_bound())) {
2385  return false;
2386  }
2387  if (!(*partition_count_ == *rhs_l.get_partition_count())) {
2388  return false;
2389  }
2390  return true;
2391 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1123
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:1030
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1122

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

References lower_bound_, partition_count_, target_value_, and upper_bound_.

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

References lower_bound_, partition_count_, target_value_, and upper_bound_.

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

References lower_bound_, partition_count_, target_value_, and upper_bound_.

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

Definition at line 1118 of file Analyzer.h.

References constant_expr_.

Referenced by CodeGenerator::codegen().

1118 { constant_expr_ = true; }

+ Here is the caller graph for this function:

void Analyzer::WidthBucketExpr::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().

1117 { 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 2840 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

2840  {
2841  std::string str{"(WIDTH_BUCKET "};
2842  str += target_value_->toString();
2843  str += lower_bound_->toString();
2844  str += upper_bound_->toString();
2845  str += partition_count_->toString();
2846  return str + ") ";
2847 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1124
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1125
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1123
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1122

Member Data Documentation

bool Analyzer::WidthBucketExpr::constant_expr_
mutableprivate

Definition at line 1127 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 1129 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: