OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExpressionRange Class Reference

#include <ExpressionRange.h>

Public Member Functions

int64_t getIntMin () const
 
int64_t getIntMax () const
 
double getFpMin () const
 
double getFpMax () const
 
void setIntMin (const int64_t int_min)
 
void setIntMax (const int64_t int_max)
 
void setIntInvalidRange ()
 
void setFpMin (const double fp_min)
 
void setFpMax (const double fp_max)
 
ExpressionRangeType getType () const
 
int64_t getBucket () const
 
bool hasNulls () const
 
void setHasNulls ()
 
void setNulls (bool n)
 
ExpressionRange operator+ (const ExpressionRange &other) const
 
ExpressionRange operator- (const ExpressionRange &other) const
 
ExpressionRange operator* (const ExpressionRange &other) const
 
ExpressionRange operator/ (const ExpressionRange &other) const
 
ExpressionRange operator|| (const ExpressionRange &other) const
 
bool operator== (const ExpressionRange &other) const
 
std::string toString () const
 

Static Public Member Functions

static ExpressionRange makeIntRange (const int64_t int_min, const int64_t int_max, const int64_t bucket, const bool has_nulls)
 
static ExpressionRange makeDoubleRange (const double fp_min, const double fp_max, const bool has_nulls)
 
static ExpressionRange makeFloatRange (const float fp_min, const float fp_max, const bool has_nulls)
 
static ExpressionRange makeNullRange ()
 
static ExpressionRange makeInvalidRange ()
 
static bool typeSupportsRange (const SQLTypeInfo &ti)
 

Private Member Functions

 ExpressionRange (const int64_t int_min_in, const int64_t int_max_in, const int64_t bucket, const bool has_nulls_in)
 
 ExpressionRange (const ExpressionRangeType type, const double fp_min_in, const double fp_max_in, const bool has_nulls_in)
 
 ExpressionRange ()
 
 ExpressionRange (const ExpressionRangeType type)
 
template<class T , class BinOp >
ExpressionRange binOp (const ExpressionRange &other, const BinOp &bin_op) const
 

Private Attributes

ExpressionRangeType type_
 
bool has_nulls_
 
union {
   int64_t   int_min_
 
   double   fp_min_
 
}; 
 
union {
   int64_t   int_max_
 
   double   fp_max_
 
}; 
 
int64_t bucket_
 

Detailed Description

Definition at line 56 of file ExpressionRange.h.

Constructor & Destructor Documentation

ExpressionRange::ExpressionRange ( const int64_t  int_min_in,
const int64_t  int_max_in,
const int64_t  bucket,
const bool  has_nulls_in 
)
inlineprivate

Definition at line 176 of file ExpressionRange.h.

181  , has_nulls_(has_nulls_in)
182  , int_min_(int_min_in)
183  , int_max_(int_max_in)
184  , bucket_(bucket) {}
ExpressionRangeType type_
ExpressionRange::ExpressionRange ( const ExpressionRangeType  type,
const double  fp_min_in,
const double  fp_max_in,
const bool  has_nulls_in 
)
inlineprivate

Definition at line 186 of file ExpressionRange.h.

References CHECK, Double, Float, and type_.

