HQL function names should support schema-based prefixes.

See #3099
This commit is contained in:
Greg L. Turnquist
2023-08-04 10:26:14 -05:00
parent b5106d1ada
commit a5cfcfb157
3 changed files with 40 additions and 2 deletions

View File

@@ -686,7 +686,7 @@ character
;
functionName
: reservedWord
: reservedWord ('.' reservedWord)*
;
reservedWord

View File

@@ -2503,7 +2503,17 @@ class HqlQueryRenderer extends HqlBaseVisitor<List<JpaQueryParsingToken>> {
@Override
public List<JpaQueryParsingToken> visitFunctionName(HqlParser.FunctionNameContext ctx) {
return visit(ctx.reservedWord());
List<JpaQueryParsingToken> tokens = new ArrayList<>();
ctx.reservedWord().forEach(reservedWordContext -> {
tokens.addAll(visit(reservedWordContext));
NOSPACE(tokens);
tokens.add(TOKEN_DOT);
});
CLIP(tokens);
return tokens;
}
@Override

View File

@@ -1556,4 +1556,32 @@ class HqlQueryRendererTests {
assertQuery("select e from Employee e where e.type = :_type");
assertQuery("select te from TestEntity te where te.type = :type");
}
@Test // GH-3099
void functionNamesShouldSupportSchemaScoping() {
assertQuery("""
SELECT b
FROM MyEntity b
WHERE b.status = :status
AND utl_raw.cast_to_varchar2((nlssort(lower(b.name), 'nls_sort=binary_ai'))) LIKE lower(:name)
ORDER BY utl_raw.cast_to_varchar2((nlssort(lower(b.name), 'nls_sort=binary_ai'))) ASC
""");
assertQuery("""
select b
from Bairro b
where b.situacao = :situacao
and utl_raw.cast_to_varchar2((nlssort(lower(b.nome), 'nls_sort=binary_ai'))) like lower(:nome)
order by utl_raw.cast_to_varchar2((nlssort(lower(b.nome), 'nls_sort=binary_ai'))) ASC
""");
assertQuery("""
select b
from Bairro b
where b.situacao = :situacao
and CTM_UTLRAW_NLSSORT_LOWER(b.nome) like lower(:nome)
order by CTM_UTLRAW_NLSSORT_LOWER(b.nome) ASC
""");
}
}