HHH-15613 remove lateral roots from criteria API

This commit is contained in:
Gavin King 2022-10-19 14:09:11 +02:00
parent 3357d1e5a0
commit 24f75fb8e8
8 changed files with 16 additions and 59 deletions

View File

@ -18,12 +18,5 @@ public interface JpaDerivedFrom<T> extends JpaFrom<T,T> {
* The subquery part for this derived from node. * The subquery part for this derived from node.
*/ */
JpaSubQuery<T> getQueryPart(); JpaSubQuery<T> getQueryPart();
/**
* Specifies whether the subquery part can access previous from node aliases.
* Normally, subqueries in the from clause are unable to access other from nodes,
* but when specifying them as lateral, they are allowed to do so.
* Refer to the SQL standard definition of LATERAL for more details.
*/
boolean isLateral();
} }

View File

@ -15,4 +15,12 @@ import org.hibernate.query.sqm.tree.from.SqmQualifiedJoin;
@Incubating @Incubating
public interface JpaDerivedJoin<T> extends JpaDerivedFrom<T>, SqmQualifiedJoin<T,T>, JpaJoinedFrom<T,T> { public interface JpaDerivedJoin<T> extends JpaDerivedFrom<T>, SqmQualifiedJoin<T,T>, JpaJoinedFrom<T,T> {
/**
* Specifies whether the subquery part can access previous from node aliases.
* Normally, subqueries in the from clause are unable to access other from nodes,
* but when specifying them as lateral, they are allowed to do so.
* Refer to the SQL standard definition of LATERAL for more details.
*/
boolean isLateral();
} }

View File

@ -38,26 +38,6 @@ public interface JpaSelectCriteria<T> extends AbstractQuery<T>, JpaCriteriaBase
*/ */
<X> JpaDerivedRoot<X> from(Subquery<X> subquery); <X> JpaDerivedRoot<X> from(Subquery<X> subquery);
/**
* Create and add a query root corresponding to the given lateral subquery,
* forming a cartesian product with any existing roots.
*
* @param subquery the subquery
* @return query root corresponding to the given subquery
*/
<X> JpaDerivedRoot<X> fromLateral(Subquery<X> subquery);
/**
* Create and add a query root corresponding to the given subquery,
* forming a cartesian product with any existing roots.
* If the subquery is marked as lateral, it may access previous from elements.
*
* @param subquery the subquery
* @param lateral whether to allow access to previous from elements in the subquery
* @return query root corresponding to the given subquery
*/
<X> JpaDerivedRoot<X> from(Subquery<X> subquery, boolean lateral);
@Override @Override
JpaSelectCriteria<T> distinct(boolean distinct); JpaSelectCriteria<T> distinct(boolean distinct);

View File

@ -400,8 +400,7 @@ public class QuerySplitter {
} }
final SqmDerivedRoot<?> copy = new SqmDerivedRoot<>( final SqmDerivedRoot<?> copy = new SqmDerivedRoot<>(
(SqmSubQuery<?>) sqmRoot.getQueryPart().accept( this ), (SqmSubQuery<?>) sqmRoot.getQueryPart().accept( this ),
sqmRoot.getExplicitAlias(), sqmRoot.getExplicitAlias()
sqmRoot.isLateral()
); );
getProcessingStateStack().getCurrent().getPathRegistry().register( copy ); getProcessingStateStack().getCurrent().getPathRegistry().register( copy );
sqmFromCopyMap.put( sqmRoot, copy ); sqmFromCopyMap.put( sqmRoot, copy );

View File

