Skip to content

modernize some code in o.h.query.sqm.produce.function #10561

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
Jul 17, 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 @@ -62,7 +62,7 @@ public void render(
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( getName() );
sqlAppender.appendSql( '(' );
final Expression arg = (Expression) sqlAstArguments.get( 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void render(
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "avg(" );
final Expression arg;
if ( sqlAstArguments.get( 0 ) instanceof Distinct ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void render(
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
final SqlAstNode arg = sqlAstArguments.get( 0 );
sqlAppender.appendSql( countFunctionName );
sqlAppender.appendSql( '(' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* A {@link ArgumentsValidator} that validates the array type is compatible with the element type.
*/
public class GenerateSeriesArgumentTypeResolver extends AbstractFunctionArgumentTypeResolver {
public class GenerateSeriesArgumentTypeResolver implements AbstractFunctionArgumentTypeResolver {

private final BasicType<Duration> durationType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
if ( filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause() ) {
if ( filter != null && !filterClauseSupported( translator ) ) {
throw new IllegalArgumentException( "Can't emulate filter clause for inverse distribution function [" + getName() + "]" );
}
sqlAppender.appendSql( getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
if ( filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause() ) {
if ( filter != null && !filterClauseSupported( translator ) ) {
throw new IllegalArgumentException( "Can't emulate filter clause for inverse distribution function [" + getName() + "]" );
}
sqlAppender.appendSql( getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "listagg(" );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
final Expression arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "group_concat(" );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
final Expression arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( functionName );
sqlAppender.appendSql( '(' );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "stats_mode(" );
if ( withinGroup == null || withinGroup.size() != 1 ) {
throw new IllegalArgumentException( "MODE function requires a WITHIN GROUP clause with exactly one order by item" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void render(
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( getName() );
sqlAppender.appendSql( '(' );
final Expression arg = (Expression) sqlAstArguments.get( 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getArgumentListSignature() {
return "(OBJECT element, INTEGER elementCount)";
}

private static class ArrayFillArgumentsValidator extends AbstractFunctionArgumentTypeResolver {
private static class ArrayFillArgumentsValidator implements AbstractFunctionArgumentTypeResolver {

public static final FunctionArgumentTypeResolver INSTANCE = new ArrayFillArgumentsValidator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && ( !supportsFilter || !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause() );
final boolean caseWrapper = filter != null && ( !supportsFilter || !filterClauseSupported( translator ) );
sqlAppender.appendSql( functionName );
sqlAppender.appendSql( '(' );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* A {@link FunctionArgumentTypeResolver} that resolves the array argument type based on the element argument type
* or the element argument type based on the array argument type.
*/
public class ArrayAndElementArgumentTypeResolver extends AbstractFunctionArgumentTypeResolver {
public class ArrayAndElementArgumentTypeResolver implements AbstractFunctionArgumentTypeResolver {

public static final FunctionArgumentTypeResolver DEFAULT_INSTANCE = new ArrayAndElementArgumentTypeResolver( 0, 1 );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* A {@link FunctionArgumentTypeResolver} that resolves the argument types for the {@code array_contains} function.
*/
public class ArrayContainsArgumentTypeResolver extends AbstractFunctionArgumentTypeResolver {
public class ArrayContainsArgumentTypeResolver implements AbstractFunctionArgumentTypeResolver {

public static final FunctionArgumentTypeResolver INSTANCE = new ArrayContainsArgumentTypeResolver();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* A {@link FunctionArgumentTypeResolver} that resolves the argument types for the {@code array_includes} function.
*/
public class ArrayIncludesArgumentTypeResolver extends AbstractFunctionArgumentTypeResolver {
public class ArrayIncludesArgumentTypeResolver implements AbstractFunctionArgumentTypeResolver {

public static final FunctionArgumentTypeResolver INSTANCE = new ArrayIncludesArgumentTypeResolver();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "json_arrayagg(" );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
final JsonNullBehavior nullBehavior;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected void render(
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "json_objectagg(" );
arguments.key().accept( translator );
sqlAppender.appendSql( valueSeparator );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "cast(string_agg(" );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
final Expression arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void render(
List<SortSpecification> withinGroup,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
final boolean caseWrapper = filter != null && !filterClauseSupported( translator );
sqlAppender.appendSql( "xmlagg(" );
final SqlAstNode firstArg = sqlAstArguments.get( 0 );
final Expression arg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ protected <T> SelfRenderingSqmWindowFunction<T> generateSqmWindowFunctionExpress
);
}

public static boolean filterClauseSupported(SqlAstTranslator<?> translator) {
return translator.getSessionFactory().getJdbcServices().getDialect().supportsFilterClause();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void validate(
BindingContext bindingContext) {
delegate.validate( arguments, functionName, bindingContext );
int count = 0;
for (SqmTypedNode<?> argument : arguments) {
for ( var argument : arguments ) {
// JdbcTypeIndicators indicators = typeConfiguration.getCurrentBaseSqlTypeIndicators();
final SqmExpressible<?> nodeType = argument.getNodeType();
final FunctionParameterType type = count < types.length ? types[count++] : types[types.length - 1];
Expand Down Expand Up @@ -182,7 +182,7 @@ public void validateSqlTypes(List<? extends SqlAstNode> arguments, String functi
for ( SqlAstNode argument : arguments ) {
if ( argument instanceof Expression expression ) {
final JdbcMappingContainer expressionType = expression.getExpressionType();
if (expressionType != null) {
if ( expressionType != null ) {
if ( isUnknownExpressionType( expressionType ) ) {
count += expressionType.getJdbcTypeCount();
}
Expand All @@ -199,8 +199,8 @@ public void validateSqlTypes(List<? extends SqlAstNode> arguments, String functi
*/
public static boolean isUnknownExpressionType(JdbcMappingContainer expressionType) {
return expressionType instanceof JavaObjectType
|| expressionType instanceof BasicType
&& isUnknown( ((BasicType<?>) expressionType).getJavaTypeDescriptor() );
|| expressionType instanceof BasicType<?> basicType
&& isUnknown( basicType.getJavaTypeDescriptor() );
}

private int validateArgument(int paramNumber, JdbcMappingContainer expressionType, String functionName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface FunctionArgumentTypeResolver {
* @return The resolved type.
* @deprecated Use {@link #resolveFunctionArgumentType(List, int, SqmToSqlAstConverter)} instead
*/
@Deprecated(forRemoval = true)
@Deprecated(forRemoval = true, since = "7.0")
@Nullable MappingModelExpressible<?> resolveFunctionArgumentType(
SqmFunction<?> function,
int argumentIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void validate(

@Override
public String getSignature() {
StringBuilder sig = new StringBuilder("(");
final StringBuilder sig = new StringBuilder("(");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the expected computed String is expected to be quite long, it could be better to initialize all the StringBuilder in this class with an initial capacity large enough to contain the average case ... ;)

for (int i=0; i<minNumOfArgs; i++) {
if (i!=0) {
sig.append(", ");
Expand Down Expand Up @@ -128,7 +128,7 @@ public void validate(

@Override
public String getSignature() {
StringBuilder sig = new StringBuilder("(");
final StringBuilder sig = new StringBuilder("(");
for (int i=0; i<number; i++) {
if (i!=0) {
sig.append(", ");
Expand Down Expand Up @@ -167,7 +167,7 @@ public void validate(

@Override
public String getSignature() {
StringBuilder sig = new StringBuilder("([");
final StringBuilder sig = new StringBuilder("([");
for (int i=0; i<maxNumOfArgs; i++) {
if (i!=0) {
sig.append(", ");
Expand All @@ -187,7 +187,7 @@ public void validate(
List<? extends SqmTypedNode<?>> arguments,
String functionName,
BindingContext bindingContext) {
if (arguments.size() < minNumOfArgs || arguments.size() > maxNumOfArgs) {
if ( arguments.size() < minNumOfArgs || arguments.size() > maxNumOfArgs ) {
throw new FunctionArgumentException(
String.format(
Locale.ROOT,
Expand All @@ -203,7 +203,7 @@ public void validate(

@Override
public String getSignature() {
StringBuilder sig = new StringBuilder("(");
final StringBuilder sig = new StringBuilder("(");
for (int i=0; i<maxNumOfArgs; i++) {
if (i==minNumOfArgs) {
sig.append("[");
Expand All @@ -226,8 +226,8 @@ public void validate(
List<? extends SqmTypedNode<?>> arguments,
String functionName,
BindingContext bindingContext) {
for ( SqmTypedNode<?> argument : arguments ) {
Class<?> argType = argument.getNodeJavaType().getJavaTypeClass();
for ( var argument : arguments ) {
var argType = argument.getNodeJavaType().getJavaTypeClass();
if ( !javaType.isAssignableFrom( argType ) ) {
throw new FunctionArgumentException(
String.format(
Expand Down Expand Up @@ -255,11 +255,8 @@ public void validate(
List<? extends SqmTypedNode<?>> arguments,
String functionName,
BindingContext bindingContext) {
validators.forEach( individualValidator -> individualValidator.validate(
arguments,
functionName,
bindingContext
) );
validators.forEach( individualValidator ->
individualValidator.validate( arguments, functionName, bindingContext ) );
}
};
}
Expand Down
Loading