Skip to content

Commit

Permalink
HHH-15613 remove lateral roots from criteria API
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking authored and beikov committed Oct 19, 2022
1 parent 4c59f2d commit 4b1a13d
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 59 deletions.
Expand Up @@ -18,12 +18,5 @@ public interface JpaDerivedFrom<T> extends JpaFrom<T,T> {
* The subquery part for this derived from node.
*/
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();

}
Expand Up @@ -15,4 +15,12 @@
@Incubating
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();

}
Expand Up @@ -38,26 +38,6 @@ public interface JpaSelectCriteria<T> extends AbstractQuery<T>, JpaCriteriaBase
*/
<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
JpaSelectCriteria<T> distinct(boolean distinct);

Expand Down
Expand Up @@ -400,8 +400,7 @@ public SqmDerivedRoot<?> visitRootDerived(SqmDerivedRoot<?> sqmRoot) {
}
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 );
Expand Down
Expand Up @@ -1661,10 +1661,8 @@ public SqmRoot<?> visitRootSubquery(HqlParser.RootSubqueryContext ctx) {
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;
Expand All @@ -1680,7 +1678,7 @@ public SqmRoot<?> visitRootSubquery(HqlParser.RootSubqueryContext ctx) {

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 );

Expand Down
Expand Up @@ -2562,7 +2562,7 @@ protected void consumeFromClauseRoot(SqmRoot<?> sqmRoot) {
identifierVariable,
columnNames,
tableGroupProducer.getCompatibleTableExpressions(),
derivedRoot.isLateral(),
false,
true,
creationContext.getSessionFactory()
);
Expand Down
Expand Up @@ -28,16 +28,13 @@
public class SqmDerivedRoot<T> extends SqmRoot<T> implements JpaDerivedRoot<T> {

private final SqmSubQuery<T> subQuery;
private final boolean lateral;

public SqmDerivedRoot(
SqmSubQuery<T> subQuery,
String alias,
boolean lateral) {
String alias) {
this(
SqmCreationHelper.buildRootNavigablePath( "<<derived>>", alias ),
subQuery,
lateral,
new AnonymousTupleType<>( subQuery ),
alias
);
Expand All @@ -46,7 +43,6 @@ public SqmDerivedRoot(
protected SqmDerivedRoot(
NavigablePath navigablePath,
SqmSubQuery<T> subQuery,
boolean lateral,
SqmPathSource<T> pathSource,
String alias) {
super(
Expand All @@ -57,7 +53,6 @@ protected SqmDerivedRoot(
subQuery.nodeBuilder()
);
this.subQuery = subQuery;
this.lateral = lateral;
}

@Override
Expand All @@ -71,7 +66,6 @@ public SqmDerivedRoot<T> copy(SqmCopyContext context) {
new SqmDerivedRoot<>(
getNavigablePath(),
getQueryPart().copy( context ),
isLateral(),
getReferencedPathSource(),
getExplicitAlias()
)
Expand All @@ -85,11 +79,6 @@ public SqmSubQuery<T> getQueryPart() {
return subQuery;
}

@Override
public boolean isLateral() {
return lateral;
}

@Override
public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitRootDerived( this );
Expand Down
Expand Up @@ -143,18 +143,8 @@ public <X> SqmRoot<X> from(Class<X> entityClass) {

@Override
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();
final SqmDerivedRoot<X> root = new SqmDerivedRoot<>( (SqmSubQuery<X>) subquery, null, lateral );
final SqmDerivedRoot<X> root = new SqmDerivedRoot<>( (SqmSubQuery<X>) subquery, null );
addRoot( root );
return root;
}
Expand Down

0 comments on commit 4b1a13d

Please sign in to comment.