org.eigenbase.rel.rules
Class ReduceDecimalsRule.ReinterpretExpander

java.lang.Object
  extended by org.eigenbase.rel.rules.ReduceDecimalsRule.RexExpander
      extended by org.eigenbase.rel.rules.ReduceDecimalsRule.ReinterpretExpander
Enclosing class:
ReduceDecimalsRule

private class ReduceDecimalsRule.ReinterpretExpander
extends ReduceDecimalsRule.RexExpander

This expander simplifies reinterpret calls. Consider (1.0+1)*1. The inner operation encodes a decimal (Reinterpret(...)) which the outer operation immediately decodes: (Reinterpret(Reinterpret(...))). Arithmetic overflow is handled by underlying integer operations, so we don't have to consider it. Simply remove the nested Reinterpret.


Field Summary
 
Fields inherited from class org.eigenbase.rel.rules.ReduceDecimalsRule.RexExpander
builder, int8, real8
 
Constructor Summary
private ReduceDecimalsRule.ReinterpretExpander(RexBuilder builder)
           
 
Method Summary
 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.
private  boolean canSimplify(RexCall outer, RexCall inner, RexNode value)
          Detect, in a generic, but strict way, whether it is possible to simplify a reinterpret cast.
 RexNode expand(RexCall call)
          Rewrites an expression containing decimals.
 
Methods inherited from class org.eigenbase.rel.rules.ReduceDecimalsRule.RexExpander
accessValue, decodeValue, encodeValue, encodeValue, ensureScale, ensureType, ensureType, makeApproxLiteral, makeApproxScaleFactor, makeCase, makeCase, makeDivide, makeExactLiteral, makeIsNegative, makeIsPositive, makeMinus, makeMultiply, makePlus, makeRoundFactor, makeScaleFactor, matchNullability, powerOfTen, scaleDown, scaleDownDouble, scaleUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReduceDecimalsRule.ReinterpretExpander

private ReduceDecimalsRule.ReinterpretExpander(RexBuilder builder)
Method Detail

canExpand

public boolean canExpand(RexCall call)
Description copied from class: ReduceDecimalsRule.RexExpander
This defaults to the utility method, 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.

Overrides:
canExpand in class ReduceDecimalsRule.RexExpander

expand

public RexNode expand(RexCall call)
Description copied from class: ReduceDecimalsRule.RexExpander
Rewrites an expression containing decimals. Normally, this method always performs a rewrite, but implementations may choose to return the original expression if no change was required.

Specified by:
expand in class ReduceDecimalsRule.RexExpander

canSimplify

private boolean canSimplify(RexCall outer,
                            RexCall inner,
                            RexNode value)
Detect, in a generic, but strict way, whether it is possible to simplify a reinterpret cast. The rules are as follows:
  1. If value is not the same basic type as outer, then we cannot simplify
  2. If the value is nullable but the inner or outer are not, then we cannot simplify.
  3. If inner is nullable but outer is not, we cannot simplify.
  4. If an overflow check is required from either inner or outer, we cannot simplify.
  5. Otherwise, given the same type, and sufficient nullability constraints, we can simplify.

Parameters:
outer - outer call to reinterpret
inner - inner call to reinterpret
value - inner value
Returns:
whether the two reinterpret casts can be removed