OmniSciDB  5ade3759e0
DecimalOverflowValidator Class Reference

#include <Encoder.h>

Public Member Functions

 DecimalOverflowValidator (SQLTypeInfo type)
 
template<typename T >
void validate (T value)
 
void do_validate (int64_t value)
 

Private Attributes

bool do_check_
 
int64_t max_
 
int64_t min_
 
int pow10_
 

Detailed Description

Definition at line 38 of file Encoder.h.

Constructor & Destructor Documentation

◆ DecimalOverflowValidator()

DecimalOverflowValidator::DecimalOverflowValidator ( SQLTypeInfo  type)
inline

Definition at line 40 of file Encoder.h.

References SQLTypeInfoCore< TYPE_FACET_PACK >::get_elem_type(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_precision(), SQLTypeInfoCore< TYPE_FACET_PACK >::get_scale(), SQLTypeInfoCore< TYPE_FACET_PACK >::is_array(), and SQLTypeInfoCore< TYPE_FACET_PACK >::is_decimal().

40  {
41  if (type.is_array()) {
42  type = type.get_elem_type();
43  }
44 
45  do_check_ = type.is_decimal();
46  int precision = type.get_precision();
47  int scale = type.get_scale();
48  max_ = (int64_t)std::pow((double)10.0, precision);
49  min_ = -max_;
50  pow10_ = precision - scale;
51  }
int get_precision() const
Definition: sqltypes.h:326
HOST DEVICE int get_scale() const
Definition: sqltypes.h:328
bool is_array() const
Definition: sqltypes.h:458
bool is_decimal() const
Definition: sqltypes.h:453
SQLTypeInfoCore get_elem_type() const
Definition: sqltypes.h:632
+ Here is the call graph for this function:

Member Function Documentation

◆ do_validate()

void DecimalOverflowValidator::do_validate ( int64_t  value)
inline

Definition at line 60 of file Encoder.h.

References to_string().

60  {
61  if (!do_check_) {
62  return;
63  }
64 
65  if (value >= max_) {
66  throw std::runtime_error("Decimal overflow: value is greater than 10^" +
68  " value " + std::to_string(value));
69  }
70 
71  if (value <= min_) {
72  throw std::runtime_error("Decimal overflow: value is less than -10^" +
74  " value " + std::to_string(value));
75  }
76  }
std::string to_string(char const *&&v)
+ Here is the call graph for this function:

◆ validate()

template<typename T >
void DecimalOverflowValidator::validate ( value)
inline

Definition at line 54 of file Encoder.h.

Referenced by FixedLengthEncoder< T, V >::appendData(), NoneEncoder< T >::appendData(), and FixedLengthArrayNoneEncoder::update_elem_stats().

54  {
55  if (std::is_integral<T>::value) {
56  do_validate(static_cast<int64_t>(value));
57  }
58  }
void do_validate(int64_t value)
Definition: Encoder.h:60
+ Here is the caller graph for this function:

Member Data Documentation

◆ do_check_

bool DecimalOverflowValidator::do_check_
private

Definition at line 79 of file Encoder.h.

◆ max_

int64_t DecimalOverflowValidator::max_
private

Definition at line 80 of file Encoder.h.

◆ min_

int64_t DecimalOverflowValidator::min_
private

Definition at line 81 of file Encoder.h.

◆ pow10_

int DecimalOverflowValidator::pow10_
private

Definition at line 82 of file Encoder.h.


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