[#1524] Simulate ROW_NUMBER() OVER() in HSQLDB using ROWNUM()
This commit is contained in:
parent
577ddd4a60
commit
006ec665aa
@ -256,7 +256,6 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
switch (getDialect()) {
|
||||
case ASE:
|
||||
case CUBRID:
|
||||
case HSQLDB:
|
||||
case INGRES:
|
||||
case MYSQL:
|
||||
case SQLITE:
|
||||
@ -264,8 +263,8 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
return;
|
||||
}
|
||||
|
||||
// [#1523] Derby now supports the ROW_NUMBER() OVER() window function
|
||||
// without any window clause, though
|
||||
// [#1523] Derby, H2 now support the ROW_NUMBER() OVER() window function
|
||||
// without any window clause, though. HSQLDB can simulate it using ROWNUM()
|
||||
List<Integer> rows =
|
||||
create().select(rowNumber().over()).from(TBook()).fetch(0, Integer.class);
|
||||
assertEquals(asList(1, 2, 3, 4), rows);
|
||||
@ -273,6 +272,7 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658,
|
||||
switch (getDialect()) {
|
||||
case DERBY:
|
||||
case H2:
|
||||
case HSQLDB:
|
||||
log.info("SKIPPING", "Advanced window function tests");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ package org.jooq;
|
||||
import static org.jooq.SQLDialect.DB2;
|
||||
import static org.jooq.SQLDialect.DERBY;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
import static org.jooq.SQLDialect.ORACLE;
|
||||
import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
@ -67,7 +68,7 @@ public interface WindowOverStep<T> {
|
||||
/**
|
||||
* Add an <code>OVER</code> clause
|
||||
*/
|
||||
@Support({ DB2, DERBY, H2, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
WindowPartitionByStep<T> over();
|
||||
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ import static org.jooq.SQLDialect.SQLITE;
|
||||
import static org.jooq.SQLDialect.SQLSERVER;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
import static org.jooq.conf.SettingsTools.getRenderMapping;
|
||||
import static org.jooq.impl.Term.ROW_NUMBER;
|
||||
import static org.jooq.impl.Util.combine;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -5101,11 +5102,13 @@ public class Factory implements FactoryOperations {
|
||||
* <p>
|
||||
* Newer versions of {@link SQLDialect#DERBY} and {@link SQLDialect#H2} also
|
||||
* support the <code>ROW_NUMBER() OVER()</code> window function without any
|
||||
* window clause. See the respective docs for details
|
||||
* window clause. See the respective docs for details.
|
||||
* {@link SQLDialect#HSQLDB} can simulate this function using
|
||||
* <code>ROWNUM()</code>
|
||||
*/
|
||||
@Support({ DB2, DERBY, H2, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
@Support({ DB2, DERBY, H2, HSQLDB, POSTGRES, ORACLE, SQLSERVER, SYBASE })
|
||||
public static WindowOverStep<Integer> rowNumber() {
|
||||
return new Function<Integer>("row_number", SQLDataType.INTEGER);
|
||||
return new Function<Integer>(ROW_NUMBER, SQLDataType.INTEGER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -46,6 +46,7 @@ import static org.jooq.SQLDialect.POSTGRES;
|
||||
import static org.jooq.SQLDialect.SYBASE;
|
||||
import static org.jooq.impl.Factory.one;
|
||||
import static org.jooq.impl.Term.LIST_AGG;
|
||||
import static org.jooq.impl.Term.ROW_NUMBER;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@ -299,7 +300,16 @@ class Function<T> extends AbstractField<T> implements
|
||||
}
|
||||
|
||||
private final void toSQLOverClause(RenderContext context) {
|
||||
if (!over) return;
|
||||
|
||||
// Render this clause only if needed
|
||||
if (!over) {
|
||||
return;
|
||||
}
|
||||
|
||||
// [#1524] Don't render this clause where it is not supported
|
||||
if (over && term == ROW_NUMBER && context.getDialect() == HSQLDB) {
|
||||
return;
|
||||
}
|
||||
|
||||
String glue = "";
|
||||
context.keyword(" over (");
|
||||
|
||||
@ -149,6 +149,17 @@ enum Term {
|
||||
return "octet_length";
|
||||
}
|
||||
},
|
||||
ROW_NUMBER {
|
||||
@Override
|
||||
public String translate(SQLDialect dialect) {
|
||||
switch (dialect) {
|
||||
case HSQLDB:
|
||||
return "rownum";
|
||||
}
|
||||
|
||||
return "row_number";
|
||||
}
|
||||
},
|
||||
STDDEV_POP {
|
||||
@Override
|
||||
public String translate(SQLDialect dialect) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user