OmniSciDB  a5dc49c757
 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 57 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 177 of file ExpressionRange.h.

182  , has_nulls_(has_nulls_in)
183  , int_min_(int_min_in)
184  , int_max_(int_max_in)
185  , 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 187 of file ExpressionRange.h.

References CHECK, Double, Float, and type_.

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

Definition at line 199 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 202 of file ExpressionRange.h.

References CHECK, Null, and type_.

203  : type_(type), has_nulls_(true), bucket_(0) {
205  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

Member Function Documentation

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

Definition at line 208 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_.

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

+ Here is the call graph for this function:

int64_t ExpressionRange::getBucket ( ) const
inline

Definition at line 132 of file ExpressionRange.h.

References bucket_, CHECK, Invalid, and type_.

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

132  {
134  return bucket_;
135  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

double ExpressionRange::getFpMax ( ) const
inline

Definition at line 99 of file ExpressionRange.h.

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

Referenced by getExpressionRange().

99  {
101  return fp_max_;
102  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

double ExpressionRange::getFpMin ( ) const
inline

Definition at line 94 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 130 of file ExpressionRange.h.

References type_.

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

130 { return type_; }
ExpressionRangeType type_

+ Here is the caller graph for this function:

bool ExpressionRange::hasNulls ( ) const
inline

Definition at line 137 of file ExpressionRange.h.

References CHECK, has_nulls_, Invalid, and type_.

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

137  {
139  return has_nulls_;
140  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

+ 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 66 of file ExpressionRange.h.

References Double, and ExpressionRange().

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

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

+ 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 72 of file ExpressionRange.h.

References ExpressionRange(), and Float.

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

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

+ 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 59 of file ExpressionRange.h.

References ExpressionRange().

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ExpressionRange ExpressionRange::makeInvalidRange ( )
inlinestatic

Definition at line 82 of file ExpressionRange.h.

References ExpressionRange().

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

82 { 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 78 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 206 of file ExpressionRange.cpp.

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

206  {
210  }
211  if (other.int_min_ * other.int_max_ <= 0) {
212  // if the other interval contains 0, the rule is more complicated;
213  // punt for now, we can revisit by splitting the other interval and
214  // taking the convex hull of the resulting two intervals
216  }
217  auto div_range = binOp<int64_t>(other, [](const int64_t x, const int64_t y) {
218  return int64_t(checked_int64_t(x) / y);
219  });
220  if (g_null_div_by_zero) {
221  div_range.setHasNulls();
222  }
223  return div_range;
224 }
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:95
ExpressionRangeType type_
static ExpressionRange makeInvalidRange()

+ Here is the call graph for this function:

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

Definition at line 256 of file ExpressionRange.cpp.

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

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

Definition at line 226 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_.

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

+ Here is the call graph for this function:

void ExpressionRange::setFpMax ( const double  fp_max)
inline

Definition at line 125 of file ExpressionRange.h.

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

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

Definition at line 120 of file ExpressionRange.h.

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

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

Definition at line 142 of file ExpressionRange.h.

References has_nulls_.

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

Definition at line 114 of file ExpressionRange.h.

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

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

Definition at line 109 of file ExpressionRange.h.

References CHECK, int_max_, Integer, and type_.

Referenced by apply_int_qual().

109  {
111  int_max_ = int_max;
112  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

void ExpressionRange::setIntMin ( const int64_t  int_min)
inline

Definition at line 104 of file ExpressionRange.h.

References CHECK, int_min_, Integer, and type_.

Referenced by apply_int_qual().

104  {
106  int_min_ = int_min;
107  }
ExpressionRangeType type_
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function:

void ExpressionRange::setNulls ( bool  n)
inline

Definition at line 144 of file ExpressionRange.h.

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

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

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

156  {
157  std::ostringstream oss;
158  switch (type_) {
160  oss << has_nulls_ << "|" << std::to_string(int_min_) << "|"
162  break;
165  oss << has_nulls_ << "|" << std::to_string(fp_min_) << "|"
167  break;
168  default:
169  oss << "INVALID";
170  break;
171  }
172  oss << "|" << std::to_string(bucket_);
173  return oss.str();
174  }
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 278 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().

278  {
279  if (ti.is_array()) {
280  return typeSupportsRange(ti.get_elem_type());
281  } else {
282  return (ti.is_number() || ti.is_boolean() || ti.is_time() ||
283  (ti.is_string() && ti.get_compression() == kENCODING_DICT));
284  }
285 }
bool is_number() const
Definition: sqltypes.h:576
bool is_time() const
Definition: sqltypes.h:579
bool is_boolean() const
Definition: sqltypes.h:582
HOST DEVICE EncodingType get_compression() const
Definition: sqltypes.h:399
static bool typeSupportsRange(const SQLTypeInfo &ti)
bool is_string() const
Definition: sqltypes.h:561
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:977
bool is_array() const
Definition: sqltypes.h:585

+ 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 249 of file ExpressionRange.h.

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

double ExpressionRange::fp_max_

Definition at line 247 of file ExpressionRange.h.

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

double ExpressionRange::fp_min_

Definition at line 243 of file ExpressionRange.h.

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

bool ExpressionRange::has_nulls_
private

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