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

public Class WindowFunction

extends DataAnalysisOperation
Class Inheritance
Imports
java.util.ArrayList, .HashMap, .Iterator, org.h2.command.query.Select, .SelectGroups, org.h2.engine.SessionLocal, org.h2.expression.Expression, .ValueExpression, org.h2.message.DbException, org.h2.table.ColumnResolver, .TableFilter, org.h2.value.TypeInfo, .Value, .ValueBigint, .ValueDouble, .ValueNull

A window function.

Field Summary

Modifier and TypeField and Description
private final Expression[]
private boolean
private boolean
private final WindowFunctionType
Inherited from org.h2.expression.analysis.DataAnalysisOperation:
overoverOrderBySortselectSTAGE_GROUPSTAGE_RESETSTAGE_WINDOW

Constructor Summary

AccessConstructor and Description
public
WindowFunction(WindowFunctionType
the type
type
,
Select
the select statement
select
,
Expression[]
arguments, or null
args
)

Creates new instance of a window function.

Method Summary

Modifier and TypeMethod and Description
protected Object
createAggregateData()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.createAggregateData.

Create aggregate data object specific to the subclass.

protected Value
getAggregatedValue(SessionLocal
the session
session
,
Object
the aggregate data
aggregateData
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getAggregatedValue.

Returns aggregated value.

public int
getCost()

Implements abstract org.h2.expression.Expression.getCost.

Estimate the cost to process the expression.

private void
getCumeDist(HashMap<Integer, Value> result, ArrayList<Value[]> orderedData, int rowIdColumn)

public WindowFunctionType

Returns:

the type of this function
getFunctionType
()

Returns the type of this function.

private void
getLeadLag(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, SessionLocal session)

public static int

Returns:

maximal number of arguments
getMaxArgumentCount
(WindowFunctionType
the type of a window function
type
)

Returns maximal number of arguments for the specified type.

public static int

Returns:

minimal number of arguments
getMinArgumentCount
(WindowFunctionType
the type of a window function
type
)

Returns minimal number of arguments for the specified type.

private void
getNth(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

private static Value
getNthValue(Iterator<Value[]> iterator, int number, boolean ignoreNulls)

private static void
getNtile(HashMap<Integer, Value> result, ArrayList<Value[]> orderedData, int rowIdColumn)

protected int
getNumExpressions()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getNumExpressions.

Returns the number of expressions, excluding OVER clause.

protected void
getOrderedResultLoop(SessionLocal
the session
session
,
HashMap<Integer, Value>
the map to append result to
result
,
ArrayList<Value[]>
ordered data
ordered
,
int
the index of row id value
rowIdColumn
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Returns result of this window function or window aggregate.

private void
getRank(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

private static void
getRatioToReport(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

public TypeInfo
getType()

Implements abstract org.h2.expression.Expression.getType.

Implements org.h2.value.Typed.getType.

Returns the data type.

public StringBuilder
getUnenclosedSQL(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Implements abstract org.h2.expression.Expression.getUnenclosedSQL.

Get the SQL statement of this expression.

public boolean
isAggregate()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Checks whether this expression is an aggregate function.

public void
mapColumnsAnalysis(ColumnResolver
the column resolver
resolver
,
int
the subquery nesting level
level
,
int
one of the Expression MAP_IN_* values
innerState
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Map the columns of the resolver to expression columns.

public Expression
optimize(SessionLocal
the session
session
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.optimize.

Try to optimize the expression.

protected void
rememberExpressions(SessionLocal
the session
session
,
Value[]
array to store values of expressions
array
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.rememberExpressions.

Stores current values of expressions into the specified array.

public void
setEvaluatable(TableFilter
the table filter
tableFilter
,
boolean
true if the table filter can return value
b
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.setEvaluatable.

Tell the expression columns whether the table filter can return values now.

public void
setFromLast(boolean
whether FROM LAST clause was specified.
fromLast
)

Sets FROM FIRST or FROM LAST clause value.

public void
setIgnoreNulls(boolean
whether IGNORE NULLS clause was specified
ignoreNulls
)

Sets RESPECT NULLS or IGNORE NULLS clause value.

protected void
updateAggregate(SessionLocal
the database session
session
,
SelectGroups
data for the aggregate group
groupData
,
int
row id of group
groupRowId
)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Update a row of an aggregate.

protected void
updateGroupAggregates(SessionLocal
the session
session
,
int
select stage
stage
)

Overrides org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Invoked when processing group stage of grouped window queries to update arguments of this aggregate.

Inherited from org.h2.expression.analysis.DataAnalysisOperation:
appendTailConditionscreateOrdergetGroupDatagetOverConditiongetOverOrderBySortgetValuegetWindowDataisEverythingmapColumnssetOverConditionupdateAggregateupdateOrderedAggregate

Field Detail

argsback to summary
private final Expression[] args
fromLastback to summary
private boolean fromLast
ignoreNullsback to summary
private boolean ignoreNulls
typeback to summary
private final WindowFunctionType type

Constructor Detail

WindowFunctionback to summary
public WindowFunction(WindowFunctionType type, Select select, Expression[] args)

Creates new instance of a window function.

Parameters
type:WindowFunctionType

the type

select:Select

the select statement

args:Expression[]

arguments, or null

Method Detail

createAggregateDataback to summary
protected Object createAggregateData()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.createAggregateData.

Doc from org.h2.expression.analysis.DataAnalysisOperation.createAggregateData.

Create aggregate data object specific to the subclass.

Returns:Object

aggregate-specific data object.

Annotations
@Override
getAggregatedValueback to summary
protected Value getAggregatedValue(SessionLocal session, Object aggregateData)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getAggregatedValue.

Doc from org.h2.expression.analysis.DataAnalysisOperation.getAggregatedValue.

Returns aggregated value.

Parameters
session:SessionLocal

the session

aggregateData:Object

the aggregate data

Returns:Value

aggregated value.

Annotations
@Override
getCostback to summary
public int getCost()

Implements abstract org.h2.expression.Expression.getCost.

Doc from org.h2.expression.Expression.getCost.

Estimate the cost to process the expression. Used when optimizing the query, to calculate the query plan with the lowest estimated cost.

Returns:int

the estimated cost

Annotations
@Override
getCumeDistback to summary
private void getCumeDist(HashMap<Integer, Value> result, ArrayList<Value[]> orderedData, int rowIdColumn)
getFunctionTypeback to summary
public WindowFunctionType getFunctionType()

Returns the type of this function.

Returns:WindowFunctionType

the type of this function

getLeadLagback to summary
private void getLeadLag(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn, SessionLocal session)
getMaxArgumentCountback to summary
public static int getMaxArgumentCount(WindowFunctionType type)

Returns maximal number of arguments for the specified type.

Parameters
type:WindowFunctionType

the type of a window function

Returns:int

maximal number of arguments

getMinArgumentCountback to summary
public static int getMinArgumentCount(WindowFunctionType type)

Returns minimal number of arguments for the specified type.

Parameters
type:WindowFunctionType

the type of a window function

Returns:int

minimal number of arguments

getNthback to summary
private void getNth(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)
getNthValueback to summary
private static Value getNthValue(Iterator<Value[]> iterator, int number, boolean ignoreNulls)
getNtileback to summary
private static void getNtile(HashMap<Integer, Value> result, ArrayList<Value[]> orderedData, int rowIdColumn)
getNumExpressionsback to summary
protected int getNumExpressions()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getNumExpressions.

Doc from org.h2.expression.analysis.DataAnalysisOperation.getNumExpressions.

Returns the number of expressions, excluding OVER clause.

Returns:int

the number of expressions

Annotations
@Override
getOrderedResultLoopback to summary
protected void getOrderedResultLoop(SessionLocal session, HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Doc from org.h2.expression.analysis.DataAnalysisOperation.getOrderedResultLoop.

Returns result of this window function or window aggregate. This method may not be called on window aggregate without window order clause.

Parameters
session:SessionLocal

the session

result:HashMap<Integer, Value>

the map to append result to

ordered:ArrayList<Value[]>

ordered data

rowIdColumn:int

the index of row id value

Annotations
@Override
getRankback to summary
private void getRank(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)
getRatioToReportback to summary
private static void getRatioToReport(HashMap<Integer, Value> result, ArrayList<Value[]> ordered, int rowIdColumn)
getTypeback to summary
public TypeInfo getType()

Implements abstract org.h2.expression.Expression.getType.

Implements org.h2.value.Typed.getType.

Doc from org.h2.expression.Expression.getType.

Returns the data type. The data type may be unknown before the optimization phase.

Returns:TypeInfo

the data type

Annotations
@Override
getUnenclosedSQLback to summary
public StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags)

Implements abstract org.h2.expression.Expression.getUnenclosedSQL.

Doc from org.h2.expression.Expression.getUnenclosedSQL.

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

Annotations
@Override
isAggregateback to summary
public boolean isAggregate()

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Doc from org.h2.expression.analysis.DataAnalysisOperation.isAggregate.

Checks whether this expression is an aggregate function.

Returns:boolean

true if this is an aggregate function (including aggregates with OVER clause), false if this is a window function

Annotations
@Override
mapColumnsAnalysisback to summary
public void mapColumnsAnalysis(ColumnResolver resolver, int level, int innerState)

Overrides org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Doc from org.h2.expression.analysis.DataAnalysisOperation.mapColumnsAnalysis.

Map the columns of the resolver to expression columns.

Parameters
resolver:ColumnResolver

the column resolver

level:int

the subquery nesting level

innerState:int

one of the Expression MAP_IN_* values

Annotations
@Override
optimizeback to summary
public Expression optimize(SessionLocal session)

Overrides org.h2.expression.analysis.DataAnalysisOperation.optimize.

Doc from org.h2.expression.Expression.optimize.

Try to optimize the expression.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized expression

Annotations
@Override
rememberExpressionsback to summary
protected void rememberExpressions(SessionLocal session, Value[] array)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.rememberExpressions.

Doc from org.h2.expression.analysis.DataAnalysisOperation.rememberExpressions.

Stores current values of expressions into the specified array.

Parameters
session:SessionLocal

the session

array:Value[]

array to store values of expressions

Annotations
@Override
setEvaluatableback to summary
public void setEvaluatable(TableFilter tableFilter, boolean b)

Overrides org.h2.expression.analysis.DataAnalysisOperation.setEvaluatable.

Doc from org.h2.expression.Expression.setEvaluatable.

Tell the expression columns whether the table filter can return values now. This is used when optimizing the query.

Parameters
tableFilter:TableFilter

the table filter

b:boolean

true if the table filter can return value

Annotations
@Override
setFromLastback to summary
public void setFromLast(boolean fromLast)

Sets FROM FIRST or FROM LAST clause value.

Parameters
fromLast:boolean

whether FROM LAST clause was specified.

setIgnoreNullsback to summary
public void setIgnoreNulls(boolean ignoreNulls)

Sets RESPECT NULLS or IGNORE NULLS clause value.

Parameters
ignoreNulls:boolean

whether IGNORE NULLS clause was specified

updateAggregateback to summary
protected void updateAggregate(SessionLocal session, SelectGroups groupData, int groupRowId)

Implements abstract org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Doc from org.h2.expression.analysis.DataAnalysisOperation.updateAggregate.

Update a row of an aggregate.

Parameters
session:SessionLocal

the database session

groupData:SelectGroups

data for the aggregate group

groupRowId:int

row id of group

Annotations
@Override
updateGroupAggregatesback to summary
protected void updateGroupAggregates(SessionLocal session, int stage)

Overrides org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Doc from org.h2.expression.analysis.DataAnalysisOperation.updateGroupAggregates.

Invoked when processing group stage of grouped window queries to update arguments of this aggregate.

Parameters
session:SessionLocal

the session

stage:int

select stage

Annotations
@Override