Top Description Inners Fields Constructors Methods
org.h2.expression.analysis

public final Class WindowFrame

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .Iterator, .NoSuchElementException, org.h2.api.ErrorCode, org.h2.engine.SessionLocal, org.h2.expression.BinaryOperation, .BinaryOperation.OpType, .Expression, .ValueExpression, org.h2.message.DbException, org.h2.result.SortOrder, org.h2.table.ColumnResolver, org.h2.value.Value, .ValueNull

Window frame clause.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private abstract static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private final WindowFrameExclusion
private final WindowFrameBound
private final WindowFrameBound
private final WindowFrameUnits

Constructor Summary

AccessConstructor and Description
public
WindowFrame(WindowFrameUnits
units
units
,
WindowFrameBound
starting clause
starting
,
WindowFrameBound
following clause
following
,
WindowFrameExclusion
exclusion clause
exclusion
)

Creates new instance of window frame clause.

Method Summary

Modifier and TypeMethod and Description
private static Iterator<Value[]>
biIterator(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, boolean reverse)

private Iterator<Value[]>
complexIterator(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, int startIndex, int endIndex, boolean reverse)

private static Value[]

Returns:

row for comparison operations, or null if result is out of range and should be treated as UNLIMITED
getCompareRow
(SessionLocal
the session
session
,
ArrayList<Value[]>
rows in partition
orderedRows
,
SortOrder
the sort order
sortOrder
,
int
index of the current row
currentRow
,
WindowFrameBound
window frame bound
bound
,
boolean
false for PRECEDING, true for FOLLOWING
add
)

Appends bound value to the current row and produces row for comparison operations.

public static int

Returns:

end index
getEndIndex
(Window
window
over
,
SessionLocal
the session
session
,
ArrayList<Value[]>
ordered rows
orderedRows
,
SortOrder
sort order
sortOrder
,
int
index of the current row
currentRow
)

Returns end index for the specified frame, or default end index if frame is null.

private int

Returns:

end index
getEndIndex
(SessionLocal
the session
session
,
ArrayList<Value[]>
ordered rows
orderedRows
,
SortOrder
sort order
sortOrder
,
int
index of the current row
currentRow
)

Returns end index of this frame,

public WindowFrameExclusion

Returns:

the exclusion clause
getExclusion
()

Returns the exclusion clause.

public WindowFrameBound

Returns:

the following clause, or null
getFollowing
()

Returns the following clause.

private int

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
getIndex
(SessionLocal
the session
session
,
ArrayList<Value[]>
rows in partition
orderedRows
,
SortOrder
the sort order
sortOrder
,
int
index of the current row
currentRow
,
WindowFrameBound
window frame bound
bound
,
boolean
false for start index, true for end index
forFollowing
)

Returns starting or ending index of a window frame.

private static int
getIntOffset(WindowFrameBound bound, Value[] values, SessionLocal session)

public StringBuilder

Returns:

the specified string builder
getSQL
(StringBuilder
string builder
builder
,
int
quote all identifiers
formattingFlags
)

Append SQL representation to the specified builder.

public int

Returns:

start index
getStartIndex
(SessionLocal
the session
session
,
ArrayList<Value[]>
ordered rows
orderedRows
,
SortOrder
sort order
sortOrder
,
int
index of the current row
currentRow
)

Returns start index of this frame,

public WindowFrameBound

Returns:

the starting clause
getStarting
()

Returns the starting clause.

public WindowFrameUnits

Returns:

the units
getUnits
()

Returns the units.

private static Value
public boolean

Returns:

whether bounds of this frame valid
isValid
()

Checks validity of this frame.

public boolean

Returns:

if bounds of this frame has variable expressions
isVariableBounds
()

Check if bounds of this frame has variable expressions.

public static Iterator<Value[]>

Returns:

iterator
iterator
(Window
window
over
,
SessionLocal
the session
session
,
ArrayList<Value[]>
ordered rows
orderedRows
,
SortOrder
sort order
sortOrder
,
int
index of the current row
currentRow
,
boolean
whether iterator should iterate in reverse order
reverse
)

Returns iterator for the specified frame, or default iterator if frame is null.

public Iterator<Value[]>

Returns:

