Skip to content

Commit

Permalink
HHH-15998 Check dynamic instantiation arguments in group by clause
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel authored and beikov committed Feb 3, 2023
1 parent a34182d commit c7541cf
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,31 @@ private boolean selectClauseContains(SqmFrom<?, ?> from) {
return true;
}
for ( SqmSelection<?> selection : selections ) {
if ( selection.getSelectableNode() == from ) {
if ( selectableNodeContains( selection.getSelectableNode(), from ) ) {
return true;
}
}
return false;
}

private boolean selectableNodeContains(SqmSelectableNode<?> selectableNode, SqmFrom<?, ?> from) {
if ( selectableNode == from ) {
return true;
}
else if ( selectableNode instanceof SqmDynamicInstantiation ) {
for ( SqmDynamicInstantiationArgument<?> argument : ( (SqmDynamicInstantiation<?>) selectableNode ).getArguments() ) {
if ( selectableNodeContains( argument.getSelectableNode(), from ) ) {
return true;
}
}
}
return false;
}

private boolean groupByClauseContains(SqmFrom<?, ?> from) {
final SqmQuerySpec<?> sqmQuerySpec = (SqmQuerySpec<?>) currentSqmQueryPart;
for ( SqmExpression<?> expression : sqmQuerySpec.getGroupByClauseExpressions() ) {
if ( expression == from ) {
return true;
}
}
Expand Down Expand Up @@ -3888,6 +3912,11 @@ else if ( entityValuedModelPart instanceof AnonymousTupleEntityValuedModelPart )
// we need to expand to all columns, as we also expand this to all columns in the select clause
expandToAllColumns = tableGroup.isFetched() || selectClauseContains( path );
}
else if ( currentClauseStack.getCurrent() == Clause.ORDER ) {
// We must ensure that the order by expression be expanded if the group by
// contained the same expression, and that was expanded as well
expandToAllColumns = groupByClauseContains( path ) && ( tableGroup.isFetched() || selectClauseContains( path ) );
}
else {
expandToAllColumns = false;
}
Expand Down

0 comments on commit c7541cf

Please sign in to comment.