Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::DecimalValue< T > Class Template Reference

#include <decimal-value.h>

Collaboration diagram for impala::DecimalValue< T >:

Public Member Functions

 DecimalValue ()
 
 DecimalValue (const T &s)
 
DecimalValueoperator= (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

value_
 

Detailed Description

template<typename T>
class impala::DecimalValue< T >

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.

Constructor & Destructor Documentation

template<typename T>
impala::DecimalValue< T >::DecimalValue ( const T &  s)
inline

Definition at line 43 of file decimal-value.h.

Member Function Documentation

template<typename T>
DecimalValue<T> impala::DecimalValue< T >::Abs ( ) const
inline

Definition at line 309 of file decimal-value.h.

template<typename T>
template<typename RESULT_T >
DecimalValue<RESULT_T> impala::DecimalValue< T >::Add ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type,
int  result_scale,
bool overflow 
) const
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().

template<typename T>
template<typename RESULT_T >
static bool impala::DecimalValue< T >::AdjustToSameScale ( const DecimalValue< T > &  x,
const ColumnType x_type,
const DecimalValue< T > &  y,
const ColumnType y_type,
RESULT_T *  x_scaled,
RESULT_T *  y_scaled 
)
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().

template<typename T>
int impala::DecimalValue< T >::Compare ( const DecimalValue< T > &  other) const
inline
template<typename T>
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.

template<typename T>
template<typename RESULT_T >
DecimalValue<RESULT_T> impala::DecimalValue< T >::Divide ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type,
int  result_scale,
bool is_nan,
bool overflow 
) const
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().

template<typename T>
bool impala::DecimalValue< T >::Eq ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Comparison utilities.

Definition at line 258 of file decimal-value.h.

template<typename T>
const T impala::DecimalValue< T >::fractional_part ( const ColumnType t) const
inline

Returns the value of the decimal after the decimal point.

Definition at line 294 of file decimal-value.h.

template<typename T>
static DecimalValue impala::DecimalValue< T >::FromDouble ( const ColumnType t,
double  d,
bool overflow 
)
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.

template<typename T>
static DecimalValue impala::DecimalValue< T >::FromInt ( const ColumnType t,
int64_t  d,
bool overflow 
)
inlinestatic

Assigns *result as a decimal.

Definition at line 67 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::Ge ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Definition at line 266 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::Gt ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Definition at line 270 of file decimal-value.h.

template<typename T>
uint32_t impala::DecimalValue< T >::Hash ( int  seed = 0) const
inline

Definition at line 303 of file decimal-value.h.

Referenced by impala::hash_value().

template<typename T>
bool impala::DecimalValue< T >::is_negative ( ) const
inline

Definition at line 104 of file decimal-value.h.

Referenced by impala::DecimalValue< int128_t >::Add().

template<typename T>
bool impala::DecimalValue< T >::Le ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Definition at line 274 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::Lt ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Definition at line 278 of file decimal-value.h.

template<typename T>
template<typename RESULT_T >
DecimalValue<RESULT_T> impala::DecimalValue< T >::Mod ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type,
int  result_scale,
bool is_nan,
bool overflow 
) const
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().

template<typename T>
template<typename RESULT_T >
DecimalValue<RESULT_T> impala::DecimalValue< T >::Multiply ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type,
int  result_scale,
bool overflow 
) const
inline

Definition at line 174 of file decimal-value.h.

Referenced by impala::TEST().

template<typename T>
bool impala::DecimalValue< T >::Ne ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type 
) const
inline

Definition at line 262 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::operator!= ( const DecimalValue< T > &  other) const
inline

Definition at line 84 of file decimal-value.h.

template<typename T>
DecimalValue impala::DecimalValue< T >::operator- ( ) const
inline

Definition at line 100 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::operator< ( const DecimalValue< T > &  other) const
inline

Definition at line 90 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::operator<= ( const DecimalValue< T > &  other) const
inline

Definition at line 87 of file decimal-value.h.

template<typename T>
DecimalValue& impala::DecimalValue< T >::operator= ( const T &  s)
inline

Definition at line 45 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::operator== ( const DecimalValue< T > &  other) const
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.

template<typename T>
bool impala::DecimalValue< T >::operator> ( const DecimalValue< T > &  other) const
inline

Definition at line 96 of file decimal-value.h.

template<typename T>
bool impala::DecimalValue< T >::operator>= ( const DecimalValue< T > &  other) const
inline

Definition at line 93 of file decimal-value.h.

template<typename T>
DecimalValue impala::DecimalValue< T >::ScaleTo ( const ColumnType src_type,
const ColumnType dst_type,
bool overflow 
) const
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().

template<typename T>
template<typename RESULT_T >
DecimalValue<RESULT_T> impala::DecimalValue< T >::Subtract ( const ColumnType this_type,
const DecimalValue< T > &  other,
const ColumnType other_type,
int  result_scale,
bool overflow 
) const
inline

Definition at line 168 of file decimal-value.h.

Referenced by impala::TEST().

template<typename T>
double impala::DecimalValue< T >::ToDouble ( const ColumnType type) const
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().

template<typename T >
std::string impala::DecimalValue< T >::ToString ( const ColumnType type) const
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().

template<typename T>
T& impala::DecimalValue< T >::value ( )
inline

Definition at line 286 of file decimal-value.h.

template<typename T>
const T impala::DecimalValue< T >::whole_part ( const ColumnType t) const
inline

Returns the value of the decimal before the decimal point.

Definition at line 289 of file decimal-value.h.

Member Data Documentation


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