iterator
iterator
(SessionLocal
the session
session
,
ArrayList<Value[]>
ordered rows
orderedRows
,
SortOrder
sort order
sortOrder
,
int
index of the current row
currentRow
,
boolean
whether iterator should iterate in reverse order
reverse
)

Returns iterator.

pack-priv void
mapColumns(ColumnResolver
the column resolver
resolver
,
int
the subquery nesting level
level
,
int
current state for nesting checks
state
)

Map the columns of the resolver to expression columns.

pack-priv void
optimize(SessionLocal
the session
session
)

Try to optimize bound expressions.

private static Iterator<Value[]>
plainIterator(ArrayList<Value[]> orderedRows, int startIndex, int endIndex, boolean reverse)

private static int
toGroupEnd(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int maxOffset)

private static int
toGroupStart(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int minOffset)

private static Iterator<Value[]>
triIterator(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3, boolean reverse)

pack-priv void
updateAggregate(SessionLocal
the session
session
,
int
select stage
stage
)

Update an aggregate value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

exclusionback to summary
private final WindowFrameExclusion exclusion
followingback to summary
private final WindowFrameBound following
startingback to summary
private final WindowFrameBound starting
unitsback to summary
private final WindowFrameUnits units

Constructor Detail

WindowFrameback to summary
public WindowFrame(WindowFrameUnits units, WindowFrameBound starting, WindowFrameBound following, WindowFrameExclusion exclusion)

Creates new instance of window frame clause.

Parameters
units:WindowFrameUnits

units

starting:WindowFrameBound

starting clause

following:WindowFrameBound

following clause

exclusion:WindowFrameExclusion

exclusion clause

Method Detail