@ -1661,10 +1661,8 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
StrictJpaComplianceViolation.Type.FROM_SUBQUERY StrictJpaComplianceViolation.Type.FROM_SUBQUERY
); );
} }
final ParseTree firstChild = ctx.getChild( 0 );
final boolean lateral = ( (TerminalNode) firstChild ).getSymbol().getType() == HqlParser.LATERAL; final SqmSubQuery<?> subQuery = (SqmSubQuery<?>) ctx.getChild(1).accept( this );
final int subqueryIndex = lateral ? 2 : 1;
final SqmSubQuery<?> subQuery = (SqmSubQuery<?>) ctx.getChild( subqueryIndex ).accept( this );
final ParseTree lastChild = ctx.getChild( ctx.getChildCount() - 1 ); final ParseTree lastChild = ctx.getChild( ctx.getChildCount() - 1 );
final HqlParser.VariableContext identificationVariableDefContext; final HqlParser.VariableContext identificationVariableDefContext;
@ -1680,7 +1678,7 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
final SqmCreationProcessingState processingState = processingStateStack.getCurrent(); final SqmCreationProcessingState processingState = processingStateStack.getCurrent();
final SqmPathRegistry pathRegistry = processingState.getPathRegistry(); final SqmPathRegistry pathRegistry = processingState.getPathRegistry();
final SqmRoot<?> sqmRoot = new SqmDerivedRoot<>( subQuery, alias, lateral ); final SqmRoot<?> sqmRoot = new SqmDerivedRoot<>( subQuery, alias );
pathRegistry.register( sqmRoot ); pathRegistry.register( sqmRoot );

View File

@ -2562,7 +2562,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
identifierVariable, identifierVariable,
columnNames, columnNames,
tableGroupProducer.getCompatibleTableExpressions(), tableGroupProducer.getCompatibleTableExpressions(),
derivedRoot.isLateral(), false,
true, true,
creationContext.getSessionFactory() creationContext.getSessionFactory()
); );

View File

@ -28,16 +28,13 @@ import org.hibernate.spi.NavigablePath;
public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> { public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
private final SqmSubQuery<T> subQuery; private final SqmSubQuery<T> subQuery;
private final boolean lateral;
public SqmDerivedRoot( public SqmDerivedRoot(
SqmSubQuery<T> subQuery, SqmSubQuery<T> subQuery,
String alias, String alias) {
boolean lateral) {
this( this(
SqmCreationHelper.buildRootNavigablePath( "<<derived>>", alias ), SqmCreationHelper.buildRootNavigablePath( "<<derived>>", alias ),
subQuery, subQuery,
lateral,
new AnonymousTupleType<>( subQuery ), new AnonymousTupleType<>( subQuery ),
alias alias
); );
@ -46,7 +43,6 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
protected SqmDerivedRoot( protected SqmDerivedRoot(
NavigablePath navigablePath, NavigablePath navigablePath,
SqmSubQuery<T> subQuery, SqmSubQuery<T> subQuery,
boolean lateral,
SqmPathSource<T> pathSource, SqmPathSource<T> pathSource,
String alias) { String alias) {
super( super(
@ -57,7 +53,6 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
subQuery.nodeBuilder() subQuery.nodeBuilder()
); );
this.subQuery = subQuery; this.subQuery = subQuery;
this.lateral = lateral;
} }
@Override @Override
@ -71,7 +66,6 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
new SqmDerivedRoot<>( new SqmDerivedRoot<>(
getNavigablePath(), getNavigablePath(),
getQueryPart().copy( context ), getQueryPart().copy( context ),
isLateral(),
getReferencedPathSource(), getReferencedPathSource(),
getExplicitAlias() getExplicitAlias()
) )
@ -85,11 +79,6 @@ public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {
return subQuery; return subQuery;
} }
@Override
public boolean isLateral() {
return lateral;
}
@Override @Override
public <X> X accept(SemanticQueryWalker<X> walker) { public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitRootDerived( this ); return walker.visitRootDerived( this );

View File

@ -143,18 +143,8 @@ public abstract class AbstractSqmSelectQuery<T>
@Override @Override
public <X> SqmDerivedRoot<X> from(Subquery<X> subquery) { public <X> SqmDerivedRoot<X> from(Subquery<X> subquery) {
return from( subquery, false );
}
@Override
public <X> SqmDerivedRoot<X> fromLateral(Subquery<X> subquery) {
return from( subquery, true );
}
@Override
public <X> SqmDerivedRoot<X> from(Subquery<X> subquery, boolean lateral) {
validateComplianceFromSubQuery(); validateComplianceFromSubQuery();
final SqmDerivedRoot<X> root = new SqmDerivedRoot<>( (SqmSubQuery<X>) subquery, null, lateral ); final SqmDerivedRoot<X> root = new SqmDerivedRoot<>( (SqmSubQuery<X>) subquery, null );
addRoot( root ); addRoot( root );
return root; return root;
} }