Class DateRangeRules.ExtractShuttle

  • All Implemented Interfaces:
    RexVisitor<RexNode>
    Enclosing class:
    DateRangeRules

    static class DateRangeRules.ExtractShuttle
    extends RexShuttle
    Walks over an expression, replacing calls to EXTRACT, FLOOR and CEIL 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)  
    • Field Detail

      • 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

      • 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 class RexShuttle
        Parameters:
        exprs - List of expressions
        update - If not null, sets this to true if any of the expressions was modified
        Returns:
        Array of visited expressions
      • isExtractCall

        boolean isExtractCall​(RexNode e)
      • 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)
      • 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