biIteratorback to summary
private static Iterator<Value[]> biIterator(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, boolean reverse)
complexIteratorback to summary
private Iterator<Value[]> complexIterator(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, int startIndex, int endIndex, boolean reverse)
getCompareRowback to summary
private static Value[] getCompareRow(SessionLocal session, 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:SessionLocal

the session

orderedRows:ArrayList<Value[]>

rows in partition

sortOrder:SortOrder

the sort order

currentRow:int

index of the current row

bound:WindowFrameBound

window frame bound

add:boolean

false for PRECEDING, true for FOLLOWING

Returns:Value[]

row for comparison operations, or null if result is out of range and should be treated as UNLIMITED

getEndIndexback to summary
public static int getEndIndex(Window over, SessionLocal session, 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

window

session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

ordered rows

sortOrder:SortOrder

sort order

currentRow:int

index of the current row

Returns:int

end index

Exceptions
UnsupportedOperationException:
if over is not null and its exclusion clause is not EXCLUDE NO OTHERS
getEndIndexback to summary
private int getEndIndex(SessionLocal session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow)

Returns end index of this frame,

Parameters
session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

ordered rows

sortOrder:SortOrder

sort order

currentRow:int

index of the current row

Returns:int

end index

Exceptions
UnsupportedOperationException:
if exclusion clause is not EXCLUDE NO OTHERS
getExclusionback to summary
public WindowFrameExclusion getExclusion()

Returns the exclusion clause.

Returns:WindowFrameExclusion

the exclusion clause

getFollowingback to summary
public WindowFrameBound getFollowing()

Returns the following clause.

Returns:WindowFrameBound

the following clause, or null

getIndexback to summary
private int getIndex(SessionLocal session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, WindowFrameBound bound, boolean forFollowing)

Returns starting or ending index of a window frame.

Parameters
session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

rows in partition

sortOrder:SortOrder

the sort order

currentRow:int

index of the current row

bound:WindowFrameBound

window frame bound

forFollowing:boolean

false for start index, true for end index

Returns:int

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

getIntOffsetback to summary
private static int getIntOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
getSQLback to summary
public StringBuilder getSQL(StringBuilder builder, int formattingFlags)

Append SQL representation to the specified builder.

Parameters
builder:StringBuilder

string builder

formattingFlags:int

quote all identifiers

Returns:StringBuilder

the specified string builder

See Also
org.h2.expression.Expression#getSQL(StringBuilder, int, int)
getStartIndexback to summary
public int getStartIndex(SessionLocal session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow)

Returns start index of this frame,

Parameters
session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

ordered rows

sortOrder:SortOrder

sort order

currentRow:int

index of the current row

Returns:int

start index

Exceptions
UnsupportedOperationException:
if exclusion clause is not EXCLUDE NO OTHERS
getStartingback to summary
public WindowFrameBound getStarting()

Returns the starting clause.

Returns:WindowFrameBound

the starting clause

getUnitsback to summary
public WindowFrameUnits getUnits()

Returns the units.

Returns:WindowFrameUnits

the units

getValueOffsetback to summary
private static Value getValueOffset(WindowFrameBound bound, Value[] values, SessionLocal session)
isValidback to summary
public boolean isValid()

Checks validity of this frame.

Returns:boolean

whether bounds of this frame valid

isVariableBoundsback to summary
public boolean isVariableBounds()

Check if bounds of this frame has variable expressions. This method may be used only after optimize(SessionLocal) invocation.

Returns:boolean

if bounds of this frame has variable expressions

iteratorback to summary
public static Iterator<Value[]> iterator(Window over, SessionLocal session, 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

window

session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

ordered rows

sortOrder:SortOrder

sort order

currentRow:int

index of the current row

reverse:boolean

whether iterator should iterate in reverse order

Returns:Iterator<Value[]>

iterator

iteratorback to summary
public Iterator<Value[]> iterator(SessionLocal session, ArrayList<Value[]> orderedRows, SortOrder sortOrder, int currentRow, boolean reverse)

Returns iterator.

Parameters
session:SessionLocal

the session

orderedRows:ArrayList<Value[]>

ordered rows

sortOrder:SortOrder

sort order

currentRow:int

index of the current row

reverse:boolean

whether iterator should iterate in reverse order

Returns:Iterator<Value[]>

iterator

mapColumnsback to summary
pack-priv void mapColumns(ColumnResolver resolver, int level, int state)

Map the columns of the resolver to expression columns.

Parameters
resolver:ColumnResolver

the column resolver

level:int

the subquery nesting level

state:int

current state for nesting checks

optimizeback to summary
pack-priv void optimize(SessionLocal session)

Try to optimize bound expressions.

Parameters
session:SessionLocal

the session

plainIteratorback to summary
private static Iterator<Value[]> plainIterator(ArrayList<Value[]> orderedRows, int startIndex, int endIndex, boolean reverse)
toGroupEndback to summary
private static int toGroupEnd(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int maxOffset)
toGroupStartback to summary
private static int toGroupStart(ArrayList<Value[]> orderedRows, SortOrder sortOrder, int offset, int minOffset)
triIteratorback to summary
private static Iterator<Value[]> triIterator(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3, boolean reverse)
updateAggregateback to summary
pack-priv void updateAggregate(SessionLocal session, int stage)

Update an aggregate value.

Parameters
session:SessionLocal

the session

stage:int

select stage

See Also
Expression#updateAggregate(SessionLocal, int)
org.h2.expression.analysis back to summary

private Class WindowFrame.BiItr

extends PlainItr
Class Inheritance
Known Direct Subclasses
org.h2.expression.analysis.WindowFrame.TriItr

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
Inherited from org.h2.expression.analysis.WindowFrame.PlainItr:
endIndex

Constructor Summary

AccessConstructor and Description
pack-priv
BiItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2)

Method Summary

Modifier and TypeMethod and Description
public Value[]
next()

Overrides org.h2.expression.analysis.WindowFrame.PlainItr.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from org.h2.expression.analysis.WindowFrame.PlainItr:
hasNext

Field Detail

end1back to summary
pack-priv final int end1
start1back to summary
pack-priv final int start1

Constructor Detail

BiItrback to summary
pack-priv BiItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2)

Method Detail

nextback to summary
public Value[] next()

Overrides org.h2.expression.analysis.WindowFrame.PlainItr.next.

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override
org.h2.expression.analysis back to summary

private Class WindowFrame.BiReverseItr

extends PlainReverseItr
Class Inheritance
Known Direct Subclasses
org.h2.expression.analysis.WindowFrame.TriReverseItr

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final int
Inherited from org.h2.expression.analysis.WindowFrame.PlainReverseItr:
startIndex

Constructor Summary

AccessConstructor and Description
pack-priv
BiReverseItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2)

Method Summary

Modifier and TypeMethod and Description
public Value[]
next()

