HHH-16198 - Fix splitting of SqlAstCreationState

This commit is contained in:
Steve Ebersole 2023-03-01 08:20:53 -06:00 committed by Christian Beikov
parent 0469b3b605
commit cb853c2c3e
2 changed files with 29 additions and 48 deletions

View File

@ -154,7 +154,8 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
SqmParameterResolutionConsumer parameterResolutionConsumer) { SqmParameterResolutionConsumer parameterResolutionConsumer) {
this.parameterResolutionConsumer = parameterResolutionConsumer; this.parameterResolutionConsumer = parameterResolutionConsumer;
for ( Assignment assignment : super.visitSetClause( setClause ) ) { final List<Assignment> assignments = super.visitSetClause( setClause );
for ( Assignment assignment : assignments ) {
assignmentConsumer.accept( assignment ); assignmentConsumer.accept( assignment );
} }
} }

View File

@ -926,29 +926,15 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
for ( SqmAssignment<?> sqmAssignment : setClause.getAssignments() ) { for ( SqmAssignment<?> sqmAssignment : setClause.getAssignments() ) {
targetColumnReferences.clear(); targetColumnReferences.clear();
pushProcessingState(
new SqlAstProcessingStateImpl(
getCurrentProcessingState(),
this,
getCurrentClauseStack()::getCurrent) {
@Override
public Expression resolveSqlExpression(
ColumnReferenceKey key,
Function<SqlAstProcessingState, Expression> creator) {
final Expression expression = getParentState()
.getSqlExpressionResolver()
.resolveSqlExpression( key, creator );
assert expression instanceof ColumnReference;
targetColumnReferences.add( (ColumnReference) expression );
return expression;
}
},
getFromClauseIndex()
);
currentClauseStack.push( Clause.SET );
final SqmPathInterpretation<?> assignedPathInterpretation; final SqmPathInterpretation<?> assignedPathInterpretation;
try { try {
pushProcessingState(
createAssignmentProcessingState( targetColumnReferences ),
getFromClauseIndex()
);
currentClauseStack.push( Clause.SET );
assignedPathInterpretation = (SqmPathInterpretation<?>) sqmAssignment.getTargetPath().accept( this ); assignedPathInterpretation = (SqmPathInterpretation<?>) sqmAssignment.getTargetPath().accept( this );
} }
finally { finally {
@ -956,32 +942,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
popProcessingStateStack(); popProcessingStateStack();
} }
try {
inferrableTypeAccessStack.push( assignedPathInterpretation::getExpressionType ); inferrableTypeAccessStack.push( assignedPathInterpretation::getExpressionType );
// final List<ColumnReference> valueColumnReferences = new ArrayList<>();
// todo: check if we can remove this
pushProcessingState(
new SqlAstProcessingStateImpl(
getCurrentProcessingState(),
this,
getCurrentClauseStack()::getCurrent) {
@Override
public Expression resolveSqlExpression(
ColumnReferenceKey key,
Function<SqlAstProcessingState, Expression> creator) {
final Expression expression = getParentState()
.getSqlExpressionResolver()
.resolveSqlExpression( key, creator );
assert expression instanceof ColumnReference;
// valueColumnReferences.add( (ColumnReference) expression );
return expression;
}
},
getFromClauseIndex()
);
currentClauseStack.push( Clause.SET_EXPRESSION ); currentClauseStack.push( Clause.SET_EXPRESSION );
try {
final SqmExpression<?> assignmentValue = sqmAssignment.getValue(); final SqmExpression<?> assignmentValue = sqmAssignment.getValue();
final SqmParameter<?> assignmentValueParameter = getSqmParameter( assignmentValue ); final SqmParameter<?> assignmentValueParameter = getSqmParameter( assignmentValue );
if ( assignmentValueParameter != null ) { if ( assignmentValueParameter != null ) {
@ -1036,13 +1000,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
} }
} }
currentClauseStack.pop();
} }
finally { finally {
popProcessingStateStack(); currentClauseStack.pop();
inferrableTypeAccessStack.pop(); inferrableTypeAccessStack.pop();
} }
} }
if ( aggregateColumnAssignmentHandler != null ) { if ( aggregateColumnAssignmentHandler != null ) {
aggregateColumnAssignmentHandler.aggregateAssignments( assignments ); aggregateColumnAssignmentHandler.aggregateAssignments( assignments );
} }
@ -1050,6 +1014,22 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return assignments; return assignments;
} }
private SqlAstProcessingStateImpl createAssignmentProcessingState(ArrayList<ColumnReference> targetColumnReferences) {
return new SqlAstProcessingStateImpl( getCurrentProcessingState(), this, getCurrentClauseStack()::getCurrent ) {
@Override
public Expression resolveSqlExpression(
ColumnReferenceKey key,
Function<SqlAstProcessingState, Expression> creator) {
final Expression expression = getParentState()
.getSqlExpressionResolver()
.resolveSqlExpression( key, creator );
assert expression instanceof ColumnReference;
targetColumnReferences.add( (ColumnReference) expression );
return expression;
}
};
}
private void addAssignment( private void addAssignment(
List<Assignment> assignments, List<Assignment> assignments,
AggregateColumnAssignmentHandler aggregateColumnAssignmentHandler, AggregateColumnAssignmentHandler aggregateColumnAssignmentHandler,