From 24f75fb8e80f6fa63e485c5488ee8cb44937de73 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Wed, 19 Oct 2022 14:09:11 +0200 Subject: [PATCH] HHH-15613 remove lateral roots from criteria API --- .../query/criteria/JpaDerivedFrom.java | 9 +-------- .../query/criteria/JpaDerivedJoin.java | 8 ++++++++ .../query/criteria/JpaSelectCriteria.java | 20 ------------------- .../query/hql/internal/QuerySplitter.java | 3 +-- .../hql/internal/SemanticQueryBuilder.java | 8 +++----- .../sqm/sql/BaseSqmToSqlAstConverter.java | 2 +- .../query/sqm/tree/domain/SqmDerivedRoot.java | 13 +----------- .../tree/select/AbstractSqmSelectQuery.java | 12 +---------- 8 files changed, 16 insertions(+), 59 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedFrom.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedFrom.java index 56b7611fdd..4a87b151d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedFrom.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedFrom.java @@ -18,12 +18,5 @@ public interface JpaDerivedFrom extends JpaFrom { * The subquery part for this derived from node. */ JpaSubQuery 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(); + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedJoin.java index 7e9fbf610a..8b81a36080 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaDerivedJoin.java @@ -15,4 +15,12 @@ import org.hibernate.query.sqm.tree.from.SqmQualifiedJoin; @Incubating public interface JpaDerivedJoin extends JpaDerivedFrom, SqmQualifiedJoin, JpaJoinedFrom { + /** + * 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(); + } diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSelectCriteria.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSelectCriteria.java index 13b91f8a75..21d068e346 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSelectCriteria.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/JpaSelectCriteria.java @@ -38,26 +38,6 @@ public interface JpaSelectCriteria extends AbstractQuery, JpaCriteriaBase */ JpaDerivedRoot from(Subquery 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 - */ - JpaDerivedRoot fromLateral(Subquery 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 - */ - JpaDerivedRoot from(Subquery subquery, boolean lateral); - @Override JpaSelectCriteria distinct(boolean distinct); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java index 65ba5f9da6..a1ca350be8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java @@ -400,8 +400,7 @@ public class QuerySplitter { } final SqmDerivedRoot copy = new SqmDerivedRoot<>( (SqmSubQuery) sqmRoot.getQueryPart().accept( this ), - sqmRoot.getExplicitAlias(), - sqmRoot.isLateral() + sqmRoot.getExplicitAlias() ); getProcessingStateStack().getCurrent().getPathRegistry().register( copy ); sqmFromCopyMap.put( sqmRoot, copy ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index 71fa7da9e2..939c74f1f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -1661,10 +1661,8 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem StrictJpaComplianceViolation.Type.FROM_SUBQUERY ); } - final ParseTree firstChild = ctx.getChild( 0 ); - final boolean lateral = ( (TerminalNode) firstChild ).getSymbol().getType() == HqlParser.LATERAL; - final int subqueryIndex = lateral ? 2 : 1; - final SqmSubQuery subQuery = (SqmSubQuery) ctx.getChild( subqueryIndex ).accept( this ); + + final SqmSubQuery subQuery = (SqmSubQuery) ctx.getChild(1).accept( this ); final ParseTree lastChild = ctx.getChild( ctx.getChildCount() - 1 ); final HqlParser.VariableContext identificationVariableDefContext; @@ -1680,7 +1678,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem final SqmCreationProcessingState processingState = processingStateStack.getCurrent(); final SqmPathRegistry pathRegistry = processingState.getPathRegistry(); - final SqmRoot sqmRoot = new SqmDerivedRoot<>( subQuery, alias, lateral ); + final SqmRoot sqmRoot = new SqmDerivedRoot<>( subQuery, alias ); pathRegistry.register( sqmRoot ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index f0406467a2..ddaaf27830 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -2562,7 +2562,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base identifierVariable, columnNames, tableGroupProducer.getCompatibleTableExpressions(), - derivedRoot.isLateral(), + false, true, creationContext.getSessionFactory() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java index d63d6c1c81..e2f2ee1de3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmDerivedRoot.java @@ -28,16 +28,13 @@ import org.hibernate.spi.NavigablePath; public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { private final SqmSubQuery subQuery; - private final boolean lateral; public SqmDerivedRoot( SqmSubQuery subQuery, - String alias, - boolean lateral) { + String alias) { this( SqmCreationHelper.buildRootNavigablePath( "<>", alias ), subQuery, - lateral, new AnonymousTupleType<>( subQuery ), alias ); @@ -46,7 +43,6 @@ public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { protected SqmDerivedRoot( NavigablePath navigablePath, SqmSubQuery subQuery, - boolean lateral, SqmPathSource pathSource, String alias) { super( @@ -57,7 +53,6 @@ public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { subQuery.nodeBuilder() ); this.subQuery = subQuery; - this.lateral = lateral; } @Override @@ -71,7 +66,6 @@ public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { new SqmDerivedRoot<>( getNavigablePath(), getQueryPart().copy( context ), - isLateral(), getReferencedPathSource(), getExplicitAlias() ) @@ -85,11 +79,6 @@ public class SqmDerivedRoot extends SqmRoot implements JpaDerivedRoot { return subQuery; } - @Override - public boolean isLateral() { - return lateral; - } - @Override public X accept(SemanticQueryWalker walker) { return walker.visitRootDerived( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java index c8e115f953..c13ae1a9b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java @@ -143,18 +143,8 @@ public abstract class AbstractSqmSelectQuery @Override public SqmDerivedRoot from(Subquery subquery) { - return from( subquery, false ); - } - - @Override - public SqmDerivedRoot fromLateral(Subquery subquery) { - return from( subquery, true ); - } - - @Override - public SqmDerivedRoot from(Subquery subquery, boolean lateral) { validateComplianceFromSubQuery(); - final SqmDerivedRoot root = new SqmDerivedRoot<>( (SqmSubQuery) subquery, null, lateral ); + final SqmDerivedRoot root = new SqmDerivedRoot<>( (SqmSubQuery) subquery, null ); addRoot( root ); return root; }