Package org.h2.expression.analysis
Class WindowFrame
- java.lang.Object
-
- org.h2.expression.analysis.WindowFrame
-
public final class WindowFrame extends java.lang.Object
Window frame clause.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
WindowFrame.BiItr
private static class
WindowFrame.BiReverseItr
private static class
WindowFrame.Itr
private static class
WindowFrame.PlainItr
private static class
WindowFrame.PlainReverseItr
private static class
WindowFrame.TriItr
private static class
WindowFrame.TriReverseItr
-
Field Summary
Fields Modifier and Type Field Description private WindowFrameExclusion
exclusion
private WindowFrameBound
following
private WindowFrameBound
starting
private WindowFrameUnits
units
-
Constructor Summary
Constructors Constructor Description WindowFrame(WindowFrameUnits units, WindowFrameBound starting, WindowFrameBound following, WindowFrameExclusion exclusion)
Creates new instance of window frame clause.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.Iterator<Value[]>
biIterator(java.util.ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, boolean reverse)
private java.util.Iterator<Value[]>
complexIterator(java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, int startIndex, int endIndex, boolean reverse)
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.private int
getEndIndex(SessionLocal session, java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow)
Returns end index of this frame,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.WindowFrameExclusion
getExclusion()
Returns the exclusion clause.WindowFrameBound
getFollowing()
Returns the following clause.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.private static int
getIntOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
java.lang.StringBuilder
getSQL(java.lang.StringBuilder builder, int formattingFlags)
Append SQL representation to the specified builder.int
getStartIndex(SessionLocal session, java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow)
Returns start index of this frame,WindowFrameBound
getStarting()
Returns the starting clause.WindowFrameUnits
getUnits()
Returns the units.private static Value
getValueOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
boolean
isValid()
Checks validity of this frame.boolean
isVariableBounds()
Check if bounds of this frame has variable expressions.java.util.Iterator<Value[]>
iterator(SessionLocal session, java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, boolean reverse)
Returns iterator.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.(package private) void
mapColumns(ColumnResolver resolver, int level, int state)
Map the columns of the resolver to expression columns.(package private) void
optimize(SessionLocal session)
Try to optimize bound expressions.private static java.util.Iterator<Value[]>
plainIterator(java.util.ArrayList<Value[]> orderedRows, int startIndex, int endIndex, boolean reverse)
private static int
toGroupEnd(java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int maxOffset)
private static int
toGroupStart(java.util.ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int minOffset)
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)
(package private) void
updateAggregate(SessionLocal session, int stage)
Update an aggregate value.
-
-
-
Field Detail
-
units
private final WindowFrameUnits units
-
starting
private final WindowFrameBound starting
-
following
private final WindowFrameBound following
-
exclusion
private final WindowFrameExclusion exclusion
-
-
Constructor Detail
-
WindowFrame
public WindowFrame(WindowFrameUnits units, WindowFrameBound starting, WindowFrameBound following, WindowFrameExclusion exclusion)
Creates new instance of window frame clause.- Parameters:
units
- unitsstarting
- starting clausefollowing
- following clauseexclusion
- exclusion 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
- windowsession
- the sessionorderedRows
- ordered rowssortOrder
- sort ordercurrentRow
- index of the current rowreverse
- 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
- windowsession
- the sessionorderedRows
- ordered rowssortOrder
- sort ordercurrentRow
- 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)
-
getIntOffset
private static int getIntOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
-
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 sessionorderedRows
- rows in partitionsortOrder
- the sort ordercurrentRow
- index of the current rowbound
- window frame boundadd
- 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
-
getValueOffset
private static Value getValueOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
-
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 afteroptimize(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 resolverlevel
- the subquery nesting levelstate
- current state for nesting checks
-
optimize
void optimize(SessionLocal session)
Try to optimize bound expressions.- Parameters:
session
- the session
-
updateAggregate
void updateAggregate(SessionLocal session, int stage)
Update an aggregate value.- Parameters:
session
- the sessionstage
- select stage- See Also:
Expression.updateAggregate(SessionLocal, int)
-
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 sessionorderedRows
- ordered rowssortOrder
- sort ordercurrentRow
- index of the current rowreverse
- 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 sessionorderedRows
- ordered rowssortOrder
- sort ordercurrentRow
- 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 sessionorderedRows
- ordered rowssortOrder
- sort ordercurrentRow
- 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 sessionorderedRows
- rows in partitionsortOrder
- the sort ordercurrentRow
- index of the current rowbound
- window frame boundforFollowing
- 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 builderformattingFlags
- quote all identifiers- Returns:
- the specified string builder
- See Also:
Expression.getSQL(StringBuilder, int, int)
-
-