Overrides org.h2.expression.analysis.WindowFrame.PlainReverseItr.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Inherited from org.h2.expression.analysis.WindowFrame.PlainReverseItr:
hasNext

Field Detail

end1back to summary
pack-priv final int end1
start1back to summary
pack-priv final int start1

Constructor Detail

BiReverseItrback to summary
pack-priv BiReverseItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2)

Method Detail

nextback to summary
public Value[] next()

Overrides org.h2.expression.analysis.WindowFrame.PlainReverseItr.next.

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override
org.h2.expression.analysis back to summary

private abstract Class WindowFrame.Itr

extends Object
implements Iterator<Value[]>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Known Direct Subclasses
org.h2.expression.analysis.WindowFrame.PlainItr, org.h2.expression.analysis.WindowFrame.PlainReverseItr

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv final ArrayList<Value[]>

Constructor Summary

AccessConstructor and Description
pack-priv
Itr(ArrayList<Value[]> orderedRows)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cursorback to summary
pack-priv int cursor
orderedRowsback to summary
pack-priv final ArrayList<Value[]> orderedRows

Constructor Detail

Itrback to summary
pack-priv Itr(ArrayList<Value[]> orderedRows)
org.h2.expression.analysis back to summary

private Class WindowFrame.PlainItr

extends Itr
Class Inheritance
Known Direct Subclasses
org.h2.expression.analysis.WindowFrame.BiItr

Field Summary

Modifier and TypeField and Description
pack-priv final int
Inherited from org.h2.expression.analysis.WindowFrame.Itr:
cursororderedRows

Constructor Summary

AccessConstructor and Description
pack-priv
PlainItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Value[]
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Field Detail

endIndexback to summary
pack-priv final int endIndex

Constructor Detail

PlainItrback to summary
pack-priv PlainItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Value[] next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override
org.h2.expression.analysis back to summary

private Class WindowFrame.PlainReverseItr

extends Itr
Class Inheritance
Known Direct Subclasses
org.h2.expression.analysis.WindowFrame.BiReverseItr

Field Summary

Modifier and TypeField and Description
pack-priv final int
Inherited from org.h2.expression.analysis.WindowFrame.Itr:
cursororderedRows

Constructor Summary

AccessConstructor and Description
pack-priv
PlainReverseItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex)

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public Value[]
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Field Detail

startIndexback to summary
pack-priv final int startIndex

Constructor Detail

PlainReverseItrback to summary
pack-priv PlainReverseItr(ArrayList<Value[]> orderedRows, int startIndex, int endIndex)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public Value[] next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override
org.h2.expression.analysis back to summary

private final Class WindowFrame.TriItr

extends BiItr
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
private final int
Inherited from org.h2.expression.analysis.WindowFrame.BiItr:
end1start1

Constructor Summary

AccessConstructor and Description
pack-priv
TriItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3)

Method Summary

Modifier and TypeMethod and Description
public Value[]
next()

Overrides org.h2.expression.analysis.WindowFrame.BiItr.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Field Detail

end2back to summary
private final int end2
start2back to summary
private final int start2

Constructor Detail

TriItrback to summary
pack-priv TriItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3)

Method Detail

nextback to summary
public Value[] next()

Overrides org.h2.expression.analysis.WindowFrame.BiItr.next.

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override
org.h2.expression.analysis back to summary

private final Class WindowFrame.TriReverseItr

extends BiReverseItr
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int
private final int
Inherited from org.h2.expression.analysis.WindowFrame.BiReverseItr:
end1start1

Constructor Summary

AccessConstructor and Description
pack-priv
TriReverseItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3)

Method Summary

Modifier and TypeMethod and Description
public Value[]
next()

Overrides org.h2.expression.analysis.WindowFrame.BiReverseItr.next.

Implements java.util.Iterator.next.

Returns the next element in the iteration.

Field Detail

end2back to summary
private final int end2
start2back to summary
private final int start2

Constructor Detail

TriReverseItrback to summary
pack-priv TriReverseItr(ArrayList<Value[]> orderedRows, int startIndex1, int endIndex1, int startIndex2, int endIndex2, int startIndex3, int endIndex3)

Method Detail

nextback to summary
public Value[] next()

Overrides org.h2.expression.analysis.WindowFrame.BiReverseItr.next.

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:Value[]

the next element in the iteration

Annotations
@Override