Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
|
#include <decimal-value.h>
Public Member Functions | |
DecimalValue () | |
DecimalValue (const T &s) | |
DecimalValue & | operator= (const T &s) |
bool | operator== (const DecimalValue &other) const |
bool | operator!= (const DecimalValue &other) const |
bool | operator<= (const DecimalValue &other) const |
bool | operator< (const DecimalValue &other) const |
bool | operator>= (const DecimalValue &other) const |
bool | operator> (const DecimalValue &other) const |
DecimalValue | operator- () const |
bool | is_negative () const |
int | Compare (const DecimalValue &other) const |
DecimalValue | ScaleTo (const ColumnType &src_type, const ColumnType &dst_type, bool *overflow) const |
template<typename RESULT_T > | |
DecimalValue< RESULT_T > | Add (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type, int result_scale, bool *overflow) const |
template<typename RESULT_T > | |
DecimalValue< RESULT_T > | Subtract (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type, int result_scale, bool *overflow) const |
template<typename RESULT_T > | |
DecimalValue< RESULT_T > | Multiply (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type, int result_scale, bool *overflow) const |
template<typename RESULT_T > | |
DecimalValue< RESULT_T > | Divide (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type, int result_scale, bool *is_nan, bool *overflow) const |
is_nan is set to true if 'other' is 0. The value returned is undefined. More... | |
template<typename RESULT_T > | |
DecimalValue< RESULT_T > | Mod (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type, int result_scale, bool *is_nan, bool *overflow) const |
is_nan is set to true if 'other' is 0. The value returned is undefined. More... | |
int | Compare (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
bool | Eq (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
Comparison utilities. More... | |
bool | Ne (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
bool | Ge (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
bool | Gt (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
bool | Le (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
bool | Lt (const ColumnType &this_type, const DecimalValue &other, const ColumnType &other_type) const |
const T & | value () const |
T & | value () |
const T | whole_part (const ColumnType &t) const |
Returns the value of the decimal before the decimal point. More... | |
const T | fractional_part (const ColumnType &t) const |
Returns the value of the decimal after the decimal point. More... | |
double | ToDouble (const ColumnType &type) const |
Returns an approximate double for this decimal. More... | |
uint32_t | Hash (int seed=0) const |
std::string | ToString (const ColumnType &type) const |
DecimalValue< T > | Abs () const |
Static Public Member Functions | |
static DecimalValue | FromDouble (const ColumnType &t, double d, bool *overflow) |
static DecimalValue | FromInt (const ColumnType &t, int64_t d, bool *overflow) |
Assigns *result as a decimal. More... | |
Static Private Member Functions | |
template<typename RESULT_T > | |
static bool | AdjustToSameScale (const DecimalValue &x, const ColumnType &x_type, const DecimalValue &y, const ColumnType &y_type, RESULT_T *x_scaled, RESULT_T *y_scaled) |
Private Attributes | |
T | value_ |
Implementation of decimal types. The type is parametrized on the underlying storage type, which must implement all operators (example of a storage type is int32_t). The decimal does not store its precision and scale since we'd like to keep the storage as small as possible. Overflow handling: anytime the value is assigned, we need to consider overflow. Overflow is handled by an output return parameter. Functions should set this to true if overflow occured and leave it unchanged otherwise (e.g. |= rather than =). This allows the caller to not have to check overflow after every call.
Definition at line 40 of file decimal-value.h.
|
inline |
Definition at line 42 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::FromDouble(), impala::DecimalValue< int128_t >::FromInt(), impala::DecimalValue< int128_t >::operator-(), and impala::DecimalValue< int128_t >::ScaleTo().
|
inline |
Definition at line 43 of file decimal-value.h.
|
inline |
Definition at line 309 of file decimal-value.h.
|
inline |
Implementations of the basic arithmetic operators. In all these functions, we take the precision and scale of both inputs. The return type is assumed to be known by the caller (generated by the planner). Although these functions accept the result scale, that should be seen as an optimization to avoid having to recompute it in the function. The functions implement the SQL decimal rules only so other result scales are not valid. RESULT_T needs to be larger than T to avoid overflow issues.
Definition at line 147 of file decimal-value.h.
Referenced by impala::TEST().
|
inlinestaticprivate |
Returns in *x_val and *y_val, the adjusted values so that both are at the same scale. The scale is the number of digits after the decimal. Returns true if the adjusted causes overflow in which case the values in x_scaled and y_scaled are unmodified.
Definition at line 319 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::Add(), and impala::DecimalValue< int128_t >::Mod().
|
inline |
Compares this and other. Returns 0 if equal, < 0 if this < other and > 0 if this > other.
Definition at line 108 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::Eq(), impala::DecimalValue< int128_t >::Ge(), impala::DecimalValue< int128_t >::Gt(), impala::DecimalValue< int128_t >::Le(), impala::DecimalValue< int128_t >::Lt(), impala::DecimalValue< int128_t >::Ne(), and impala::TEST().
int impala::DecimalValue< T >::Compare | ( | const ColumnType & | this_type, |
const DecimalValue< T > & | other, | ||
const ColumnType & | other_type | ||
) | const |
Compares this and other. Returns 0 if equal, < 0 if this < other and > 0 if this > other.
|
inline |
is_nan is set to true if 'other' is 0. The value returned is undefined.
Definition at line 205 of file decimal-value.h.
Referenced by impala::AggregateFunctions::DecimalAvgGetValue(), and impala::TEST().
|
inline |
Comparison utilities.
Definition at line 258 of file decimal-value.h.
|
inline |
Returns the value of the decimal after the decimal point.
Definition at line 294 of file decimal-value.h.
|
inlinestatic |
Returns the closest Decimal to 'd' of type 't', truncating digits that cannot be represented.
Definition at line 52 of file decimal-value.h.
|
inlinestatic |
Assigns *result as a decimal.
Definition at line 67 of file decimal-value.h.
|
inline |
Definition at line 266 of file decimal-value.h.
|
inline |
Definition at line 270 of file decimal-value.h.
|
inline |
Definition at line 303 of file decimal-value.h.
Referenced by impala::hash_value().
|
inline |
Definition at line 104 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::Add().
|
inline |
Definition at line 274 of file decimal-value.h.
|
inline |
Definition at line 278 of file decimal-value.h.
|
inline |
is_nan is set to true if 'other' is 0. The value returned is undefined.
Definition at line 236 of file decimal-value.h.
Referenced by impala::TEST().
|
inline |
Definition at line 174 of file decimal-value.h.
Referenced by impala::TEST().
|
inline |
Definition at line 262 of file decimal-value.h.
|
inline |
Definition at line 84 of file decimal-value.h.
|
inline |
Definition at line 100 of file decimal-value.h.
|
inline |
Definition at line 90 of file decimal-value.h.
|
inline |
Definition at line 87 of file decimal-value.h.
|
inline |
Definition at line 45 of file decimal-value.h.
|
inline |
The overloaded operators assume that this and other have the same scale. They are more efficient than the comparison functions that handle differing scale and should be used if the scales are known to be the same. (e.g. min(decimal_col) or order by decimal_col.
Definition at line 81 of file decimal-value.h.
|
inline |
Definition at line 96 of file decimal-value.h.
|
inline |
Definition at line 93 of file decimal-value.h.
|
inline |
Returns a new decimal scaled by from src_type to dst_type. e.g. If this value was 1100 at scale 3 and the dst_type had scale two, the result would be 110. (In both cases representing the decimal 1.1).
Definition at line 119 of file decimal-value.h.
Referenced by impala::DecimalOperators::ScaleDecimalValue().
|
inline |
Definition at line 168 of file decimal-value.h.
Referenced by impala::TEST().
|
inline |
Returns an approximate double for this decimal.
Definition at line 299 of file decimal-value.h.
Referenced by impala::DecimalOperators::CastToTimestampVal(), and impala::TEST().
|
inline |
Returns as string with full 0 padding on the right and single 0 padded on the left if the whole part is zero otherwise there will be no left padding.
Definition at line 449 of file decimal-value.h.
References impala::ColumnType::precision, impala::ColumnType::scale, impala::ColumnType::type, and impala::TYPE_DECIMAL.
Referenced by impala::DecimalOperators::CastToStringVal(), impala::Literal::DebugString(), and impala::TEST().
|
inline |
Returns the underlying storage. For a particular storage size, there is only one representation for any decimal and the storage is directly comparable.
Definition at line 285 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::AdjustToSameScale(), impala::DecimalOperators::CastToDecimalVal(), impala::DecimalValue< int128_t >::Compare(), impala::AggregateFunctions::DecimalAvgGetValue(), impala::DecimalValue< int128_t >::Divide(), impala::DecimalOperators::FloatToDecimalVal(), impala::DecimalValue< int128_t >::fractional_part(), impala::Literal::GetCodegendComputeFn(), impala::Literal::GetDecimalVal(), impala::IncrementValue(), impala::DecimalOperators::IntToDecimalVal(), impala::DecimalValue< int128_t >::Mod(), impala::DecimalValue< int128_t >::Multiply(), impala::operator<<(), impala::DecimalOperators::RoundDecimalNegativeScale(), impala::DecimalOperators::RoundDelta(), impala::DecimalOperators::ScaleDecimalValue(), impala::DecimalValue< int128_t >::ScaleTo(), impala::TEST(), impala::ToDecimal16(), impala::ToDecimal4(), impala::ToDecimal8(), and impala::DecimalValue< int128_t >::whole_part().
|
inline |
Definition at line 286 of file decimal-value.h.
|
inline |
Returns the value of the decimal before the decimal point.
Definition at line 289 of file decimal-value.h.
|
private |
Definition at line 312 of file decimal-value.h.
Referenced by impala::DecimalValue< int128_t >::Abs(), impala::DecimalValue< int128_t >::Hash(), impala::DecimalValue< int128_t >::is_negative(), impala::DecimalValue< int128_t >::operator!=(), impala::DecimalValue< int128_t >::operator-(), impala::DecimalValue< int128_t >::operator<(), impala::DecimalValue< int128_t >::operator<=(), impala::DecimalValue< int128_t >::operator=(), impala::DecimalValue< int128_t >::operator==(), impala::DecimalValue< int128_t >::operator>(), impala::DecimalValue< int128_t >::operator>=(), impala::DecimalValue< int128_t >::ToDouble(), and impala::DecimalValue< int128_t >::value().