Skip to content

Commit 2f1c2e1

Browse files
committed
median function documentation, improve test
1 parent dd0b1b2 commit 2f1c2e1

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

documentation/src/main/asciidoc/querylanguage/Relational.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,17 @@ The standard aggregate functions defined in both ANSI SQL and JPQL are these one
178178

179179
| `count()`, including `count(distinct)`, `count(all)`, and `count(*)` | Any | `Long` | ✔/✔
180180
| `avg()` | Any numeric type | `Double` | ✔/✔
181+
| `median()` | Any numeric type | `Double` | ✖/✖
181182
| `min()` | Any numeric type, or string | Same as the argument type | ✔/✔
182183
| `max()` | Any numeric type, or string | Same as the argument type | ✔/✔
183184
| `sum()` | Any numeric type | See table below | ✔/✔
184185
| `var_pop()`, `var_samp()` | Any numeric type | `Double` | ✖/✔
185186
| `stddev_pop()`, `stddev_samp()` | Any numeric type | `Double` | ✖/✔
186187
|===
187188

189+
[NOTE]
190+
The `median()` function is not supported on MySQL or Sybase ASE.
191+
188192
[[aggregate-functions-example]]
189193
[source, hql]
190194
[%unbreakable]

hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262

6363
/**
6464
* A {@linkplain Dialect SQL dialect} for HSQLDB (HyperSQL) 2.6.1 and above.
65+
* <p>
66+
* Please refer to the
67+
* <a href="https://hsqldb.org/doc/2.0/guide/index.html">HyperSQL User Guide</a>.
6568
*
6669
* @author Christoph Sturm
6770
* @author Phillip Baird

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,12 @@ public void testFormatTime(SessionFactoryScope scope) {
23162316
public void testMedian(SessionFactoryScope scope) {
23172317
scope.inTransaction(
23182318
session -> {
2319+
assertEquals( 1.0,
2320+
session.createQuery("select median(e.theDouble) from EntityOfBasics e", Double.class).getSingleResult(),
2321+
1e-5);
2322+
assertEquals( 5.0,
2323+
session.createQuery("select median(e.theInt) from EntityOfBasics e", Double.class).getSingleResult(),
2324+
1e-5);
23192325
List<Object[]> list = session.createQuery("select median(e.theDouble), median(e.theInt) from EntityOfBasics e", Object[].class)
23202326
.list();
23212327
assertEquals( 1, list.size() );

hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,11 @@ public boolean apply(Dialect dialect) {
552552
public static class SupportsMedian implements DialectFeatureCheck {
553553
public boolean apply(Dialect dialect) {
554554
dialect = DialectDelegateWrapper.extractRealDialect( dialect );
555-
return !( dialect instanceof MySQLDialect
555+
return !( dialect instanceof MySQLDialect && !(dialect instanceof MariaDBDialect)
556556
|| dialect instanceof SybaseDialect
557557
|| dialect instanceof DerbyDialect
558558
|| dialect instanceof FirebirdDialect
559-
|| dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) )
560-
|| dialect instanceof InformixDialect
561-
|| dialect instanceof MariaDBDialect;
559+
|| dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) );
562560
}
563561
}
564562

0 commit comments

Comments
 (0)