8000 HHH-6856 RowValueConstructorSyntax with In syntax is not working · JavaInCloud/hibernate-orm@eca0489 · GitHub
[go: up one dir, main page]

Skip to content

Commit eca0489

Browse files
stliusebersole
authored andcommitted
HHH-6856 RowValueConstructorSyntax with In syntax is not working
1 parent 9a7924d commit eca0489

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

hibernate-core/src/main/antlr/sql-gen.g

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ inList
309309
;
310310
311311
simpleExprList
312-
: { out("("); } (e:simpleExpr { separator(e," , "); } )* { out(")"); }
312+
: { out("("); } (e:simpleExprWithVectorExpr { separator(e," , "); } )* { out(")"); }
313+
;
314+
315+
simpleExprWithVectorExpr
316+
: simpleExpr
317+
| #( VECTOR_EXPR { out("("); } (e:expr { separator(e," , "); } )* { out(")"); } )
313318
;
314319
315320
// A simple expression, or a sub-select with parens around it.

hibernate-core/src/matrix/java/org/hibernate/test/criteria/CriteriaQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ public void testAliasJoinCriterion() {
16961696
session.close();
16971697
}
16981698

1699-
@Test
1699+
@Test
17001700
public void testCriteriaCollectionOfValue() {
17011701
Session session = openSession();
17021702
Transaction t = session.beginTransaction();
@@ -1806,7 +1806,7 @@ public void testMultiplePropertiesSubquery() {
18061806
session.close();
18071807
}
18081808

1809-
@Test
1809+
@Test
18101810
public void testCriteriaCollectionOfComponent() {
18111811
Session session = openSession();
18121812
Transaction t = session.beginTransaction();

hibernate-core/src/matrix/java/org/hibernate/test/hql/HQLTest.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,44 @@ public void testRowValueConstructorSyntaxInInList2() {
139139
}
140140

141141
@Test
142-
@RequiresDialectFeature( DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck .class )
143-
public void testRowValueConstructorSyntaxInInList() {
142+
public void testRowValueConstructorSyntaxInInListBeingTranslated() {
144143
QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
145144
assertInExist("'in' should be translated to 'and'", false, translator);
146145
translator = createNewQueryTranslator("from LineItem l where l.id in ?");
147146
assertInExist("'in' should be translated to 'and'", false, translator);
148147
translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
149148
assertInExist("'in' should be translated to 'and'", false, translator);
150149
translator = createNewQueryTranslator("from Animal a where a.id in (?)");
151-
assertInExist("only translate tuple with 'in' syntax", true, translator);
150+
assertInExist("only translated tuple has 'in' syntax", true, translator);
152151
translator = createNewQueryTranslator("from Animal a where a.id in ?");
153-
assertInExist("only translate tuple with 'in' syntax", true, translator);
152+
assertInExist("only translated tuple has 'in' syntax", true, translator);
154153
translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
155-
assertInExist("do not translate subqueries", true, translator);
154+
assertInExist("do not translate sub-queries", true, translator);
155+
}
156156

157+
@Test
158+
@RequiresDialectFeature( DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck.class )
159+
public void testRowValueConstructorSyntaxInInList() {
160+
QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
161+
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
162+
translator = createNewQueryTranslator("from LineItem l where l.id in ?");
163+
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
164+
translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
165+
assertInExist(" 'in' should be kept, since the dialect supports this syntax", true,translator);
166+
translator = createNewQueryTranslator("from Animal a where a.id in (?)");
167+
assertInExist("only translated tuple has 'in' syntax", true, translator);
168+
translator = createNewQueryTranslator("from Animal a where a.id in ?");
169+
assertInExist("only translated tuple has 'in' syntax", true, translator);
170+
translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
171+
assertInExist("do not translate sub-queries", true, translator);
157172
}
158173

159174
private void assertInExist( String message, boolean expected, QueryTranslatorImpl translator ) {
160175
AST ast = translator.getSqlAST().getWalker().getAST();
161176
QueryNode queryNode = (QueryNode) ast;
162-
AST inNode = ASTUtil.findTypeInChildren( queryNode, HqlTokenTypes.IN );
163-
assertEquals( message, expected, inNode != null );
177+
AST whereNode = ASTUtil.findTypeInChildren( queryNode, HqlTokenTypes.WHERE );
178+
AST inNode = whereNode.getFirstChild();
179+
assertEquals( message, expected, inNode != null && inNode.getType() == HqlTokenTypes.IN );
164180
}
165181

166182
@Test

0 commit comments

Comments
 (0)
0