diff --git a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcMetaTest.java b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcMetaTest.java index d0188e2c5a..d2e786c8b4 100644 --- a/dbms/src/test/java/org/polypheny/db/jdbc/JdbcMetaTest.java +++ b/dbms/src/test/java/org/polypheny/db/jdbc/JdbcMetaTest.java @@ -17,7 +17,10 @@ package org.polypheny.db.jdbc; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import com.google.common.collect.ImmutableList; import java.sql.Connection; @@ -43,6 +46,14 @@ @Slf4j public class JdbcMetaTest { + private static final String CREATE_TEST_TABLE = "CREATE TABLE IF NOT EXISTS my_table (id INT PRIMARY KEY, some_value INT)"; + private static final String INSERT_TEST_DATA = "INSERT INTO my_table (id, some_value) VALUES " + + "(1, 10), " + + "(2, NULL), " + + "(3, 5), " + + "(4, NULL), " + + "(5, 8)"; + private static TestHelper helper; @@ -342,6 +353,75 @@ public void testGetTableTypes() throws SQLException { } + @Test + public void testSortNullsAtEnd() throws SQLException { + try ( + JdbcConnection polyphenyDbConnection = new JdbcConnection( false ); + Connection connection = polyphenyDbConnection.getConnection(); + Statement statement = connection.createStatement() + ) { + statement.execute( CREATE_TEST_TABLE ); + statement.executeUpdate( INSERT_TEST_DATA ); + + ResultSet rs = statement.executeQuery( "SELECT * FROM my_table ORDER BY some_value IS NULL, some_value" ); + + boolean trigger = false; + while ( rs.next() ) { + Integer value = rs.getInt( "some_value" ); + if ( value == 0 ) { + trigger = true; + } else if ( trigger && value != null ) { + fail( "Values are not sorted correctly." ); + } + } + + ResultSet rs2 = statement.executeQuery( "SELECT * FROM my_table ORDER BY some_value IS NULL, some_value" ); + + trigger = false; + while ( rs2.next() ) { + Integer value = rs2.getInt( "some_value" ); + if ( value == 0 ) { + trigger = true; + } else if ( trigger && value != null ) { + fail( "Values are not sorted correctly." ); + } + } + } + } + + @Test + public void testNullsAreSortedAtEnd() throws SQLException { + try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( false, true ); + Connection connection = polyphenyDbConnection.getConnection() ) { + assertTrue(connection.getMetaData().nullsAreSortedAtEnd()); + } + } + + @Test + public void testNullsAreSortedStart() throws SQLException { + try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( false, true ); + Connection connection = polyphenyDbConnection.getConnection() ) { + assertFalse(connection.getMetaData().nullsAreSortedAtStart()); + } + } + + @Test + public void testNullsAreSortedHigh() throws SQLException { + try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( false, true ); + Connection connection = polyphenyDbConnection.getConnection() ) { + assertFalse(connection.getMetaData().nullsAreSortedHigh()); + } + } + + @Test + public void testNullsAreSortedLow() throws SQLException { + try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( false, true ); + Connection connection = polyphenyDbConnection.getConnection() ) { + assertFalse(connection.getMetaData().nullsAreSortedLow()); + } + } + + @Test public void testMetaGetColumns() throws SQLException { try ( JdbcConnection polyphenyDbConnection = new JdbcConnection( false ) ) { diff --git a/dbms/src/test/java/org/polypheny/db/protointerface/MqlTest.java b/dbms/src/test/java/org/polypheny/db/protointerface/MqlTest.java index cd08db547e..4ac782d775 100644 --- a/dbms/src/test/java/org/polypheny/db/protointerface/MqlTest.java +++ b/dbms/src/test/java/org/polypheny/db/protointerface/MqlTest.java @@ -58,7 +58,7 @@ public void simpleMqlTest() throws SQLException { if ( !connection.isWrapperFor( PolyConnection.class ) ) { fail( "Driver must support unwrapping to PolyphenyConnection" ); } - PolyStatement polyStatement = connection.unwrap( PolyConnection.class ).createProtoStatement(); + PolyStatement polyStatement = connection.unwrap( PolyConnection.class ).createPolyStatement(); assertThrows( PrismInterfaceServiceException.class, () -> { // fails due to autogenerated query (would create students collection) Result result = polyStatement.execute( "mqltest", MQL_LANGUAGE_NAME, TEST_QUERY );