[#2339] Support CUBRID 9.1's new features - Document support for
NTILE(), LEAD(), LAG() window functions
This commit is contained in:
parent
46a4c431f7
commit
ed860507cf
@ -635,7 +635,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
}
|
||||
|
||||
// NTILE()
|
||||
if (asList(CUBRID, DB2, SYBASE).contains(dialect())) {
|
||||
if (asList(DB2, SYBASE).contains(dialect())) {
|
||||
log.info("SKIPPING", "NTILE tests");
|
||||
}
|
||||
else {
|
||||
@ -659,65 +659,68 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
column = 0;
|
||||
if (asList(CUBRID, SQLSERVER).contains(dialect())) {
|
||||
log.info("SKIPPING", "ROWS UNBOUNDED PRECEDING and similar tests");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
// SUM()
|
||||
result =
|
||||
create().select(TBook_ID(),
|
||||
sum(TBook_ID()).over().partitionByOne(),
|
||||
sum(TBook_ID()).over().partitionBy(TBook_AUTHOR_ID()),
|
||||
sum(TBook_ID()).over().orderBy(TBook_ID().asc())
|
||||
.rowsBetweenUnboundedPreceding()
|
||||
.andPreceding(1))
|
||||
.from(TBook())
|
||||
.orderBy(TBook_ID().asc())
|
||||
.fetch();
|
||||
|
||||
// Overall SUM()
|
||||
column++;
|
||||
assertEquals(new BigDecimal("10"), result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(3, column));
|
||||
|
||||
// Partitioned SUM()
|
||||
column++;
|
||||
assertEquals(new BigDecimal("3"), result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("3"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("7"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("7"), result.getValue(3, column));
|
||||
|
||||
// Ordered SUM() with ROWS
|
||||
column++;
|
||||
assertEquals(null, result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("1"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("3"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("6"), result.getValue(3, column));
|
||||
|
||||
column = 0;
|
||||
|
||||
// FIRST_VALUE()
|
||||
result =
|
||||
create().select(TBook_ID(),
|
||||
firstValue(TBook_ID()).over()
|
||||
.partitionBy(TBook_AUTHOR_ID())
|
||||
.orderBy(TBook_PUBLISHED_IN().asc())
|
||||
.rowsBetweenUnboundedPreceding()
|
||||
.andUnboundedFollowing())
|
||||
.from(TBook())
|
||||
.orderBy(TBook_ID().asc())
|
||||
.fetch();
|
||||
|
||||
// Partitioned and ordered FIRST_VALUE() with ROWS
|
||||
column++;
|
||||
assertEquals(Integer.valueOf(2), result.getValue(0, column));
|
||||
assertEquals(Integer.valueOf(2), result.getValue(1, column));
|
||||
assertEquals(Integer.valueOf(3), result.getValue(2, column));
|
||||
assertEquals(Integer.valueOf(3), result.getValue(3, column));
|
||||
}
|
||||
|
||||
// SUM()
|
||||
result =
|
||||
create().select(TBook_ID(),
|
||||
sum(TBook_ID()).over().partitionByOne(),
|
||||
sum(TBook_ID()).over().partitionBy(TBook_AUTHOR_ID()),
|
||||
sum(TBook_ID()).over().orderBy(TBook_ID().asc())
|
||||
.rowsBetweenUnboundedPreceding()
|
||||
.andPreceding(1))
|
||||
.from(TBook())
|
||||
.orderBy(TBook_ID().asc())
|
||||
.fetch();
|
||||
|
||||
// Overall SUM()
|
||||
column++;
|
||||
assertEquals(new BigDecimal("10"), result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("10"), result.getValue(3, column));
|
||||
|
||||
// Partitioned SUM()
|
||||
column++;
|
||||
assertEquals(new BigDecimal("3"), result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("3"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("7"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("7"), result.getValue(3, column));
|
||||
|
||||
// Ordered SUM() with ROWS
|
||||
column++;
|
||||
assertEquals(null, result.getValue(0, column));
|
||||
assertEquals(new BigDecimal("1"), result.getValue(1, column));
|
||||
assertEquals(new BigDecimal("3"), result.getValue(2, column));
|
||||
assertEquals(new BigDecimal("6"), result.getValue(3, column));
|
||||
|
||||
column = 0;
|
||||
|
||||
// FIRST_VALUE()
|
||||
result =
|
||||
create().select(TBook_ID(),
|
||||
firstValue(TBook_ID()).over()
|
||||
.partitionBy(TBook_AUTHOR_ID())
|
||||
.orderBy(TBook_PUBLISHED_IN().asc())
|
||||
.rowsBetweenUnboundedPreceding()
|
||||
.andUnboundedFollowing())
|
||||
.from(TBook())
|
||||
.orderBy(TBook_ID().asc())
|
||||
.fetch();
|
||||
|
||||
// Partitioned and ordered FIRST_VALUE() with ROWS
|
||||
column++;
|
||||
assertEquals(Integer.valueOf(2), result.getValue(0, column));
|
||||
assertEquals(Integer.valueOf(2), result.getValue(1, column));
|
||||
assertEquals(Integer.valueOf(3), result.getValue(2, column));
|
||||
assertEquals(Integer.valueOf(3), result.getValue(3, column));
|
||||
|
||||
switch (dialect()) {
|
||||
case CUBRID:
|
||||
case POSTGRES:
|
||||
case SQLSERVER:
|
||||
log.info("SKIPPING", "FIRST_VALUE(... IGNORE NULLS) window function test");
|
||||
break;
|
||||
|
||||
|
||||
@ -60,8 +60,8 @@ public interface AggregateFunction<T> extends Field<T>, WindowOverStep<T> {
|
||||
* MAX(ID) OVER (PARTITION BY 1)
|
||||
* </code></pre>
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Override
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
|
||||
@ -6498,8 +6498,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>row_number() over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
* <p>
|
||||
* Newer versions of {@link SQLDialect#DERBY} and {@link SQLDialect#H2} also
|
||||
* support the <code>ROW_NUMBER() OVER()</code> window function without any
|
||||
@ -6515,8 +6515,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>rank_over() over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
public static WindowOverStep<Integer> rank() {
|
||||
@ -6526,8 +6526,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>dense_rank() over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
public static WindowOverStep<Integer> denseRank() {
|
||||
@ -6537,8 +6537,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>precent_rank() over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ POSTGRES, ORACLE, SYBASE })
|
||||
public static WindowOverStep<BigDecimal> percentRank() {
|
||||
@ -6548,8 +6548,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>cume_dist() over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ POSTGRES, ORACLE, SYBASE })
|
||||
public static WindowOverStep<BigDecimal> cumeDist() {
|
||||
@ -6559,19 +6559,19 @@ public class DSL {
|
||||
/**
|
||||
* The <code>ntile([number]) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ POSTGRES, ORACLE, SQLSERVER })
|
||||
@Support({ CUBRID, POSTGRES, ORACLE, SQLSERVER })
|
||||
public static WindowOverStep<Integer> ntile(int number) {
|
||||
return new Function<Integer>("ntile", SQLDataType.INTEGER, field("" + number, Integer.class));
|
||||
return new Function<Integer>("ntile", SQLDataType.INTEGER, inline(number));
|
||||
}
|
||||
|
||||
/**
|
||||
* The <code>first_value(field) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE, SYBASE })
|
||||
public static <T> WindowIgnoreNullsStep<T> firstValue(Field<T> field) {
|
||||
@ -6581,8 +6581,8 @@ public class DSL {
|
||||
/**
|
||||
* The <code>last_value(field) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE, SYBASE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lastValue(Field<T> field) {
|
||||
@ -6592,10 +6592,10 @@ public class DSL {
|
||||
/**
|
||||
* The <code>lead(field) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lead(Field<T> field) {
|
||||
return new Function<T>("lead", nullSafeDataType(field), nullSafe(field));
|
||||
}
|
||||
@ -6603,10 +6603,10 @@ public class DSL {
|
||||
/**
|
||||
* The <code>lead(field, offset) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lead(Field<T> field, int offset) {
|
||||
return new Function<T>("lead", nullSafeDataType(field), nullSafe(field), inline(offset));
|
||||
}
|
||||
@ -6616,10 +6616,10 @@ public class DSL {
|
||||
* <code>lead(field, offset, defaultValue) over ([analytic clause])</code>
|
||||
* function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lead(Field<T> field, int offset, T defaultValue) {
|
||||
return lead(nullSafe(field), offset, Utils.field(defaultValue));
|
||||
}
|
||||
@ -6629,10 +6629,10 @@ public class DSL {
|
||||
* <code>lead(field, offset, defaultValue) over ([analytic clause])</code>
|
||||
* function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lead(Field<T> field, int offset, Field<T> defaultValue) {
|
||||
return new Function<T>("lead", nullSafeDataType(field), nullSafe(field), inline(offset), nullSafe(defaultValue));
|
||||
}
|
||||
@ -6640,10 +6640,10 @@ public class DSL {
|
||||
/**
|
||||
* The <code>lag(field) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lag(Field<T> field) {
|
||||
return new Function<T>("lag", nullSafeDataType(field), nullSafe(field));
|
||||
}
|
||||
@ -6651,10 +6651,10 @@ public class DSL {
|
||||
/**
|
||||
* The <code>lag(field, offset) over ([analytic clause])</code> function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lag(Field<T> field, int offset) {
|
||||
return new Function<T>("lag", nullSafeDataType(field), nullSafe(field), inline(offset));
|
||||
}
|
||||
@ -6664,10 +6664,10 @@ public class DSL {
|
||||
* <code>lag(field, offset, defaultValue) over ([analytic clause])</code>
|
||||
* function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lag(Field<T> field, int offset, T defaultValue) {
|
||||
return lag(nullSafe(field), offset, Utils.field(defaultValue));
|
||||
}
|
||||
@ -6677,10 +6677,10 @@ public class DSL {
|
||||
* <code>lag(field, offset, defaultValue) over ([analytic clause])</code>
|
||||
* function.
|
||||
* <p>
|
||||
* Window functions are supported in DB2, Postgres, Oracle, SQL Server and
|
||||
* Sybase.
|
||||
* Window functions are supported in CUBRID, DB2, Postgres, Oracle, SQL
|
||||
* Server and Sybase.
|
||||
*/
|
||||
@Support({ DB2, POSTGRES, ORACLE })
|
||||
@Support({ CUBRID, DB2, POSTGRES, ORACLE })
|
||||
public static <T> WindowIgnoreNullsStep<T> lag(Field<T> field, int offset, Field<T> defaultValue) {
|
||||
return new Function<T>("lag", nullSafeDataType(field), nullSafe(field), inline(offset), nullSafe(defaultValue));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user