HHH-16945 Cast to varbinary for tuple distinct count on SQL Server to avoid collation issues

This commit is contained in:
Christian Beikov 2023-09-05 19:57:22 +02:00
parent a145db8d9b
commit ce19d9600e
3 changed files with 30 additions and 4 deletions

View File

@ -300,7 +300,8 @@ public class SQLServerLegacyDialect extends AbstractTransactSQLDialect {
"count_big",
"+",
"varchar(max)",
false
false,
"varbinary(max)"
)
);

View File

@ -314,7 +314,8 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
"count_big",
"+",
"varchar(max)",
false
true,
"varbinary(max)"
)
);

View File

@ -49,6 +49,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
private final String concatOperator;
private final String concatArgumentCastType;
private final boolean castDistinctStringConcat;
private final String distinctArgumentCastType;
public CountFunction(
Dialect dialect,
@ -79,7 +80,8 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
"count",
concatOperator,
concatArgumentCastType,
castDistinctStringConcat
castDistinctStringConcat,
concatArgumentCastType
);
}
@ -91,6 +93,27 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
String concatOperator,
String concatArgumentCastType,
boolean castDistinctStringConcat) {
this(
dialect,
typeConfiguration,
defaultArgumentRenderingMode,
countFunctionName,
concatOperator,
concatArgumentCastType,
castDistinctStringConcat,
concatArgumentCastType
);
}
public CountFunction(
Dialect dialect,
TypeConfiguration typeConfiguration,
SqlAstNodeRenderingMode defaultArgumentRenderingMode,
String countFunctionName,
String concatOperator,
String concatArgumentCastType,
boolean castDistinctStringConcat,
String distinctArgumentCastType) {
super(
"count",
FunctionKind.AGGREGATE,
@ -106,6 +129,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
this.concatOperator = concatOperator;
this.concatArgumentCastType = concatArgumentCastType;
this.castDistinctStringConcat = castDistinctStringConcat;
this.distinctArgumentCastType = distinctArgumentCastType;
}
@Override
@ -211,7 +235,7 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
sqlAppender.appendSql( "')" );
if ( castDistinctStringConcat ) {
sqlAppender.appendSql( " as " );
sqlAppender.appendSql( concatArgumentCastType );
sqlAppender.appendSql( distinctArgumentCastType );
sqlAppender.appendSql( ')' );
}
if ( caseWrapper ) {