From 0dfa91f6ecbc5101f194f895a63609be85b06fc0 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 8 Feb 2022 14:25:38 +0100 Subject: [PATCH] add a test --- .../orm/test/query/hql/FunctionTests.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index df45bae8a1..939b2d41d2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -128,6 +128,44 @@ public class FunctionTests { ); } + @Test + public void testNoMaxMinSumIndexElement(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + assertThat( session.createQuery("select max(index(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(1) ); + assertThat( session.createQuery("select max(element(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(2.0) ); + + assertThat( session.createQuery("select sum(index(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(1L) ); + assertThat( session.createQuery("select sum(element(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(3.0) ); + + //TODO: why does this fail?? + assertThat( session.createQuery("select avg(index(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(0.5) ); + assertThat( session.createQuery("select avg(element(l)) from EntityOfLists eol join eol.listOfNumbers l group by eol") + .getSingleResult(), is(1.5) ); + + assertThat( session.createQuery("select max(index(m)) from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1) ); + assertThat( session.createQuery("select max(element(m)) from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1.0) ); + + assertThat( session.createQuery("select sum(index(m)) from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1L) ); + assertThat( session.createQuery("select sum(element(m))from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1.0) ); + + assertThat( session.createQuery("select avg(index(m)) from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1.0) ); + assertThat( session.createQuery("select avg(element(m)) from EntityOfMaps eom join eom.numberByNumber m group by eom") + .getSingleResult(), is(1.0) ); + } + ); + } + @Test public void testMaxindexMaxelement(SessionFactoryScope scope) { scope.inTransaction(