try to make var_xxx() and sdtev_xxx() more portable

This commit is contained in:
Gavin King 2022-10-08 19:03:30 +02:00
parent 477f1e7af6
commit f5a5990d03
6 changed files with 23 additions and 9 deletions

View File

@ -1795,7 +1795,7 @@ public class HQLTest extends BaseEntityManagerFunctionalTestCase {
} }
@Test @Test
@RequiresDialect({MySQLDialect.class, PostgreSQLDialect.class, H2Dialect.class, DerbyDialect.class, OracleDialect.class}) // @RequiresDialect({MySQLDialect.class, PostgreSQLDialect.class, H2Dialect.class, DerbyDialect.class, OracleDialect.class})
public void test_var_function_example() { public void test_var_function_example() {
doInJPA(this::entityManagerFactory, entityManager -> { doInJPA(this::entityManagerFactory, entityManager -> {
//tag::hql-native-function-example[] //tag::hql-native-function-example[]

View File

@ -277,9 +277,10 @@ public class DB2LegacyDialect extends Dialect {
functionFactory.median(); functionFactory.median();
functionFactory.stddev(); functionFactory.stddev();
functionFactory.stddevPopSamp(); functionFactory.stddevPopSamp();
functionFactory.varPopSamp();
functionFactory.regrLinearRegressionAggregates(); functionFactory.regrLinearRegressionAggregates();
functionFactory.variance(); functionFactory.variance();
functionFactory.stdevVarianceSamp(); functionFactory.varianceSamp();
functionFactory.addYearsMonthsDaysHoursMinutesSeconds(); functionFactory.addYearsMonthsDaysHoursMinutesSeconds();
functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween(); functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween();
functionFactory.dateTrunc(); functionFactory.dateTrunc();

View File

@ -259,9 +259,10 @@ public class DB2Dialect extends Dialect {
functionFactory.median(); functionFactory.median();
functionFactory.stddev(); functionFactory.stddev();
functionFactory.stddevPopSamp(); functionFactory.stddevPopSamp();
functionFactory.varPopSamp();
functionFactory.regrLinearRegressionAggregates(); functionFactory.regrLinearRegressionAggregates();
functionFactory.variance(); functionFactory.variance();
functionFactory.stdevVarianceSamp(); functionFactory.varianceSamp();
functionFactory.addYearsMonthsDaysHoursMinutesSeconds(); functionFactory.addYearsMonthsDaysHoursMinutesSeconds();
functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween(); functionFactory.yearsMonthsDaysHoursMinutesSecondsBetween();
functionFactory.dateTrunc(); functionFactory.dateTrunc();

View File

@ -208,6 +208,13 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine);
functionFactory.stddev();
functionFactory.variance();
functionFactory.stddevPopSamp_stdevp();
functionFactory.varPopSamp_varp();
functionFactory.stddevPopSamp();
functionFactory.varPopSamp();
// For SQL-Server we need to cast certain arguments to varchar(16384) to be able to concat them // For SQL-Server we need to cast certain arguments to varchar(16384) to be able to concat them
queryEngine.getSqmFunctionRegistry().register( queryEngine.getSqmFunctionRegistry().register(
"count", "count",

View File

@ -419,12 +419,7 @@ public class CommonFunctionFactory {
/** /**
* DB2 * DB2
*/ */
public void stdevVarianceSamp() { public void varianceSamp() {
functionRegistry.namedAggregateDescriptorBuilder( "stddev_samp" )
.setInvariantType(doubleType)
.setExactArgumentCount( 1 )
.setParameterTypes(NUMERIC)
.register();
functionRegistry.namedAggregateDescriptorBuilder( "variance_samp" ) functionRegistry.namedAggregateDescriptorBuilder( "variance_samp" )
.setInvariantType(doubleType) .setInvariantType(doubleType)
.setExactArgumentCount( 1 ) .setExactArgumentCount( 1 )

View File

@ -926,6 +926,16 @@ public class FunctionTests {
); );
} }
@Test
public void testStatisticalFunctions(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("select var_samp(e.theDouble), var_pop(abs(e.theDouble)), stddev_samp(e.theDouble), stddev_pop(e.theDouble) from EntityOfBasics e")
.list();
}
);
}
@Test @Test
public void testCurrentDateTimeFunctions(SessionFactoryScope scope) { public void testCurrentDateTimeFunctions(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(