Skip to content

HHH-19560 Remove TupleTransformer and ResultListTransformer from interpretation caching #10399

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 @@ -5,16 +5,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.metamodel.model.domain.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 @@ -28,7 +34,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 @@ -1005,13 +1005,10 @@ public static int determineBindValueMaxCount(boolean paddingEnabled, int inExprL
}

private SelectInterpretationsKey selectInterpretationsKey(ResultSetMapping resultSetMapping) {
final QueryOptions options = getQueryOptions();
return new SelectInterpretationsKey(
getQueryString(),
resultSetMapping,
getSynchronizedQuerySpaces(),
options.getTupleTransformer(),
options.getResultListTransformer()
getSynchronizedQuerySpaces()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,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 @@ -64,8 +64,6 @@ public QueryInterpretationCache.Key prepareForStore() {
sql,
jdbcValuesMappingProducer.cacheKeyInstance(),
new HashSet<>( querySpaces ),
tupleTransformer,
resultListTransformer,
hash
);
}
Expand All @@ -89,8 +87,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 );
&& Objects.equals( querySpaces, that.querySpaces );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
private final SqmSelectStatement<?> sqm;
private final DomainParameterXref domainParameterXref;
private final RowTransformer<R> rowTransformer;
private final SqmInterpreter<?, ? extends ResultsConsumer<?, R>> executeQueryInterpreter;
private final SqmInterpreter<List<R>, Void> listInterpreter;
private final SqmInterpreter<ScrollableResultsImplementor<R>, ScrollMode> scrollInterpreter;
Expand All @@ -92,8 +91,6 @@ public ConcreteSqmSelectQueryPlan(
this.sqm = sqm;
this.domainParameterXref = domainParameterXref;

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

final ListResultsConsumer.UniqueSemantic uniqueSemantic =
sqm.producesUniqueResults() && !containsCollectionFetches( queryOptions )
? ListResultsConsumer.UniqueSemantic.NONE
Expand All @@ -118,7 +115,7 @@ public ConcreteSqmSelectQueryPlan(
jdbcSelect,
jdbcParameterBindings,
listInterpreterExecutionContext( hql, executionContext, jdbcSelect, subSelectFetchKeyHandler ),
rowTransformer,
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() ),
null,
resultCountEstimate,
resultsConsumer
Expand Down Expand Up @@ -150,7 +147,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 @@ -186,7 +183,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 @@ -9,8 +9,6 @@
import java.util.Set;

import org.hibernate.LockOptions;
import org.hibernate.query.ResultListTransformer;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.spi.QueryInterpretationCache;
import org.hibernate.query.sqm.spi.InterpretationsKeySource;

Expand All @@ -28,8 +26,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 @@ -86,8 +82,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 @@ -96,15 +90,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 @@ -116,8 +106,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 @@ -139,8 +127,6 @@ public boolean equals(Object other) {
&& this.query.equals( that.query )
&& Objects.equals( this.resultType, that.resultType )
&& Objects.equals( this.lockOptions, that.lockOptions )
&& Objects.equals( this.tupleTransformer, that.tupleTransformer )
&& Objects.equals( this.resultListTransformer, that.resultListTransformer )
&& Objects.equals( this.enabledFetchProfiles, that.enabledFetchProfiles );
}

Expand Down