OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecimalOverflowValidator Class Reference

#include <Encoder.h>

Public Member Functions

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

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 ( SQLTypeInfo  type)
inline

Definition at line 40 of file Encoder.h.

References do_check_, SQLTypeInfo::get_elem_type(), SQLTypeInfo::get_precision(), SQLTypeInfo::get_scale(), SQLTypeInfo::is_array(), SQLTypeInfo::is_decimal(), max_, min_, and pow10_.

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  }
HOST DEVICE int get_scale() const
Definition: sqltypes.h:396
int get_precision() const
Definition: sqltypes.h:394
SQLTypeInfo get_elem_type() const
Definition: sqltypes.h:975
bool is_decimal() const
Definition: sqltypes.h:568
bool is_array() const
Definition: sqltypes.h:583

+ Here is the call graph for this function:

Member Function Documentation

void DecimalOverflowValidator::do_validate ( int64_t  value) const
inline

Definition at line 60 of file Encoder.h.

References do_check_, max_, min_, pow10_, and to_string().

Referenced by validate().

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:

+ Here is the caller graph for this function:

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

Definition at line 54 of file Encoder.h.

References do_validate().

Referenced by import_export::TypedImportBuffer::add_value(), FixedLengthEncoder< T, V >::encodeDataAndUpdateStats(), FixedLengthArrayNoneEncoder::update_elem_stats(), FixedLengthEncoder< T, V >::updateStatsEncoded(), NoneEncoder< T >::updateStatsEncoded(), foreign_storage::ParquetDecimalEncoder< V, T, NullType >::validate(), ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal(), and NoneEncoder< T >::validateDataAndUpdateStats().

54  {
55  if (std::is_integral<T>::value) {
56  do_validate(static_cast<int64_t>(value));
57  }
58  }
void do_validate(int64_t value) const
Definition: Encoder.h:60

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool DecimalOverflowValidator::do_check_
private

Definition at line 79 of file Encoder.h.

Referenced by DecimalOverflowValidator(), and do_validate().

int64_t DecimalOverflowValidator::max_
private

Definition at line 80 of file Encoder.h.

Referenced by DecimalOverflowValidator(), and do_validate().

int64_t DecimalOverflowValidator::min_
private

Definition at line 81 of file Encoder.h.

Referenced by DecimalOverflowValidator(), and do_validate().

int DecimalOverflowValidator::pow10_
private

Definition at line 82 of file Encoder.h.

Referenced by DecimalOverflowValidator(), and do_validate().


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