HHH-13612 Quoted table name in FROM clause in @Formula gets wrongly qualified with generated alias
This commit is contained in:
parent
0dac348b94
commit
d28d214ec1
|
@ -167,8 +167,11 @@ public final class Template {
|
||||||
|
|
||||||
boolean hasMore = tokens.hasMoreTokens();
|
boolean hasMore = tokens.hasMoreTokens();
|
||||||
String nextToken = hasMore ? tokens.nextToken() : null;
|
String nextToken = hasMore ? tokens.nextToken() : null;
|
||||||
|
String token = null;
|
||||||
|
String previousToken;
|
||||||
while ( hasMore ) {
|
while ( hasMore ) {
|
||||||
String token = nextToken;
|
previousToken = token;
|
||||||
|
token = nextToken;
|
||||||
String lcToken = token.toLowerCase(Locale.ROOT);
|
String lcToken = token.toLowerCase(Locale.ROOT);
|
||||||
hasMore = tokens.hasMoreTokens();
|
hasMore = tokens.hasMoreTokens();
|
||||||
nextToken = hasMore ? tokens.nextToken() : null;
|
nextToken = hasMore ? tokens.nextToken() : null;
|
||||||
|
@ -203,7 +206,9 @@ public final class Template {
|
||||||
else {
|
else {
|
||||||
isOpenQuote = false;
|
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( '.' );
|
result.append( alias ).append( '.' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -232,7 +237,8 @@ public final class Template {
|
||||||
result.append(token);
|
result.append(token);
|
||||||
inExtractOrTrim = true;
|
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 )
|
&& !isFunctionOrKeyword( lcToken, nextToken, dialect, typeConfiguration )
|
||||||
&& !isLiteral( lcToken, nextToken, sql, symbols, tokens ) ) {
|
&& !isLiteral( lcToken, nextToken, sql, symbols, tokens ) ) {
|
||||||
result.append(alias)
|
result.append(alias)
|
||||||
|
@ -268,6 +274,10 @@ public final class Template {
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean notEndsWithDot(String token) {
|
||||||
|
return token == null || !token.endsWith( "." );
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isLiteral(
|
private static boolean isLiteral(
|
||||||
String lcToken, String next,
|
String lcToken, String next,
|
||||||
String sqlWhereString, String symbols, StringTokenizer tokens) {
|
String sqlWhereString, String symbols, StringTokenizer tokens) {
|
||||||
|
|
Loading…
Reference in New Issue