public abstract class ReduceDecimalsRule.RexExpander extends Object
BigDecimal.unscaledValue() (i.e. 10^scale). Once decimals are
decoded, SqlOperators can then operate on the integer representations. The
value can later be recoded as a decimal.
For example, suppose one casts 2.0 as a decima(10,4). The value is decoded (20), multiplied by a scale factor (1000), for a result of (20000) which is encoded as a decimal(10,4), in this case 2.0000
To avoid the lengthy coding of RexNode expressions, this base class provides succinct methods for building expressions used in rewrites.
| Constructor and Description |
|---|
ReduceDecimalsRule.RexExpander(RexBuilder builder)
Constructs a RexExpander
|
| Modifier and Type | Method and Description |
|---|---|
protected RexNode |
accessValue(RexNode node)
Retrieves the primitive value of a numeric node.
|
boolean |
canExpand(RexCall call)
This defaults to the utility method,
RexUtil.requiresDecimalExpansion(RexNode, boolean) which checks
general guidelines on whether a rewrite should be considered at all. |
protected RexNode |
decodeValue(RexNode decimalNode)
Retrieves a decimal node's integer representation
|
protected RexNode |
encodeValue(RexNode value,
RelDataType decimalType)
Casts a decimal's integer representation to a decimal node.
|
protected RexNode |
encodeValue(RexNode value,
RelDataType decimalType,
boolean checkOverflow)
Casts a decimal's integer representation to a decimal node.
|
protected RexNode |
ensureScale(RexNode value,
int scale,
int required)
Ensures a value is of a required scale.
|
protected RexNode |
ensureType(RelDataType type,
RexNode node)
Ensures expression is interpreted as a specified type.
|
protected RexNode |
ensureType(RelDataType type,
RexNode node,
boolean matchNullability)
Ensures expression is interpreted as a specified type.
|
abstract RexNode |
expand(RexCall call)
Rewrites an expression containing decimals.
|
protected RexNode |
makeApproxLiteral(BigDecimal bd)
Makes an approximate literal of double precision
|
protected RexNode |
makeApproxScaleFactor(int scale)
Makes an approximate literal to be used for scaling
|
protected RexNode |
makeCase(RexNode condition,
RexNode thenClause,
RexNode elseClause) |
protected RexNode |
makeCase(RexNode whenA,
RexNode thenA,
RexNode whenB,
RexNode thenB,
RexNode elseClause) |
protected RexNode |
makeDivide(RexNode a,
RexNode b) |
protected RexNode |
makeExactLiteral(long l)
Makes an exact, non-nullable literal of Bigint type
|
protected RexNode |
makeIsNegative(RexNode a) |
protected RexNode |
makeIsPositive(RexNode a) |
protected RexNode |
makeMinus(RexNode a,
RexNode b) |
protected RexNode |
makeMultiply(RexNode a,
RexNode b) |
protected RexNode |
makePlus(RexNode a,
RexNode b) |
protected RexNode |
makeRoundFactor(int scale)
Makes an exact numeric value to be used for rounding.
|
protected RexNode |
makeScaleFactor(int scale)
Makes an exact numeric literal to be used for scaling
|
protected long |
powerOfTen(int scale)
Calculates a power of ten, as a long value
|
protected RexNode |
scaleDown(RexNode value,
int scale)
Scales down a decimal value, and returns the scaled value as an exact
numeric.
|
protected RexNode |
scaleDownDouble(RexNode value,
int scale)
Scales down a decimal value and returns the scaled value as a an
double precision approximate value.
|
protected RexNode |
scaleUp(RexNode value,
int scale)
Scales up a decimal value and returns the scaled value as an exact
number.
|
public ReduceDecimalsRule.RexExpander(RexBuilder builder)
public boolean canExpand(RexCall call)
RexUtil.requiresDecimalExpansion(RexNode, boolean) which checks
general guidelines on whether a rewrite should be considered at all. In
general, it is helpful to update the utility method since that method is
often used to filter the somewhat expensive rewrite process.
However, this method provides another place for implementations of RexExpander to make a more detailed analysis before deciding on whether to perform a rewrite.
public abstract RexNode expand(RexCall call)
protected RexNode makeScaleFactor(int scale)
scale - a scale from one to max precision - 1protected RexNode makeApproxScaleFactor(int scale)
scale - a scale from -99 to 99protected RexNode makeRoundFactor(int scale)
scale - a scale from 1 to max precision - 1protected long powerOfTen(int scale)
protected RexNode makeExactLiteral(long l)
protected RexNode makeApproxLiteral(BigDecimal bd)
protected RexNode scaleUp(RexNode value, int scale)
value - the integer representation of a decimalscale - a value from zero to max precision - 1protected RexNode scaleDown(RexNode value, int scale)
BigDecimal.ROUND_HALF_UP. (Values midway
between two points are rounded away from zero.)value - the integer representation of a decimalscale - a value from zero to max precisionprotected RexNode scaleDownDouble(RexNode value, int scale)
value - the integer representation of a decimalscale - a value from zero to max precisionprotected RexNode ensureScale(RexNode value, int scale, int required)
value - integer representation of decimal, or a floating point
numberscale - current scale, 0 for floating point numbersrequired - required scale, must be at least the current scale;
the scale difference may not be greater than max
precision - 1 for exact numericsprotected RexNode decodeValue(RexNode decimalNode)
decimalNode - the decimal value as an opaque typeprotected RexNode accessValue(RexNode node)
node - a numeric node, possibly a decimalprotected RexNode encodeValue(RexNode value, RelDataType decimalType)
This method does not request an overflow check.
value - integer representation of decimaldecimalType - type integer will be reinterpreted asprotected RexNode encodeValue(RexNode value, RelDataType decimalType, boolean checkOverflow)
An overflow check may be requested to ensure the internal value does not exceed the maximum value of the decimal type.
value - integer representation of decimaldecimalType - type integer will be reinterpreted ascheckOverflow - indicates whether an overflow check is required
when reinterpreting this particular value as the
decimal type. A check usually not required for
arithmetic, but is often required for rounding and
explicit casts.protected RexNode ensureType(RelDataType type, RexNode node)
This method corrects the nullability of the specified type to match the nullability of the expression.
type - desired typenode - expressionprotected RexNode ensureType(RelDataType type, RexNode node, boolean matchNullability)
type - desired typenode - expressionmatchNullability - whether to correct nullability of specified
type to match the expression; this usually should
be true, except for explicit casts which can
override default nullabilityprotected RexNode makeCase(RexNode whenA, RexNode thenA, RexNode whenB, RexNode thenB, RexNode elseClause)
Copyright © 2012–2015 The Apache Software Foundation. All rights reserved.