HHH-13612 Quoted table name in FROM clause in @Formula gets wrongly qualified with generated alias

This commit is contained in:
Andrea Boriero 2024-12-04 15:09:06 +01:00 committed by Andrea Boriero
parent 0dac348b94
commit d28d214ec1
1 changed files with 13 additions and 3 deletions

View File

@ -167,8 +167,11 @@ public final class Template {
boolean hasMore = tokens.hasMoreTokens();
String nextToken = hasMore ? tokens.nextToken() : null;
String token = null;
String previousToken;
while ( hasMore ) {
String token = nextToken;
previousToken = token;
token = nextToken;
String lcToken = token.toLowerCase(Locale.ROOT);
hasMore = tokens.hasMoreTokens();
nextToken = hasMore ? tokens.nextToken() : null;
@ -203,7 +206,9 @@ public final class Template {
else {
isOpenQuote = false;
}
if ( isOpenQuote ) {
if ( isOpenQuote
&& !inFromClause // don't want to append alias to tokens inside the from clause
&& notEndsWithDot( previousToken ) ) {
result.append( alias ).append( '.' );
}
}
@ -232,7 +237,8 @@ public final class Template {
result.append(token);
inExtractOrTrim = true;
}
else if ( isIdentifier(token)
else if ( !inFromClause // don't want to append alias to tokens inside the from clause
&& isIdentifier( token )
&& !isFunctionOrKeyword( lcToken, nextToken, dialect, typeConfiguration )
&& !isLiteral( lcToken, nextToken, sql, symbols, tokens ) ) {
result.append(alias)
@ -268,6 +274,10 @@ public final class Template {
return result.toString();
}
private static boolean notEndsWithDot(String token) {
return token == null || !token.endsWith( "." );
}
private static boolean isLiteral(
String lcToken, String next,
String sqlWhereString, String symbols, StringTokenizer tokens) {