|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eigenbase.rel.rules.ReduceDecimalsRule.RexExpander
public abstract class ReduceDecimalsRule.RexExpander
Rewrites a decimal expression for a specific set of SqlOperator's. In
general, most expressions are rewritten in such a way that SqlOperator's
do not have to deal with decimals. Decimals are represented by their
unscaled integer representations, similar to 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.
Field Summary | |
---|---|
(package private) RexBuilder |
builder
Factory for constructing new relational expressions |
(package private) RelDataType |
int8
Type for the internal representation of decimals. |
(package private) RelDataType |
real8
Type for doubles. |
Constructor Summary | |
---|---|
ReduceDecimalsRule.RexExpander(RexBuilder builder)
Constructs a RexExpander |
Method Summary | |
---|---|
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 RelDataType |
matchNullability(RelDataType type,
RexNode value)
Ensure's type's nullability matches a value's nullability |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
RexBuilder builder
RelDataType int8
RelDataType real8
Constructor Detail |
---|
public ReduceDecimalsRule.RexExpander(RexBuilder builder)
Method Detail |
---|
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 - 1
protected RexNode makeApproxScaleFactor(int scale)
scale
- a scale from -99 to 99
protected RexNode makeRoundFactor(int scale)
scale
- a scale from 1 to max precision - 1
protected 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 - 1
protected 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 precision
protected RexNode scaleDownDouble(RexNode value, int scale)
value
- the integer representation of a decimalscale
- a value from zero to MAX_NUMERIC_PRECISION
protected 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 numerics
protected RexNode decodeValue(RexNode decimalNode)
decimalNode
- the decimal value as an opaque type
protected RexNode accessValue(RexNode node)
node
- a numeric node, possibly a decimal
protected RexNode encodeValue(RexNode value, RelDataType decimalType)
This method does not request an overflow check.
value
- integer representation of decimaldecimalType
- type integer will be reinterpreted as
protected 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
- expression
protected 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 nullability
protected RelDataType matchNullability(RelDataType type, RexNode value)
protected RexNode makeCase(RexNode condition, RexNode thenClause, RexNode elseClause)
protected RexNode makeCase(RexNode whenA, RexNode thenA, RexNode whenB, RexNode thenB, RexNode elseClause)
protected RexNode makePlus(RexNode a, RexNode b)
protected RexNode makeMinus(RexNode a, RexNode b)
protected RexNode makeDivide(RexNode a, RexNode b)
protected RexNode makeMultiply(RexNode a, RexNode b)
protected RexNode makeIsPositive(RexNode a)
protected RexNode makeIsNegative(RexNode a)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |