Skip to content

Commit

Permalink
HQL function names should support schema-based prefixes.
Browse files Browse the repository at this point in the history
See #3099
  • Loading branch information
gregturn committed Aug 4, 2023
1 parent 7eeca10 commit 7e7b050
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ character
;

functionName
: reservedWord
: reservedWord ('.' reservedWord)*
;

reservedWord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,17 @@ public List<JpaQueryParsingToken> visitCharacter(HqlParser.CharacterContext ctx)

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1556,4 +1556,32 @@ void typeShouldBeAValidParameter() {
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
""");
}
}

0 comments on commit 7e7b050

Please sign in to comment.