Top Description Fields Constructors Methods
org.hibernate.dialect.function

public Class AggregateWindowEmulationQueryTransformer

extends Object
implements QueryTransformer
Class Inheritance
All Implemented Interfaces
org.hibernate.sql.ast.tree.expression.QueryTransformer
Imports
java.util.ArrayList, .Collections, .HashMap, .List, .Map, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.metamodel.mapping.BasicValuedMapping, .JdbcMapping, org.hibernate.query.ReturnableType, org.hibernate.spi.NavigablePath, org.hibernate.query.sqm.ComparisonOperator, org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression, org.hibernate.query.sqm.sql.SqmToSqlAstConverter, org.hibernate.query.sqm.sql.internal.SqmPathInterpretation, org.hibernate.sql.ast.spi.ExpressionReplacementWalker, .SqlSelection, org.hibernate.sql.ast.tree.SqlAstNode, org.hibernate.sql.ast.tree.cte.CteContainer, org.hibernate.sql.ast.tree.expression.ColumnReference, .Expression, .JdbcParameter, .Literal, .Over, .QueryTransformer, .SqlSelectionExpression, .SqlTuple, org.hibernate.sql.ast.tree.from.QueryPartTableGroup, org.hibernate.sql.ast.tree.predicate.ComparisonPredicate, .Predicate, org.hibernate.sql.ast.tree.select.QuerySpec, .SelectClause, .SelectStatement, .SortSpecification, org.hibernate.sql.results.internal.ResolvedSqlSelection, org.hibernate.type.BasicType

Since the query spec will render a hypothetical set window function instead of an aggregate, the following query transformer will wrap the query spec and apply aggregation in the outer query. We can do this because these functions can only be used in the select clause. A hypothetical set aggregate function like e.g. "rank" returns the rank of a passed value within the ordered set as defined through the WITHIN GROUP clause. When used as window function, the function provides the rank of the current row within the ordered set as defined for the window frame through the OVER clause, but does not do aggregation. The aggregation effect can be achieved by: 1. Selecting the elements by which the ordered set is sorted 2. In the outer query, add a comparison predicate `function_args`=`sort_expressions` 3. Use an arbitrary row produced by the inner query by using e.g. the "min" function The following query select rank(5) within group (order by e.num) from (values (1), (2), (5)) e(num) can be rewritten to select min(t.c1) from ( select rank() over (order by e.num), e.num from (values (1), (2), (5)) e(num) ) t(c1,c2) where t.c2 = 5
Author
Christian Beikov

Field Summary

Modifier and TypeField and Description
private final List<SqlAstNode>
private final Over<Object>
private final List<SortSpecification>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public QuerySpec
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argumentsback to summary
private final List<SqlAstNode> arguments
windowFunctionback to summary
private final Over<Object> windowFunction
withinGroupback to summary
private final List<SortSpecification> withinGroup

Constructor Detail

AggregateWindowEmulationQueryTransformerback to summary
public AggregateWindowEmulationQueryTransformer(Over<Object> windowFunction, List<SortSpecification> withinGroup, List<SqlAstNode> arguments)

Method Detail

transformback to summary
public QuerySpec transform(CteContainer cteContainer, QuerySpec querySpec, SqmToSqlAstConverter converter)

Implements org.hibernate.sql.ast.tree.expression.QueryTransformer.transform.

Annotations
@Override