Class WindowFrame


  • public final class WindowFrame
    extends java.lang.Object
    Window frame clause.
    • Method Detail

      • iterator

        public static java.util.Iterator<Value[]> iterator​(Window over,
                                                           SessionLocal session,
                                                           java.util.ArrayList<Value[]> orderedRows,
                                                           SortOrder sortOrder,
                                                           int currentRow,
                                                           boolean reverse)
        Returns iterator for the specified frame, or default iterator if frame is null.
        Parameters:
        over - window
        session - the session
        orderedRows - ordered rows
        sortOrder - sort order
        currentRow - index of the current row
        reverse - whether iterator should iterate in reverse order
        Returns:
        iterator
      • getEndIndex

        public static int getEndIndex​(Window over,
                                      SessionLocal session,
                                      java.util.ArrayList<Value[]> orderedRows,
                                      SortOrder sortOrder,
                                      int currentRow)
        Returns end index for the specified frame, or default end index if frame is null.
        Parameters:
        over - window
        session - the session
        orderedRows - ordered rows
        sortOrder - sort order
        currentRow - index of the current row
        Returns:
        end index
        Throws:
        java.lang.UnsupportedOperationException - if over is not null and its exclusion clause is not EXCLUDE NO OTHERS
      • plainIterator

        private static java.util.Iterator<Value[]> plainIterator​(java.util.ArrayList<Value[]> orderedRows,
                                                                 int startIndex,
                                                                 int endIndex,
                                                                 boolean reverse)
      • biIterator

        private static java.util.Iterator<Value[]> biIterator​(java.util.ArrayList<Value[]> orderedRows,
                                                              int startIndex1,
                                                              int endIndex1,
                                                              int startIndex2,
                                                              int endIndex2,
                                                              boolean reverse)
      • triIterator

        private static java.util.Iterator<Value[]> triIterator​(java.util.ArrayList<Value[]> orderedRows,
                                                               int startIndex1,
                                                               int endIndex1,
                                                               int startIndex2,
                                                               int endIndex2,
                                                               int startIndex3,
                                                               int endIndex3,
                                                               boolean reverse)
      • toGroupStart

        private static int toGroupStart​(java.util.ArrayList<Value[]> orderedRows,
                                        SortOrder sortOrder,
                                        int offset,
                                        int minOffset)
      • toGroupEnd

        private static int toGroupEnd​(java.util.ArrayList<Value[]> orderedRows,
                                      SortOrder sortOrder,
                                      int offset,
                                      int maxOffset)
      • getCompareRow

        private static Value[] getCompareRow​(SessionLocal session,
                                             java.util.ArrayList<Value[]> orderedRows,
                                             SortOrder sortOrder,
                                             int currentRow,
                                             WindowFrameBound bound,
                                             boolean add)
        Appends bound value to the current row and produces row for comparison operations.
        Parameters:
        session - the session
        orderedRows - rows in partition
        sortOrder - the sort order
        currentRow - index of the current row
        bound - window frame bound
        add - false for PRECEDING, true for FOLLOWING
        Returns:
        row for comparison operations, or null if result is out of range and should be treated as UNLIMITED
      • getUnits

        public WindowFrameUnits getUnits()
        Returns the units.
        Returns:
        the units
      • getStarting

        public WindowFrameBound getStarting()
        Returns the starting clause.
        Returns:
        the starting clause
      • getFollowing

        public WindowFrameBound getFollowing()
        Returns the following clause.
        Returns:
        the following clause, or null
      • getExclusion

        public WindowFrameExclusion getExclusion()
        Returns the exclusion clause.
        Returns:
        the exclusion clause
      • isValid

        public boolean isValid()
        Checks validity of this frame.
        Returns:
        whether bounds of this frame valid
      • isVariableBounds

        public boolean isVariableBounds()
        Check if bounds of this frame has variable expressions. This method may be used only after optimize(SessionLocal) invocation.
        Returns:
        if bounds of this frame has variable expressions
      • mapColumns

        void mapColumns​(ColumnResolver resolver,
                        int level,
                        int state)
        Map the columns of the resolver to expression columns.
        Parameters:
        resolver - the column resolver
        level - the subquery nesting level
        state - current state for nesting checks
      • optimize

        void optimize​(SessionLocal session)
        Try to optimize bound expressions.
        Parameters:
        session - the session
      • iterator

        public java.util.Iterator<Value[]> iterator​(SessionLocal session,
                                                    java.util.ArrayList<Value[]> orderedRows,
                                                    SortOrder sortOrder,
                                                    int currentRow,
                                                    boolean reverse)
        Returns iterator.
        Parameters:
        session - the session
        orderedRows - ordered rows
        sortOrder - sort order
        currentRow - index of the current row
        reverse - whether iterator should iterate in reverse order
        Returns:
        iterator
      • getStartIndex

        public int getStartIndex​(SessionLocal session,
                                 java.util.ArrayList<Value[]> orderedRows,
                                 SortOrder sortOrder,
                                 int currentRow)
        Returns start index of this frame,
        Parameters:
        session - the session
        orderedRows - ordered rows
        sortOrder - sort order
        currentRow - index of the current row
        Returns:
        start index
        Throws:
        java.lang.UnsupportedOperationException - if exclusion clause is not EXCLUDE NO OTHERS
      • getEndIndex

        private int getEndIndex​(SessionLocal session,
                                java.util.ArrayList<Value[]> orderedRows,
                                SortOrder sortOrder,
                                int currentRow)
        Returns end index of this frame,
        Parameters:
        session - the session
        orderedRows - ordered rows
        sortOrder - sort order
        currentRow - index of the current row
        Returns:
        end index
        Throws:
        java.lang.UnsupportedOperationException - if exclusion clause is not EXCLUDE NO OTHERS
      • getIndex

        private int getIndex​(SessionLocal session,
                             java.util.ArrayList<Value[]> orderedRows,
                             SortOrder sortOrder,
                             int currentRow,
                             WindowFrameBound bound,
                             boolean forFollowing)
        Returns starting or ending index of a window frame.
        Parameters:
        session - the session
        orderedRows - rows in partition
        sortOrder - the sort order
        currentRow - index of the current row
        bound - window frame bound
        forFollowing - false for start index, true for end index
        Returns:
        starting or ending index of a window frame (inclusive), can be 0 or be equal to the number of rows if frame is not limited from that side
      • complexIterator

        private java.util.Iterator<Value[]> complexIterator​(java.util.ArrayList<Value[]> orderedRows,
                                                            SortOrder sortOrder,
                                                            int currentRow,
                                                            int startIndex,
                                                            int endIndex,
                                                            boolean reverse)
      • getSQL

        public java.lang.StringBuilder getSQL​(java.lang.StringBuilder builder,
                                              int formattingFlags)
        Append SQL representation to the specified builder.
        Parameters:
        builder - string builder
        formattingFlags - quote all identifiers
        Returns:
        the specified string builder
        See Also:
        Expression.getSQL(StringBuilder, int, int)