Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/main/java/org/duckdb/DuckDBDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,32 @@ public boolean isReadOnly() throws SQLException {
return conn.isReadOnly();
}

private String getDefaultNullOrder() throws SQLException {
try (Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT current_setting('default_null_order')")) {
rs.next();
return rs.getString(1);
}
}

@Override
public boolean nullsAreSortedHigh() throws SQLException {
return true;
return "NULLS_LAST_ON_ASC_FIRST_ON_DESC".equals(getDefaultNullOrder());
}

@Override
public boolean nullsAreSortedLow() throws SQLException {
return false;
return "NULLS_FIRST_ON_ASC_LAST_ON_DESC".equals(getDefaultNullOrder());
}

@Override
public boolean nullsAreSortedAtStart() throws SQLException {
return true;
return "NULLS_FIRST".equals(getDefaultNullOrder());
}

@Override
public boolean nullsAreSortedAtEnd() throws SQLException {
return false;
return "NULLS_LAST".equals(getDefaultNullOrder());
}

@Override
Expand Down
57 changes: 27 additions & 30 deletions src/test/java/org/duckdb/TestClosure.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,44 +683,41 @@ public static void test_open_connection_factories_return_objects() throws Except
}

public static void test_closed_connection_getMetaData_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.getMetaData();
fail("getMetaData() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
Connection conn = DriverManager.getConnection(JDBC_URL);
conn.close();
assertTrue(conn.isClosed());
try {
conn.getMetaData();
fail("getMetaData() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}

public static void test_closed_connection_createArrayOf_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.createArrayOf("INTEGER", new Object[] {1, 2});
fail("createArrayOf() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
Connection conn = DriverManager.getConnection(JDBC_URL);
conn.close();
assertTrue(conn.isClosed());
try {
conn.createArrayOf("INTEGER", new Object[] {1, 2});
fail("createArrayOf() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}

public static void test_closed_connection_createStruct_throws() throws Exception {
try (Connection conn = DriverManager.getConnection(JDBC_URL)) {
conn.close();
assertTrue(conn.isClosed());
try {
conn.createStruct("STRUCT(a INTEGER, b INTEGER)", new Object[] {1, 2});
fail("createStruct() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
Connection conn = DriverManager.getConnection(JDBC_URL);
conn.close();
assertTrue(conn.isClosed());
try {
conn.createStruct("STRUCT(a INTEGER, b INTEGER)", new Object[] {1, 2});
fail("createStruct() on a closed connection should throw SQLException");
} catch (SQLException e) {
assertEquals(e.getMessage(), "Connection was closed");
assertEquals(e.getSQLState(), "08003");
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/test/java/org/duckdb/TestMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -1203,4 +1203,33 @@ public static void test_metadata_variant_class() throws Exception {
assertEquals(rows, 3);
}
}

public static void test_metadata_null_ordering() throws Exception {
String[] options = {"NULLS_LAST", "NULLS_FIRST", "NULLS_FIRST_ON_ASC_LAST_ON_DESC",
"NULLS_LAST_ON_ASC_FIRST_ON_DESC"};
try (Connection conn = DriverManager.getConnection(JDBC_URL); Statement stmt = conn.createStatement()) {
stmt.execute("CREATE TABLE test_null_order (i INTEGER)");
stmt.execute("INSERT INTO test_null_order VALUES (1), (2), (NULL)");

DatabaseMetaData md = conn.getMetaData();
for (String option : options) {
stmt.execute("SET default_null_order = '" + option + "'");

boolean ascNullFirst = isNullFirst(stmt, "ASC");
boolean descNullFirst = isNullFirst(stmt, "DESC");

assertEquals(md.nullsAreSortedHigh(), !ascNullFirst && descNullFirst);
assertEquals(md.nullsAreSortedLow(), ascNullFirst && !descNullFirst);
assertEquals(md.nullsAreSortedAtStart(), ascNullFirst && descNullFirst);
assertEquals(md.nullsAreSortedAtEnd(), !ascNullFirst && !descNullFirst);
}
}
}

private static boolean isNullFirst(Statement stmt, String direction) throws Exception {
try (ResultSet rs = stmt.executeQuery("SELECT i FROM test_null_order ORDER BY i " + direction)) {
assertTrue(rs.next());
return rs.getObject(1) == null;
}
}
}
4 changes: 2 additions & 2 deletions src/test/java/org/duckdb/TestScalarFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2578,8 +2578,8 @@ public static void test_scalar_function_vectorized_parallel_validity_rmw() throw
.register(conn);
for (int repetition = 0; repetition < 3; repetition++) {
try (ResultSet rs =
stmt.executeQuery("SELECT java_validity_rmw(x, x + 1) FROM range(0, (1<<16)) r(x)")) {
for (long i = 0; i < (1 << 16); i++) {
stmt.executeQuery("SELECT java_validity_rmw(x, x + 1) FROM range(0, (1<<12)) r(x)")) {
for (long i = 0; i < (1 << 12); i++) {
assertTrue(rs.next());
if (i % 2 == 0) {
assertNullRow(rs);
Expand Down
Loading