median function documentation, improve test
This commit is contained in:
parent
fa772e5cc8
commit
02cf728bcb
|
@ -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` | ✔/✔
|
| `count()`, including `count(distinct)`, `count(all)`, and `count(*)` | Any | `Long` | ✔/✔
|
||||||
| `avg()` | Any numeric type | `Double` | ✔/✔
|
| `avg()` | Any numeric type | `Double` | ✔/✔
|
||||||
|
| `median()` | Any numeric type | `Double` | ✖/✖
|
||||||
| `min()` | Any numeric type, or string | Same as the argument type | ✔/✔
|
| `min()` | Any numeric type, or string | Same as the argument type | ✔/✔
|
||||||
| `max()` | 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 | ✔/✔
|
| `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` | ✖/✔
|
| `stddev_pop()`, `stddev_samp()` | Any numeric type | `Double` | ✖/✔
|
||||||
|===
|
|===
|
||||||
|
|
||||||
|
[NOTE]
|
||||||
|
The `median()` function is not supported on MySQL or Sybase ASE.
|
||||||
|
|
||||||
[[aggregate-functions-example]]
|
[[aggregate-functions-example]]
|
||||||
[source, hql]
|
[source, hql]
|
||||||
[%unbreakable]
|
[%unbreakable]
|
||||||
|
|
|
@ -62,6 +62,9 @@ import static org.hibernate.type.SqlTypes.NCLOB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@linkplain Dialect SQL dialect} for HSQLDB (HyperSQL) 2.6.1 and above.
|
* A {@linkplain Dialect SQL dialect} for HSQLDB (HyperSQL) 2.6.1 and above.
|
||||||
|
* <p>
|
||||||
|
* Please refer to the
|
||||||
|
* <a href="https://hsqldb.org/doc/2.0/guide/index.html">HyperSQL User Guide</a>.
|
||||||
*
|
*
|
||||||
* @author Christoph Sturm
|
* @author Christoph Sturm
|
||||||
* @author Phillip Baird
|
* @author Phillip Baird
|
||||||
|
|
|
@ -2316,6 +2316,12 @@ public class FunctionTests {
|
||||||
public void testMedian(SessionFactoryScope scope) {
|
public void testMedian(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
session -> {
|
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<Object[]> list = session.createQuery("select median(e.theDouble), median(e.theInt) from EntityOfBasics e", Object[].class)
|
List<Object[]> list = session.createQuery("select median(e.theDouble), median(e.theInt) from EntityOfBasics e", Object[].class)
|
||||||
.list();
|
.list();
|
||||||
assertEquals( 1, list.size() );
|
assertEquals( 1, list.size() );
|
||||||
|
|
|
@ -552,13 +552,11 @@ abstract public class DialectFeatureChecks {
|
||||||
public static class SupportsMedian implements DialectFeatureCheck {
|
public static class SupportsMedian implements DialectFeatureCheck {
|
||||||
public boolean apply(Dialect dialect) {
|
public boolean apply(Dialect dialect) {
|
||||||
dialect = DialectDelegateWrapper.extractRealDialect( dialect );
|
dialect = DialectDelegateWrapper.extractRealDialect( dialect );
|
||||||
return !( dialect instanceof MySQLDialect
|
return !( dialect instanceof MySQLDialect && !(dialect instanceof MariaDBDialect)
|
||||||
|| dialect instanceof SybaseDialect
|
|| dialect instanceof SybaseDialect
|
||||||
|| dialect instanceof DerbyDialect
|
|| dialect instanceof DerbyDialect
|
||||||
|| dialect instanceof FirebirdDialect
|
|| dialect instanceof FirebirdDialect
|
||||||
|| dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) )
|
|| dialect instanceof DB2Dialect && ( (DB2Dialect) dialect ).getDB2Version().isBefore( 11 ) );
|
||||||
|| dialect instanceof InformixDialect
|
|
||||||
|| dialect instanceof MariaDBDialect;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue