Package org.apache.calcite.rel.rules
Class DateRangeRules.ExtractShuttle
- java.lang.Object
-
- org.apache.calcite.rex.RexShuttle
-
- org.apache.calcite.rel.rules.DateRangeRules.ExtractShuttle
-
- All Implemented Interfaces:
RexVisitor<RexNode>
- Enclosing class:
- DateRangeRules
static class DateRangeRules.ExtractShuttle extends RexShuttle
Walks over an expression, replacing calls toEXTRACT
,FLOOR
andCEIL
with date ranges.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Deque<RexCall>
calls
private java.util.Map<RexNode,com.google.common.collect.RangeSet<java.util.Calendar>>
operandRanges
private RexBuilder
rexBuilder
private org.apache.calcite.avatica.util.TimeUnitRange
timeUnit
private com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange>
timeUnitRanges
private java.lang.String
timeZone
-
Constructor Summary
Constructors Constructor Description ExtractShuttle(RexBuilder rexBuilder, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, java.util.Map<RexNode,com.google.common.collect.RangeSet<java.util.Calendar>> operandRanges, com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange> timeUnitRanges, java.lang.String timeZone)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
canRewriteExtract(RexNode operand)
private java.util.Calendar
ceil(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
private com.google.common.collect.Range<java.util.Calendar>
ceilRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
(package private) RexNode
compareExtract(SqlKind comparison, RexNode operand, RexLiteral literal)
private RexNode
compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, boolean floor)
private RexLiteral
dateTimeLiteral(RexBuilder rexBuilder, java.util.Calendar calendar, RexNode operand)
private java.util.Calendar
decrement(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
private com.google.common.collect.Range<java.util.Calendar>
extractRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
private java.util.Calendar
floor(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
Computes floor of a calendar to a given time unit.private com.google.common.collect.Range<java.util.Calendar>
floorRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
private java.util.Calendar
increment(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
(package private) boolean
isExtractCall(RexNode e)
(package private) boolean
isFloorCeilCall(RexNode e)
private static boolean
isValid(int v, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
private boolean
next(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, int v, com.google.common.collect.Range<java.util.Calendar> r, boolean strict)
private java.util.Calendar
round(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, boolean down)
Returns a copy of a calendar, optionally rounded up to the next time unit.private java.util.Calendar
timestampValue(RexLiteral timeLiteral)
private RexNode
toRex(RexNode operand, com.google.common.collect.Range<java.util.Calendar> r)
RexNode
visitCall(RexCall call)
protected java.util.List<RexNode>
visitList(java.util.List<? extends RexNode> exprs, boolean[] update)
Visits each of a list of expressions and returns a list of the results.-
Methods inherited from class org.apache.calcite.rex.RexShuttle
apply, apply, apply, mutate, visitArray, visitCorrelVariable, visitDynamicParam, visitFieldAccess, visitFieldCollations, visitInputRef, visitList, visitLiteral, visitLocalRef, visitOver, visitPatternFieldRef, visitRangeRef, visitSubQuery, visitTableInputRef, visitWindow
-
-
-
-
Field Detail
-
rexBuilder
private final RexBuilder rexBuilder
-
timeUnit
private final org.apache.calcite.avatica.util.TimeUnitRange timeUnit
-
operandRanges
private final java.util.Map<RexNode,com.google.common.collect.RangeSet<java.util.Calendar>> operandRanges
-
calls
private final java.util.Deque<RexCall> calls
-
timeUnitRanges
private final com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange> timeUnitRanges
-
timeZone
private final java.lang.String timeZone
-
-
Constructor Detail
-
ExtractShuttle
ExtractShuttle(RexBuilder rexBuilder, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, java.util.Map<RexNode,com.google.common.collect.RangeSet<java.util.Calendar>> operandRanges, com.google.common.collect.ImmutableSortedSet<org.apache.calcite.avatica.util.TimeUnitRange> timeUnitRanges, java.lang.String timeZone)
-
-
Method Detail
-
visitCall
public RexNode visitCall(RexCall call)
- Specified by:
visitCall
in interfaceRexVisitor<RexNode>
- Overrides:
visitCall
in classRexShuttle
-
canRewriteExtract
private boolean canRewriteExtract(RexNode operand)
-
visitList
protected java.util.List<RexNode> visitList(java.util.List<? extends RexNode> exprs, boolean[] update)
Description copied from class:RexShuttle
Visits each of a list of expressions and returns a list of the results.- Overrides:
visitList
in classRexShuttle
- Parameters:
exprs
- List of expressionsupdate
- If not null, sets this to true if any of the expressions was modified- Returns:
- Array of visited expressions
-
isExtractCall
boolean isExtractCall(RexNode e)
-
compareExtract
RexNode compareExtract(SqlKind comparison, RexNode operand, RexLiteral literal)
-
next
private boolean next(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, int v, com.google.common.collect.Range<java.util.Calendar> r, boolean strict)
-
isValid
private static boolean isValid(int v, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
-
toRex
@Nonnull private RexNode toRex(RexNode operand, com.google.common.collect.Range<java.util.Calendar> r)
-
dateTimeLiteral
private RexLiteral dateTimeLiteral(RexBuilder rexBuilder, java.util.Calendar calendar, RexNode operand)
-
extractRange
private com.google.common.collect.Range<java.util.Calendar> extractRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
-
round
private java.util.Calendar round(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, boolean down)
Returns a copy of a calendar, optionally rounded up to the next time unit.
-
compareFloorCeil
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, org.apache.calcite.avatica.util.TimeUnitRange timeUnit, boolean floor)
-
timestampValue
private java.util.Calendar timestampValue(RexLiteral timeLiteral)
-
floorRange
private com.google.common.collect.Range<java.util.Calendar> floorRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
-
ceilRange
private com.google.common.collect.Range<java.util.Calendar> ceilRange(org.apache.calcite.avatica.util.TimeUnitRange timeUnit, SqlKind comparison, java.util.Calendar c)
-
isFloorCeilCall
boolean isFloorCeilCall(RexNode e)
-
increment
private java.util.Calendar increment(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
-
decrement
private java.util.Calendar decrement(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
-
ceil
private java.util.Calendar ceil(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
-
floor
private java.util.Calendar floor(java.util.Calendar c, org.apache.calcite.avatica.util.TimeUnitRange timeUnit)
Computes floor of a calendar to a given time unit.- Returns:
- returns a copy of calendar, floored to the given time unit
-
-