Fix NPE when parsing modifying HQL.
Closes #3649 Original pull request: #3650
This commit is contained in:
committed by
Mark Paluch
parent
ae2aa63be3
commit
490d34a2b2
@@ -48,8 +48,12 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
|
||||
return false;
|
||||
} else if (ctx instanceof HqlParser.InsertStatementContext) {
|
||||
return false;
|
||||
} else if (ctx instanceof HqlParser.DeleteStatementContext) {
|
||||
return false;
|
||||
} else if (ctx instanceof HqlParser.UpdateStatementContext) {
|
||||
return false;
|
||||
} else {
|
||||
return isSubquery(ctx.getParent());
|
||||
return ctx.getParent() != null && isSubquery(ctx.getParent());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1027,16 +1027,22 @@ class HqlQueryTransformerTests {
|
||||
.isEqualTo("FROM Story WHERE enabled = true order by created desc");
|
||||
}
|
||||
|
||||
@Test // GH-2977
|
||||
void isSubqueryThrowsException() {
|
||||
|
||||
String query = """
|
||||
insert into MyEntity (id, col)
|
||||
select max(id), col
|
||||
from MyEntityStaging
|
||||
group by col
|
||||
""";
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = { """
|
||||
insert into MyEntity (id, col)
|
||||
select max(id), col
|
||||
from MyEntityStaging
|
||||
group by col
|
||||
""", """
|
||||
update MyEntity AS mes
|
||||
set mes.col = 'test'
|
||||
where mes.id = 1
|
||||
""", """
|
||||
delete MyEntity AS mes
|
||||
where mes.col = 'test'
|
||||
"""
|
||||
}) // GH-2977, GH-3649
|
||||
void isSubqueryThrowsException(String query) {
|
||||
assertThat(createQueryFor(query, Sort.unsorted())).isEqualToIgnoringWhitespace(query);
|
||||
}
|
||||
|
||||
@@ -1133,7 +1139,6 @@ class HqlQueryTransformerTests {
|
||||
}
|
||||
assertThat(count).describedAs("Found order by clause more than once in: \n%s", it).isOne();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void assertCountQuery(String originalQuery, String countQuery) {
|
||||
|
||||
Reference in New Issue
Block a user