Skip to content

Commit f939240

Browse files
committed
mention ordered set functions in documentation
1 parent a4a15e8 commit f939240

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

documentation/src/main/asciidoc/userguide/chapters/query/hql/QueryLanguage.adoc

+30
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,36 @@ include::{sourcedir}/HQLTest.java[tags=hql-aggregate-functions-filter-example]
19151915
----
19161916
====
19171917
1918+
[[hql-aggregate-functions-orderedset]]
1919+
==== Ordered set aggregate functions
1920+
1921+
_Ordered set aggregate functions_ are special aggregate functions that have:
1922+
1923+
- not only an optional filter clause, but also
1924+
- a _within group clause_, a mini-`order by` clause.
1925+
1926+
IMPORTANT: Ordered set aggregate functions are not available on every database.
1927+
1928+
The most widely-supported ordered set aggregate function is one which builds a string by concatenating the values within a group.
1929+
This function has different names on different databases, but HQL abstracts these differences, and—following ANSI SQL—calls it `listagg()`.
1930+
1931+
[[hql-aggregate-functions-within-group-example]]
1932+
====
1933+
[source, JAVA, indent=0]
1934+
----
1935+
include::{sourcedir}/HQLTest.java[tags=hql-aggregate-functions-within-group-example]
1936+
----
1937+
====
1938+
1939+
The following ordered set aggregate functions are also available on many platforms:
1940+
1941+
|===
1942+
| Type | functions
1943+
1944+
| Inverse distribution functions | `mode()`, `percentile_cont()`, `percentile_disc()`
1945+
| Hypothetical set functions | `rank()`, `dense_rank()`, `percent_rank()`, `cume_dist()`
1946+
|===
1947+
19181948
[[hql-where-clause]]
19191949
=== Restriction: `where`
19201950

documentation/src/test/java/org/hibernate/userguide/hql/HQLTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,22 @@ public void test_hql_aggregate_functions_filter_example() {
14541454
});
14551455
}
14561456

1457+
@Test @SkipForDialect(DerbyDialect.class)
1458+
public void test_hql_aggregate_functions_within_group_example() {
1459+
doInJPA(this::entityManagerFactory, entityManager -> {
1460+
//tag::hql-aggregate-functions-within-group-example[]
1461+
1462+
List<String> callCount = entityManager.createQuery(
1463+
"select listagg(p.number, ', ') within group (order by p.type,p.number) " +
1464+
"from Phone p " +
1465+
"group by p.person",
1466+
String.class)
1467+
.getResultList();
1468+
//end::hql-aggregate-functions-within-group-example[]
1469+
assertNotNull(callCount.get(0));
1470+
});
1471+
}
1472+
14571473
@Test
14581474
@SkipForDialect(value = DerbyDialect.class, comment = "See https://issues.apache.org/jira/browse/DERBY-2072")
14591475
public void test_hql_concat_function_example() {

0 commit comments

Comments
 (0)