190  : type_(type)
191  , has_nulls_(has_nulls_in)
192  , fp_min_(fp_min_in)
193  , fp_max_(fp_max_in)
194  , bucket_(0) {
196  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
ExpressionRange::ExpressionRange ( )
inlineprivate

Definition at line 198 of file ExpressionRange.h.

Referenced by makeDoubleRange(), makeFloatRange(), makeIntRange(), makeInvalidRange(), and makeNullRange().

+ Here is the caller graph for this function:

ExpressionRange::ExpressionRange ( const ExpressionRangeType  type)
inlineexplicitprivate

Definition at line 201 of file ExpressionRange.h.

References CHECK, Null, and type_.

202  : type_(type), has_nulls_(true), bucket_(0) {
204  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

Member Function Documentation

template<class T , class BinOp >
ExpressionRange ExpressionRange::binOp ( const ExpressionRange other,
const BinOp &  bin_op 
) const
inlineprivate

Definition at line 207 of file ExpressionRange.h.

References CHECK, Double, Float, fp_max_, fp_min_, has_nulls_, int_max_, int_min_, Integer, makeInvalidRange(), run_benchmark_import::result, and type_.

207  {
208  CHECK(type_ == other.type_);
209  try {
210  std::vector<T> limits{bin_op(getMin<T>(*this), getMin<T>(other)),
211  bin_op(getMin<T>(*this), getMax<T>(other)),
212  bin_op(getMax<T>(*this), getMin<T>(other)),
213  bin_op(getMax<T>(*this), getMax<T>(other))};
215  result.type_ = type_;
216  result.has_nulls_ = has_nulls_ || other.has_nulls_;
217  switch (result.type_) {
219  result.int_min_ = *std::min_element(limits.begin(), limits.end());
220  result.int_max_ = *std::max_element(limits.begin(), limits.end());
221  break;
222  }
225  result.fp_min_ = *std::min_element(limits.begin(), limits.end());
226  result.fp_max_ = *std::max_element(limits.begin(), limits.end());
227  break;
228  }
229  default:
230  CHECK(false);
231  }
232  return result;
233  } catch (...) {
235  }
236  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

int64_t ExpressionRange::getBucket ( ) const
inline

Definition at line 131 of file ExpressionRange.h.

References bucket_, CHECK, Invalid, and type_.

Referenced by anonymous_namespace{PerfectJoinHashTable.cpp}::get_bucketized_hash_entry_info().

131  {
133  return bucket_;
134  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

double ExpressionRange::getFpMax ( ) const
inline

Definition at line 98 of file ExpressionRange.h.

References CHECK, Double, Float, fp_max_, and type_.

Referenced by getExpressionRange().

98  {
100  return fp_max_;
101  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

double ExpressionRange::getFpMin ( ) const
inline

Definition at line 93 of file ExpressionRange.h.

References CHECK, Double, Float, fp_min_, and type_.

Referenced by getExpressionRange().

+ Here is the caller graph for this function:

ExpressionRangeType ExpressionRange::getType ( ) const
inline

Definition at line 129 of file ExpressionRange.h.

References type_.

Referenced by apply_simple_quals(), getExpressionRange(), PerfectJoinHashTable::PerfectJoinHashTable(), and anonymous_namespace{QueryMemoryDescriptor.cpp}::pick_baseline_key_component_width().

129 { return type_; }
ExpressionRangeType type_

+ Here is the caller graph for this function:

bool ExpressionRange::hasNulls ( ) const
inline

Definition at line 136 of file ExpressionRange.h.

References CHECK, has_nulls_, Invalid, and type_.

Referenced by anonymous_namespace{ExpressionRange.cpp}::fpRangeFromDecimal(), anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange(), getExpressionRange(), and anonymous_namespace{QueryMemoryDescriptor.cpp}::pick_baseline_key_component_width().

136  {
138  return has_nulls_;
139  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeDoubleRange ( const double  fp_min,
const double  fp_max,
const bool  has_nulls 
)
inlinestatic

Definition at line 65 of file ExpressionRange.h.

References Double, and ExpressionRange().

Referenced by ThriftSerializers::column_ranges_from_thrift(), anonymous_namespace{ExpressionRange.cpp}::fpRangeFromDecimal(), getExpressionRange(), and getLeafColumnRange().

67  {
68  return ExpressionRange(ExpressionRangeType::Double, fp_min, fp_max, has_nulls);
69  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeFloatRange ( const float  fp_min,
const float  fp_max,
const bool  has_nulls 
)
inlinestatic

Definition at line 71 of file ExpressionRange.h.

References ExpressionRange(), and Float.

Referenced by ThriftSerializers::column_ranges_from_thrift(), anonymous_namespace{ExpressionRange.cpp}::fpRangeFromDecimal(), getExpressionRange(), and getLeafColumnRange().

73  {
74  return ExpressionRange(ExpressionRangeType::Float, fp_min, fp_max, has_nulls);
75  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeIntRange ( const int64_t  int_min,
const int64_t  int_max,
const int64_t  bucket,
const bool  has_nulls 
)
inlinestatic

Definition at line 58 of file ExpressionRange.h.

References ExpressionRange().

Referenced by ThriftSerializers::column_ranges_from_thrift(), anonymous_namespace{ExpressionRange.cpp}::getDateTimePrecisionCastRange(), getExpressionRange(), PerfectJoinHashTable::getInstance(), and getLeafColumnRange().

61  {
62  return ExpressionRange(int_min, int_max, bucket, has_nulls);
63  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeInvalidRange ( )
inlinestatic

Definition at line 81 of file ExpressionRange.h.

References ExpressionRange().

Referenced by binOp(), CodeGenerator::checkExpressionRanges(), ThriftSerializers::column_ranges_from_thrift(), getExpressionRange(), getLeafColumnRange(), operator/(), and operator||().

81 { return ExpressionRange(); }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeNullRange ( )
inlinestatic

Definition at line 77 of file ExpressionRange.h.

References ExpressionRange(), and Null.

Referenced by getExpressionRange().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ExpressionRange ExpressionRange::operator* ( const ExpressionRange other) const
ExpressionRange ExpressionRange::operator+ ( const ExpressionRange other) const
ExpressionRange ExpressionRange::operator- ( const ExpressionRange other) const
ExpressionRange ExpressionRange::operator/ ( const ExpressionRange other) const

Definition at line 207 of file ExpressionRange.cpp.

References g_null_div_by_zero, int_max_, int_min_, Integer, makeInvalidRange(), and type_.

207  {
211  }
212  if (other.int_min_ * other.int_max_ <= 0) {
213  // if the other interval contains 0, the rule is more complicated;
214  // punt for now, we can revisit by splitting the other interval and
215  // taking the convex hull of the resulting two intervals
217  }
218  auto div_range = binOp<int64_t>(other, [](const int64_t x, const int64_t y) {
219  return int64_t(checked_int64_t(x) / y);
220  });
221  if (g_null_div_by_zero) {
222  div_range.setHasNulls();
223  }
224  return div_range;
225 }
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 64, 64, boost::multiprecision::signed_magnitude, boost::multiprecision::checked, void >> checked_int64_t
bool g_null_div_by_zero
Definition: Execute.cpp:84
ExpressionRangeType type_
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

bool ExpressionRange::operator== ( const ExpressionRange other) const

Definition at line 257 of file ExpressionRange.cpp.

References CHECK, Double, Float, fp_max_, fp_min_, has_nulls_, int_max_, int_min_, Integer, Invalid, and type_.

257  {
258  if (type_ != other.type_) {
259  return false;
260  }
261  switch (type_) {
263  return true;
265  return has_nulls_ == other.has_nulls_ && int_min_ == other.int_min_ &&
266  int_max_ == other.int_max_;
267  }
270  return has_nulls_ == other.has_nulls_ && fp_min_ == other.fp_min_ &&
271  fp_max_ == other.fp_max_;
272  }
273  default:
274  CHECK(false);
275  }
276  return false;
277 }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
ExpressionRange ExpressionRange::operator|| ( const ExpressionRange other) const

Definition at line 227 of file ExpressionRange.cpp.

References bucket_, CHECK, Double, Float, fp_max_, fp_min_, has_nulls_, int_max_, int_min_, Integer, Invalid, makeInvalidRange(), run_benchmark_import::result, and type_.

227  {
228  if (type_ != other.type_) {
230  }
232  switch (type_) {
237  result.has_nulls_ = has_nulls_ || other.has_nulls_;
238  result.int_min_ = std::min(int_min_, other.int_min_);
239  result.int_max_ = std::max(int_max_, other.int_max_);
240  result.bucket_ = std::min(bucket_, other.bucket_);
241  break;
242  }
245  result.type_ = type_;
246  result.has_nulls_ = has_nulls_ || other.has_nulls_;
247  result.fp_min_ = std::min(fp_min_, other.fp_min_);
248  result.fp_max_ = std::max(fp_max_, other.fp_max_);
249  break;
250  }
251  default:
252  CHECK(false);
253  }
254  return result;
255 }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

void ExpressionRange::setFpMax ( const double  fp_max)
inline

Definition at line 124 of file ExpressionRange.h.

References CHECK, Double, Float, fp_max_, and type_.

124  {
126  fp_max_ = fp_max;
127  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
void ExpressionRange::setFpMin ( const double  fp_min)
inline

Definition at line 119 of file ExpressionRange.h.

References CHECK, Double, Float, fp_min_, and type_.

119  {
121  fp_min_ = fp_min;
122  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
void ExpressionRange::setHasNulls ( )
inline

Definition at line 141 of file ExpressionRange.h.

References has_nulls_.

141 { has_nulls_ = true; }
void ExpressionRange::setIntInvalidRange ( )
inline

Definition at line 113 of file ExpressionRange.h.

References CHECK, int_max_, int_min_, Integer, and type_.

113  {
115  int_max_ = -1;
116  int_min_ = 0;
117  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211
void ExpressionRange::setIntMax ( const int64_t  int_max)
inline

Definition at line 108 of file ExpressionRange.h.

References CHECK, int_max_, Integer, and type_.

Referenced by apply_int_qual().

108  {
110  int_max_ = int_max;
111  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

void ExpressionRange::setIntMin ( const int64_t  int_min)
inline

Definition at line 103 of file ExpressionRange.h.

References CHECK, int_min_, Integer, and type_.

Referenced by apply_int_qual().

103  {
105  int_min_ = int_min;
106  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:211

+ Here is the caller graph for this function:

void ExpressionRange::setNulls ( bool  n)
inline

Definition at line 143 of file ExpressionRange.h.

References has_nulls_, and anonymous_namespace{Utm.h}::n.

143 { has_nulls_ = n; }
constexpr double n
Definition: Utm.h:39
std::string ExpressionRange::toString ( ) const
inline

Definition at line 155 of file ExpressionRange.h.

References bucket_, Double, Float, fp_max_, fp_min_, has_nulls_, int_max_, int_min_, Integer, to_string(), and type_.

Referenced by PerfectJoinHashTable::getAlternativeCacheKey().

155  {
156  std::ostringstream oss;
157  switch (type_) {
159  oss << has_nulls_ << "|" << std::to_string(int_min_) << "|"
161  break;
164  oss << has_nulls_ << "|" << std::to_string(fp_min_) << "|"
166  break;
167  default:
168  oss << "INVALID";
169  break;
170  }
171  oss << "|" << std::to_string(bucket_);
172  return oss.str();
173  }
std::string to_string(char const *&&v)
ExpressionRangeType type_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ExpressionRange::typeSupportsRange ( const SQLTypeInfo ti)
static

Definition at line 279 of file ExpressionRange.cpp.

References SQLTypeInfo::get_compression(), SQLTypeInfo::get_elem_type(), SQLTypeInfo::is_array(), SQLTypeInfo::is_boolean(), SQLTypeInfo::is_number(), SQLTypeInfo::is_string(), SQLTypeInfo::is_time(), and kENCODING_DICT.

Referenced by Executor::computeColRangesCache(), and getExpressionRange().

279  {
280  if (ti.is_array()) {
281  return typeSupportsRange(ti.get_elem_type());
282  } else {
283  return (ti.is_number() || ti.is_boolean() || ti.is_time() ||
284  (ti.is_string() && ti.get_compression() == kENCODING_DICT));
285  }
286 }
bool is_number() const
Definition: sqltypes.h:524
bool is_time() const
Definition: sqltypes.h:525
bool is_boolean() const
Definition: sqltypes.h:526
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:337
static bool typeSupportsRange(const SQLTypeInfo &ti)
bool is_string() const
Definition: sqltypes.h:519
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:861
bool is_array() const
Definition: sqltypes.h:527

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

union { ... }
union { ... }
int64_t ExpressionRange::bucket_
private

Definition at line 248 of file ExpressionRange.h.

Referenced by getBucket(), operator||(), and toString().

double ExpressionRange::fp_max_

Definition at line 246 of file ExpressionRange.h.

Referenced by binOp(), getFpMax(), operator==(), operator||(), setFpMax(), and toString().

double ExpressionRange::fp_min_

Definition at line 242 of file ExpressionRange.h.

Referenced by binOp(), getFpMin(), operator==(), operator||(), setFpMin(), and toString().

bool ExpressionRange::has_nulls_
private

Definition at line 239 of file ExpressionRange.h.

Referenced by binOp(), hasNulls(), operator==(), operator||(), setHasNulls(), setNulls(), and toString().

int64_t ExpressionRange::int_max_
int64_t ExpressionRange::int_min_

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