Skip to content

Commit a75fa5b

Browse files
author
Mike Mannion
committed
HHH-19704 provides test cases for LISTAGG function variants, some of which work in the current version, some of which do not.
1 parent 7d4af9b commit a75fa5b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/sql/TemplateTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,74 @@ public void testFetchGrammarVariants(SessionFactoryScope scope) {
135135
"select {@}." + dialect.quote("`first`") + " from users fetch first 1 row only", factory );
136136
}
137137

138+
@Test
139+
@JiraKey("HHH-19704")
140+
public void testOrderedSetAggregationVariants(SessionFactoryScope scope) {
141+
SessionFactoryImplementor factory = scope.getSessionFactory();
142+
143+
assertWhereStringTemplate(
144+
"SELECT LISTAGG(employee_name, ', ') WITHIN GROUP (ORDER BY hire_date) FROM employees",
145+
"SELECT LISTAGG({@}.employee_name, ', ') WITHIN GROUP (ORDER BY {@}.hire_date) FROM employees",
146+
factory );
147+
148+
assertWhereStringTemplate(
149+
"SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) FROM employees",
150+
"SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY {@}.salary) FROM employees",
151+
factory );
152+
153+
assertWhereStringTemplate(
154+
"SELECT PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY salary) FROM employees",
155+
"SELECT PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY {@}.salary) FROM employees",
156+
factory );
157+
158+
assertWhereStringTemplate(
159+
"SELECT MODE() WITHIN GROUP (ORDER BY job_title) FROM employees",
160+
"SELECT MODE() WITHIN GROUP (ORDER BY {@}.job_title) FROM employees",
161+
factory );
162+
}
163+
164+
@Test
165+
@JiraKey("HHH-19704")
166+
public void testOrderedSetAggregationExtendedVariants(SessionFactoryScope scope) {
167+
SessionFactoryImplementor factory = scope.getSessionFactory();
168+
169+
assertWhereStringTemplate(
170+
"""
171+
SELECT LISTAGG(employee_name, ', ') ON OVERFLOW ERROR WITHIN GROUP (ORDER BY hire_date)
172+
FROM employees""",
173+
"""
174+
SELECT LISTAGG({@}.employee_name, ', ') ON OVERFLOW ERROR WITHIN GROUP (ORDER BY {@}.hire_date)
175+
FROM employees""",
176+
factory );
177+
178+
assertWhereStringTemplate(
179+
"""
180+
SELECT LISTAGG(employee_name, ', ') ON OVERFLOW TRUNCATE WITH COUNT WITHIN GROUP (ORDER BY hire_date)
181+
FROM employees""",
182+
"""
183+
SELECT LISTAGG({@}.employee_name, ', ') ON OVERFLOW TRUNCATE WITH COUNT WITHIN GROUP (ORDER BY {@}.hire_date)
184+
FROM employees""",
185+
factory );
186+
187+
assertWhereStringTemplate(
188+
"""
189+
SELECT LISTAGG(employee_name, ', ') ON OVERFLOW TRUNCATE '...' WITH COUNT WITHIN GROUP (ORDER BY hire_date)
190+
FROM employees""",
191+
"""
192+
SELECT LISTAGG({@}.employee_name, ', ') ON OVERFLOW TRUNCATE '...' WITH COUNT WITHIN GROUP (ORDER BY {@}.hire_date)
193+
FROM employees""",
194+
factory );
195+
196+
assertWhereStringTemplate(
197+
"""
198+
SELECT LISTAGG(employee_name, ', ') ON OVERFLOW TRUNCATE WITHOUT COUNT WITHIN GROUP (ORDER BY hire_date)
199+
FROM employees""",
200+
"""
201+
SELECT LISTAGG({@}.employee_name, ', ') ON OVERFLOW TRUNCATE WITHOUT COUNT WITHIN GROUP (ORDER BY {@}.hire_date)
202+
FROM employees""",
203+
factory );
204+
}
205+
138206
private static void assertWhereStringTemplate(String sql, SessionFactoryImplementor sf) {
139207
assertEquals( sql,
140208
Template.renderWhereStringTemplate(

0 commit comments

Comments
 (0)