Skip to content

[6.6] HHH-19560 Remove TupleTransformer and ResultListTransformer from interpretation caching #10403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
package org.hibernate.dialect.function;

import java.util.List;
import java.util.function.Supplier;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.query.sqm.sql.SqmToSqlAstConverter;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
import org.hibernate.type.JavaObjectType;
import org.hibernate.type.spi.TypeConfiguration;

/**
* A function to pass through a SQL fragment.
Expand All @@ -30,7 +36,24 @@ public SqlFunction() {
super(
"sql",
StandardArgumentsValidators.min( 1 ),
StandardFunctionReturnTypeResolvers.invariant( JavaObjectType.INSTANCE ),
new FunctionReturnTypeResolver() {
@Override
public ReturnableType<?> resolveFunctionReturnType(
ReturnableType<?> impliedType,
@Nullable SqmToSqlAstConverter converter,
List<? extends SqmTypedNode<?>> arguments,
TypeConfiguration typeConfiguration) {
return impliedType != null
? impliedType
: typeConfiguration.getBasicTypeForJavaType( Object.class );
}

@Override
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
final BasicValuedMapping impliedType = impliedTypeAccess.get();
return impliedType != null ? impliedType : JavaObjectType.INSTANCE;
}
},
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,7 @@ private SelectInterpretationsKey selectInterpretationsKey(ResultSetMapping resul
return new SelectInterpretationsKey(
getQueryString(),
resultSetMapping,
getSynchronizedQuerySpaces(),
getQueryOptions().getTupleTransformer(),
getQueryOptions().getResultListTransformer()
getSynchronizedQuerySpaces()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ public class SelectInterpretationsKey implements QueryInterpretationCache.Key {
private final String sql;
private final JdbcValuesMappingProducer jdbcValuesMappingProducer;
private final Collection<String> querySpaces;
private final TupleTransformer tupleTransformer;
private final ResultListTransformer resultListTransformer;
private final int hash;

@Deprecated(forRemoval = true)
public SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces,
TupleTransformer tupleTransformer,
ResultListTransformer resultListTransformer) {
this( sql, jdbcValuesMappingProducer, querySpaces );
}

public SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces) {
this.sql = sql;
this.jdbcValuesMappingProducer = jdbcValuesMappingProducer;
this.querySpaces = querySpaces;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.hash = generateHashCode();
}

private SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces,
TupleTransformer tupleTransformer,
ResultListTransformer resultListTransformer,
int hash) {
this.sql = sql;
this.jdbcValuesMappingProducer = jdbcValuesMappingProducer;
this.querySpaces = querySpaces;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.hash = hash;
}

Expand All @@ -66,8 +66,6 @@ public QueryInterpretationCache.Key prepareForStore() {
sql,
jdbcValuesMappingProducer.cacheKeyInstance(),
new HashSet<>( querySpaces ),
tupleTransformer,
resultListTransformer,
hash
);
}
Expand All @@ -94,7 +92,6 @@ public boolean equals(Object o) {
return sql.equals( that.sql )
&& Objects.equals( jdbcValuesMappingProducer, that.jdbcValuesMappingProducer )
&& Objects.equals( querySpaces, that.querySpaces )
&& Objects.equals( tupleTransformer, that.tupleTransformer )
&& Objects.equals( resultListTransformer, that.resultListTransformer );
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
private final SqmSelectStatement<?> sqm;
private final DomainParameterXref domainParameterXref;
private final RowTransformer<R> rowTransformer;
private final SqmInterpreter<Object, ResultsConsumer<?, R>> executeQueryInterpreter;
private final SqmInterpreter<List<R>, Void> listInterpreter;
private final SqmInterpreter<ScrollableResultsImplementor<R>, ScrollMode> scrollInterpreter;
Expand All @@ -93,8 +92,6 @@ public ConcreteSqmSelectQueryPlan(
this.sqm = sqm;
this.domainParameterXref = domainParameterXref;

this.rowTransformer = determineRowTransformer( sqm, resultType, tupleMetadata, queryOptions );

final ListResultsConsumer.UniqueSemantic uniqueSemantic;
if ( sqm.producesUniqueResults() && !AppliedGraphs.containsCollectionFetches( queryOptions ) ) {
uniqueSemantic = ListResultsConsumer.UniqueSemantic.NONE;
Expand Down Expand Up @@ -122,7 +119,7 @@ public ConcreteSqmSelectQueryPlan(
jdbcSelect,
jdbcParameterBindings,
listInterpreterExecutionContext( hql, executionContext, jdbcSelect, subSelectFetchKeyHandler ),
rowTransformer,
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() ),
null,
resultCountEstimate,
resultsConsumer
Expand Down Expand Up @@ -153,7 +150,7 @@ public ConcreteSqmSelectQueryPlan(
jdbcSelect,
jdbcParameterBindings,
listInterpreterExecutionContext( hql, executionContext, jdbcSelect, subSelectFetchKeyHandler ),
rowTransformer,
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() ),
(Class<R>) executionContext.getResultType(),
uniqueSemantic,
resultCountEstimate
Expand Down Expand Up @@ -189,7 +186,7 @@ public ConcreteSqmSelectQueryPlan(
scrollMode,
jdbcParameterBindings,
new SqmJdbcExecutionContextAdapter( executionContext, jdbcSelect ),
rowTransformer,
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() ),
resultCountEstimate
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import org.hibernate.LockOptions;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.query.ResultListTransformer;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.spi.QueryInterpretationCache;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.sqm.tree.SqmStatement;
Expand Down Expand Up @@ -50,8 +48,6 @@ public static SqmInterpretationsKey createInterpretationsKey(InterpretationsKeyS
query.hashCode(),
keySource.getResultType(),
keySource.getQueryOptions().getLockOptions(),
keySource.getQueryOptions().getTupleTransformer(),
keySource.getQueryOptions().getResultListTransformer(),
memoryEfficientDefensiveSetCopy( keySource.getLoadQueryInfluencers().getEnabledFetchProfileNames() )
);
}
Expand Down Expand Up @@ -110,8 +106,6 @@ public static QueryInterpretationCache.Key generateNonSelectKey(InterpretationsK
private final Object query;
private final Class<?> resultType;
private final LockOptions lockOptions;
private final TupleTransformer<?> tupleTransformer;
private final ResultListTransformer<?> resultListTransformer;
private final Collection<String> enabledFetchProfiles;
private final int hashcode;

Expand All @@ -120,15 +114,11 @@ private SqmInterpretationsKey(
int hash,
Class<?> resultType,
LockOptions lockOptions,
TupleTransformer<?> tupleTransformer,
ResultListTransformer<?> resultListTransformer,
Collection<String> enabledFetchProfiles) {
this.query = query;
this.hashcode = hash;
this.resultType = resultType;
this.lockOptions = lockOptions;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.enabledFetchProfiles = enabledFetchProfiles;
}

Expand All @@ -140,8 +130,6 @@ public QueryInterpretationCache.Key prepareForStore() {
resultType,
// Since lock options might be mutable, we need a copy for the cache key
lockOptions.makeDefensiveCopy(),
tupleTransformer,
resultListTransformer,
enabledFetchProfiles
);
}
Expand All @@ -165,8 +153,6 @@ public boolean equals(Object o) {
&& query.equals( that.query )
&& Objects.equals( resultType, that.resultType )
&& Objects.equals( lockOptions, that.lockOptions )
&& Objects.equals( tupleTransformer, that.tupleTransformer )
&& Objects.equals( resultListTransformer, that.resultListTransformer )
&& Objects.equals( enabledFetchProfiles, that.enabledFetchProfiles );
}

Expand Down
Loading