OmniSciDB  471d68cefb
 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 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 1075 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 1077 of file Analyzer.h.

1081  : Expr(kINT, target_value->get_type_info().get_notnull())
1082  , target_value_(target_value)
1085  , partition_count_(partition_count)
1086  , constant_expr_(false)
1087  , 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:68
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
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:1169

Member Function Documentation

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

Definition at line 1163 of file Analyzer.h.

References skip_out_of_bound_check_.

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

1163 { 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 1099 of file Analyzer.h.

References target_value_.

1102  {
1103  target_value_->collect_column_var(colvar_set, include_agg);
1104  }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
void Analyzer::WidthBucketExpr::collect_rte_idx ( std::set< int > &  rte_idx_set) const
inlineoverridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 1096 of file Analyzer.h.

References target_value_.

1096  {
1097  target_value_->collect_rte_idx(rte_idx_set);
1098  }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
template<typename T >
int32_t Analyzer::WidthBucketExpr::compute_bucket ( target_const_val,
SQLTypeInfo ti 
) const
inline

Definition at line 1129 of file Analyzer.h.

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

Referenced by getExpressionRange().

1129  {
1130  // this utility function is useful for optimizing expression range decision
1131  // for an expression depending on width_bucket expr
1132  T null_val = ti.is_integer() ? inline_int_null_val(ti) : inline_fp_null_val(ti);
1133  double lower_bound_val = get_bound_val(lower_bound_.get());
1134  double upper_bound_val = get_bound_val(upper_bound_.get());
1135  auto partition_count_val = get_partition_count_val();
1136  if (target_const_val == null_val) {
1137  return INT32_MIN;
1138  }
1139  float res;
1140  if (lower_bound_val < upper_bound_val) {
1141  if (target_const_val < lower_bound_val) {
1142  return 0;
1143  } else if (target_const_val >= upper_bound_val) {
1144  return partition_count_val + 1;
1145  }
1146  double dividend = upper_bound_val - lower_bound_val;
1147  res = ((partition_count_val * (target_const_val - lower_bound_val)) / dividend) + 1;
1148  } else {
1149  if (target_const_val > lower_bound_val) {
1150  return 0;
1151  } else if (target_const_val <= upper_bound_val) {
1152  return partition_count_val + 1;
1153  }
1154  double dividend = lower_bound_val - upper_bound_val;
1155  res = ((partition_count_val * (lower_bound_val - target_const_val)) / dividend) + 1;
1156  }
1157  return res;
1158  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
double inline_fp_null_val(const SQL_TYPE_INFO &ti)
double get_bound_val(const Analyzer::Expr *bound_expr) const
Definition: Analyzer.cpp:3420
#define INT32_MIN
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
bool is_integer() const
Definition: sqltypes.h:511
int32_t get_partition_count_val() const
Definition: Analyzer.cpp:3430
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 164 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

164  {
165  return makeExpr<WidthBucketExpr>(target_value_->deep_copy(),
166  lower_bound_->deep_copy(),
167  upper_bound_->deep_copy(),
168  partition_count_->deep_copy());
169 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
void Analyzer::WidthBucketExpr::find_expr ( bool(*)(const Expr *)  f,
std::list< const Expr * > &  expr_list 
) const
overridevirtual

Reimplemented from Analyzer::Expr.

Definition at line 3075 of file Analyzer.cpp.

References Analyzer::Expr::add_unique(), f, lower_bound_, partition_count_, target_value_, and upper_bound_.

3076  {
3077  if (f(this)) {
3078  add_unique(expr_list);
3079  return;
3080  }
3081  target_value_->find_expr(f, expr_list);
3082  lower_bound_->find_expr(f, expr_list);
3083  upper_bound_->find_expr(f, expr_list);
3084  partition_count_->find_expr(f, expr_list);
3085 }
virtual void add_unique(std::list< const Expr * > &expr_list) const
Definition: Analyzer.cpp:2965
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
char * f
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169

+ Here is the call graph for this function:

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

Definition at line 3420 of file Analyzer.cpp.

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

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

3420  {
3421  CHECK(bound_expr);
3422  auto copied_expr = bound_expr->deep_copy();
3423  auto casted_expr = copied_expr->add_cast(SQLTypeInfo(kDOUBLE, false));
3424  CHECK(casted_expr);
3425  auto casted_constant = std::dynamic_pointer_cast<const Analyzer::Constant>(casted_expr);
3426  CHECK(casted_constant);
3427  return casted_constant->get_constval().doubleval;
3428 }
virtual std::shared_ptr< Analyzer::Expr > deep_copy() const =0
#define CHECK(condition)
Definition: Logger.h:209

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

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

+ Here is the caller graph for this function:

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

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

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

+ Here is the caller graph for this function:

int32_t Analyzer::WidthBucketExpr::get_partition_count_val ( ) const

Definition at line 3430 of file Analyzer.cpp.

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

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

3430  {
3431  auto const_partition_count_expr =
3432  dynamic_cast<const Analyzer::Constant*>(partition_count_.get());
3433  if (!const_partition_count_expr) {
3434  return -1;
3435  }
3436  auto d = const_partition_count_expr->get_constval();
3437  switch (const_partition_count_expr->get_type_info().get_type()) {
3438  case kTINYINT:
3439  return d.tinyintval;
3440  case kSMALLINT:
3441  return d.smallintval;
3442  case kINT:
3443  return d.intval;
3444  case kBIGINT: {
3445  auto bi = d.bigintval;
3446  if (bi < 1 || bi > INT32_MAX) {
3447  return -1;
3448  }
3449  return bi;
3450  }
3451  default:
3452  return -1;
3453  }
3454 }
#define INT32_MAX
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
Datum get_constval() const
Definition: Analyzer.h:334
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 1088 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().

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

+ Here is the caller graph for this function:

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

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

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

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

References target_value_.

1717  {
1718  std::set<int> rte_idx_set;
1719  target_value_->collect_rte_idx(rte_idx_set);
1720  if (rte_idx_set.size() > 1) {
1721  join_predicates.push_back(this);
1722  } else if (rte_idx_set.size() == 1) {
1723  scan_predicates.push_back(this);
1724  } else {
1725  const_predicates.push_back(this);
1726  }
1727 }
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
bool Analyzer::WidthBucketExpr::is_constant_expr ( ) const
inline

Definition at line 1166 of file Analyzer.h.

References constant_expr_.

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

1166 { 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 2315 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_.

2315  {
2316  if (typeid(rhs) != typeid(WidthBucketExpr)) {
2317  return false;
2318  }
2319  const WidthBucketExpr& rhs_l = dynamic_cast<const WidthBucketExpr&>(rhs);
2320  if (!(*target_value_ == *rhs_l.get_target_value())) {
2321  return false;
2322  }
2323  if (!(*lower_bound_ == *rhs_l.get_lower_bound())) {
2324  return false;
2325  }
2326  if (!(*upper_bound_ == *rhs_l.get_upper_bound())) {
2327  return false;
2328  }
2329  if (!(*partition_count_ == *rhs_l.get_partition_count())) {
2330  return false;
2331  }
2332  return true;
2333 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
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:1077
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169

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

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1120  {
1121  return makeExpr<WidthBucketExpr>(target_value_->rewrite_agg_to_var(tlist),
1122  lower_bound_,
1123  upper_bound_,
1125  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
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 1112 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1113  {
1114  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_child_targetlist(tlist),
1115  lower_bound_,
1116  upper_bound_,
1118  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
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 1105 of file Analyzer.h.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

1106  {
1107  return makeExpr<WidthBucketExpr>(target_value_->rewrite_with_targetlist(tlist),
1108  lower_bound_,
1109  upper_bound_,
1111  }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169
void Analyzer::WidthBucketExpr::set_constant_expr ( ) const
inline

Definition at line 1165 of file Analyzer.h.

References constant_expr_.

Referenced by CodeGenerator::codegen().

1165 { constant_expr_ = true; }

+ Here is the caller graph for this function:

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

Definition at line 1164 of file Analyzer.h.

References skip_out_of_bound_check_.

Referenced by CodeGenerator::codegen().

1164 { 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 2770 of file Analyzer.cpp.

References lower_bound_, partition_count_, target_value_, and upper_bound_.

2770  {
2771  std::string str{"(WIDTH_BUCKET "};
2772  str += target_value_->toString();
2773  str += lower_bound_->toString();
2774  str += upper_bound_->toString();
2775  str += partition_count_->toString();
2776  return str + ") ";
2777 }
std::shared_ptr< Analyzer::Expr > upper_bound_
Definition: Analyzer.h:1171
std::shared_ptr< Analyzer::Expr > partition_count_
Definition: Analyzer.h:1172
std::shared_ptr< Analyzer::Expr > lower_bound_
Definition: Analyzer.h:1170
std::shared_ptr< Analyzer::Expr > target_value_
Definition: Analyzer.h:1169

Member Data Documentation

bool Analyzer::WidthBucketExpr::constant_expr_
mutableprivate

Definition at line 1174 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 1176 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: