Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::DecimalOperators Class Reference

#include <decimal-operators.h>

Collaboration diagram for impala::DecimalOperators:

Public Types

enum  DecimalRoundOp { TRUNCATE, FLOOR, CEIL, ROUND }
 

Static Public Member Functions

static DecimalVal CastToDecimalVal (FunctionContext *, const DecimalVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const TinyIntVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const SmallIntVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const IntVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const BigIntVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const FloatVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const DoubleVal &)
 
static DecimalVal CastToDecimalVal (FunctionContext *, const StringVal &)
 
static BooleanVal CastToBooleanVal (FunctionContext *, const DecimalVal &)
 
static TinyIntVal CastToTinyIntVal (FunctionContext *, const DecimalVal &)
 
static SmallIntVal CastToSmallIntVal (FunctionContext *, const DecimalVal &)
 
static IntVal CastToIntVal (FunctionContext *, const DecimalVal &)
 
static BigIntVal CastToBigIntVal (FunctionContext *, const DecimalVal &)
 
static FloatVal CastToFloatVal (FunctionContext *, const DecimalVal &)
 
static DoubleVal CastToDoubleVal (FunctionContext *, const DecimalVal &)
 
static StringVal CastToStringVal (FunctionContext *, const DecimalVal &)
 
static TimestampVal CastToTimestampVal (FunctionContext *, const DecimalVal &)
 
static DecimalVal Add_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static DecimalVal Subtract_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static DecimalVal Multiply_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static DecimalVal Divide_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static DecimalVal Mod_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Eq_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Ne_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Ge_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Gt_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Le_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static BooleanVal Lt_DecimalVal_DecimalVal (FunctionContext *, const DecimalVal &, const DecimalVal &)
 
static DecimalVal RoundDecimal (FunctionContext *context, const DecimalVal &val, const ColumnType &val_type, const ColumnType &output_type, const DecimalRoundOp &op)
 
static DecimalVal RoundDecimal (FunctionContext *context, const DecimalVal &val, const DecimalRoundOp &op)
 
static DecimalVal RoundDecimalNegativeScale (FunctionContext *context, const DecimalVal &val, const ColumnType &val_type, const ColumnType &output_type, const DecimalRoundOp &op, int64_t rounding_scale)
 

Static Private Member Functions

static DecimalVal IntToDecimalVal (FunctionContext *context, const ColumnType &type, int64_t val)
 Converts 'val' to a DecimalVal according to 'type'. 'type' must be a decimal type. More...
 
static DecimalVal FloatToDecimalVal (FunctionContext *context, const ColumnType &type, double val)
 
static DecimalVal ScaleDecimalValue (FunctionContext *context, const Decimal4Value &val, const ColumnType &val_type, const ColumnType &output_type)
 Returns the value of 'val' scaled to 'output_type'. More...
 
static DecimalVal ScaleDecimalValue (FunctionContext *context, const Decimal8Value &val, const ColumnType &val_type, const ColumnType &output_type)
 
static DecimalVal ScaleDecimalValue (FunctionContext *context, const Decimal16Value &val, const ColumnType &val_type, const ColumnType &output_type)
 
template<typename T >
static T RoundDelta (const DecimalValue< T > &v, int src_scale, int target_scale, const DecimalRoundOp &op)
 

Detailed Description

Implementation of the decimal operators. These include the cast, arithmetic and binary operators.

Definition at line 33 of file decimal-operators.h.

Member Enumeration Documentation

The rounding rule when converting decimals. These only apply going from a higher scale to a lower one.

Enumerator
TRUNCATE 

Additional digits are dropped.

FLOOR 

Returns largest value not greater than the value. (digits are dropped for positive values and rounded away from zero for negative values)

CEIL 

Returns smallest value not smaller than the value. (rounded away from zero for positive values and extra digits dropped for negative values)

ROUND 

Rounded towards zero if the extra digits are less than .5 and away from zero otherwise.

Definition at line 81 of file decimal-operators.h.

Member Function Documentation

static DecimalVal impala::DecimalOperators::Add_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BigIntVal impala::DecimalOperators::CastToBigIntVal ( FunctionContext ,
const DecimalVal  
)
static
DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext context,
const DecimalVal val 
)
static

Definition at line 435 of file decimal-operators.cc.

References RoundDecimal(), and TRUNCATE.

Referenced by impala::Expr::InitBuiltinsDummy().

static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const TinyIntVal  
)
static
static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const SmallIntVal  
)
static
static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const IntVal  
)
static
static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const BigIntVal  
)
static
static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const FloatVal  
)
static
static DecimalVal impala::DecimalOperators::CastToDecimalVal ( FunctionContext ,
const DoubleVal  
)
static
static DoubleVal impala::DecimalOperators::CastToDoubleVal ( FunctionContext ,
const DecimalVal  
)
static
static FloatVal impala::DecimalOperators::CastToFloatVal ( FunctionContext ,
const DecimalVal  
)
static
static IntVal impala::DecimalOperators::CastToIntVal ( FunctionContext ,
const DecimalVal  
)
static
static SmallIntVal impala::DecimalOperators::CastToSmallIntVal ( FunctionContext ,
const DecimalVal  
)
static
static TinyIntVal impala::DecimalOperators::CastToTinyIntVal ( FunctionContext ,
const DecimalVal  
)
static
static DecimalVal impala::DecimalOperators::Divide_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BooleanVal impala::DecimalOperators::Eq_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BooleanVal impala::DecimalOperators::Ge_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BooleanVal impala::DecimalOperators::Gt_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
DecimalVal impala::DecimalOperators::IntToDecimalVal ( FunctionContext context,
const ColumnType type,
int64_t  val 
)
inlinestaticprivate
static BooleanVal impala::DecimalOperators::Le_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BooleanVal impala::DecimalOperators::Lt_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static DecimalVal impala::DecimalOperators::Mod_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static DecimalVal impala::DecimalOperators::Multiply_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
static BooleanVal impala::DecimalOperators::Ne_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static
DecimalVal impala::DecimalOperators::RoundDecimal ( FunctionContext context,
const DecimalVal val,
const DecimalRoundOp op 
)
static

Same as above but infers 'val_type' from the first argument type and 'output_type' from the return type according to 'context'.

Definition at line 425 of file decimal-operators.cc.

References impala_udf::FunctionContext::GetArgType(), impala_udf::FunctionContext::GetReturnType(), RoundDecimal(), and impala::AnyValUtil::TypeDescToColumnType().

DecimalVal impala::DecimalOperators::RoundDecimalNegativeScale ( FunctionContext context,
const DecimalVal val,
const ColumnType val_type,
const ColumnType output_type,
const DecimalRoundOp op,
int64_t  rounding_scale 
)
static

Handles the case of rounding to a negative scale. This means rounding to a digit before the decimal point. rounding_scale is the number of digits before the decimal to round to. TODO: can this code be reorganized to combine the two version of RoundDecimal()? The implementation is similar but not quite the same. This code is, in general, harder to read because there are multiple input/output types to handle and all combinations are valid. Another option might be to use templates to generate each pair: Decimal4Value Round(const Decimal4Value&); Decimal8Value Round(const Decimal4Value&); Decimal4Value Round(const Decimal8Value&); etc.

Definition at line 306 of file decimal-operators.cc.

References impala::abs(), impala_udf::AnyVal::is_null, impala::DecimalUtil::MAX_UNSCALED_DECIMAL, impala_udf::DecimalVal::val16, impala_udf::DecimalVal::val4, impala_udf::DecimalVal::val8, and impala::DecimalValue< T >::value().

Referenced by impala::DecimalFunctions::RoundTo().

template<typename T >
static T impala::DecimalOperators::RoundDelta ( const DecimalValue< T > &  v,
int  src_scale,
int  target_scale,
const DecimalRoundOp op 
)
inlinestaticprivate

Returns the delta that needs to be added when the source decimal is rounded to target scale. Returns 0, if no rounding is necessary, or -1/1 if rounding is required.

Definition at line 147 of file decimal-operators.h.

References impala::abs(), and impala::DecimalValue< T >::value().

Referenced by RoundDecimal().

DecimalVal impala::DecimalOperators::ScaleDecimalValue ( FunctionContext context,
const Decimal4Value val,
const ColumnType val_type,
const ColumnType output_type 
)
inlinestaticprivate
DecimalVal impala::DecimalOperators::ScaleDecimalValue ( FunctionContext context,
const Decimal8Value val,
const ColumnType val_type,
const ColumnType output_type 
)
inlinestaticprivate
DecimalVal impala::DecimalOperators::ScaleDecimalValue ( FunctionContext context,
const Decimal16Value val,
const ColumnType val_type,
const ColumnType output_type 
)
inlinestaticprivate
static DecimalVal impala::DecimalOperators::Subtract_DecimalVal_DecimalVal ( FunctionContext ,
const DecimalVal ,
const DecimalVal  
)
static

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