Reproducer for implicit group by issue with constantified case-when
@@ -259,6 +259,49 @@ public class CaseWhenTest extends AbstractCoreTest {
criteria.getResultList();
}
+@Test
+public void testImplicitGroupByCase() {
+ CriteriaBuilder<Tuple> criteria = cbf.create(em, Tuple.class)
+ .from(Document.class, "d")
+ .selectCase()
+ .when("version").eqExpression("1").thenExpression("'first'")
+ .otherwiseExpression("'later'")
+ .select("COUNT(id)");
+
+ final String queryString = criteria.getQueryString();
+
+ assertEquals("SELECT CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END, COUNT(d.id) FROM Document d GROUP BY CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END", queryString);
+}
+
+@Test
+public void testImplicitGroupByConstantifiedCase1() {
+ CriteriaBuilder<Tuple> criteria = cbf.create(em, Tuple.class)
+ .from(Document.class, "d")
+ .selectCase()
+ .when("version").eqExpression("1").then("first")
+ .otherwiseExpression("'later'")
+ .select("COUNT(id)");
+
+ final String queryString = criteria.getQueryString();
+
+ assertEquals("SELECT CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END, COUNT(d.id) FROM Document d GROUP BY CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END", queryString);
+}
+
+
+@Test
+public void testImplicitGroupByConstantifiedCase2() {
+ CriteriaBuilder<Tuple> criteria = cbf.create(em, Tuple.class)
+ .from(Document.class, "d")
+ .selectCase()
+ .when("version").eqExpression("1").thenExpression("'first'")
+ .otherwise("later")
+ .select("COUNT(id)");
+
+ final String queryString = criteria.getQueryString();
+
+ assertEquals("SELECT CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END, COUNT(d.id) FROM Document d GROUP BY CASE WHEN d.version = 1 THEN 'first' ELSE 'later' END", queryString);
+}
+
@Test
public void testCaseWhenSizeThenAttribute(){
CriteriaBuilder<Tuple> criteria = cbf.create(em, Tuple.class)
