From 02cf728bcb83bab4226f67a9830037eb3acb85ee Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 6 Dec 2024 21:52:38 +0100 Subject: [PATCH] median function documentation, improve test --- .../src/main/asciidoc/querylanguage/Relational.adoc | 4 ++++ .../src/main/java/org/hibernate/dialect/HSQLDialect.java | 3 +++ .../org/hibernate/orm/test/query/hql/FunctionTests.java | 6 ++++++ .../hibernate/testing/orm/junit/DialectFeatureChecks.java | 6 ++---- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/documentation/src/main/asciidoc/querylanguage/Relational.adoc b/documentation/src/main/asciidoc/querylanguage/Relational.adoc index 7216bd4169..5f46341f7a 100644 --- a/documentation/src/main/asciidoc/querylanguage/Relational.adoc +++ b/documentation/src/main/asciidoc/querylanguage/Relational.adoc @@ -178,6 +178,7 @@ The standard aggregate functions defined in both ANSI SQL and JPQL are these one | `count()`, including `count(distinct)`, `count(all)`, and `count(*)` | Any | `Long` | ✔/✔ | `avg()` | Any numeric type | `Double` | ✔/✔ +| `median()` | Any numeric type | `Double` | ✖/✖ | `min()` | Any numeric type, or string | Same as the argument type | ✔/✔ | `max()` | Any numeric type, or string | Same as the argument type | ✔/✔ | `sum()` | Any numeric type | See table below | ✔/✔ @@ -185,6 +186,9 @@ The standard aggregate functions defined in both ANSI SQL and JPQL are these one | `stddev_pop()`, `stddev_samp()` | Any numeric type | `Double` | ✖/✔ |=== +[NOTE] +The `median()` function is not supported on MySQL or Sybase ASE. + [[aggregate-functions-example]] [source, hql] [%unbreakable] diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java index 819320c146..9f78bc212e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HSQLDialect.java @@ -62,6 +62,9 @@ import static org.hibernate.type.SqlTypes.NCLOB; /** * A {@linkplain Dialect SQL dialect} for HSQLDB (HyperSQL) 2.6.1 and above. + *

+ * Please refer to the + * HyperSQL User Guide. * * @author Christoph Sturm * @author Phillip Baird 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 f1f3f6c622..38bbebe181 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 @@ -2316,6 +2316,12 @@ public class FunctionTests { public void testMedian(SessionFactoryScope scope) { scope.inTransaction( session -> { + assertEquals( 1.0, + session.createQuery("select median(e.theDouble) from EntityOfBasics e", Double.class).getSingleResult(), + 1e-5); + assertEquals( 5.0, + session.createQuery("select median(e.theInt) from EntityOfBasics e", Double.class).getSingleResult(), + 1e-5); List list = session.createQuery("select median(e.theDouble), median(e.theInt) from EntityOfBasics e", Object[].class) .list(); assertEquals( 1, list.size() ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java index 1522a522b6..6f0e313854 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFeatureChecks.java @@ -552,13 +552,11 @@ abstract public class DialectFeatureChecks { public static class SupportsMedian implements DialectFeatureCheck { public boolean apply(Dialect dialect) { dialect = DialectDelegateWrapper.extractRealDialect( dialect ); - return !( dialect instanceof MySQLDialect + return !( dialect instanceof MySQLDialect && !(dialect instanceof MariaDBDialect) || dialect instanceof SybaseDialect || dialect instanceof DerbyDialect || dialect instanceof FirebirdDialect - || dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) ) - || dialect instanceof InformixDialect - || dialect instanceof MariaDBDialect; + || dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) ); } }