From 38e6415804f7a956de04fe1b61660cbff6dcecf8 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 24 Nov 2019 12:29:21 +0100 Subject: Test ORDER BY functionality (#30) --- .../cloudatlas/interpreter/InterpreterTests.java | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'src/test') diff --git a/src/test/java/pl/edu/mimuw/cloudatlas/interpreter/InterpreterTests.java b/src/test/java/pl/edu/mimuw/cloudatlas/interpreter/InterpreterTests.java index 1c7be00..fdc6fd2 100644 --- a/src/test/java/pl/edu/mimuw/cloudatlas/interpreter/InterpreterTests.java +++ b/src/test/java/pl/edu/mimuw/cloudatlas/interpreter/InterpreterTests.java @@ -607,6 +607,62 @@ public class InterpreterTests { ); } + @Test + public void testNullFromEmptyColumn() throws Exception { + assertInterpreterRun( + "SELECT max(num_cores) AS num_cores WHERE cpu_usage = 0.1", + new String[] { + "/uw: num_cores: NULL", + "/pjwstk: num_cores: 7", + "/: num_cores: NULL" + } + ); + } + + @Test + public void testOrderDescending() throws Exception { + assertInterpreterRun( + "SELECT first(1, unfold(php_modules)) AS php_modules ORDER BY cpu_usage DESC NULLS LAST", + new String[] { + "/pjwstk: php_modules: [odbc]", + "/: php_modules: [odbc]", + } + ); + } + + @Test + public void testOrderAscending() throws Exception { + assertInterpreterRun( + "SELECT first(1, unfold(php_modules)) AS php_modules ORDER BY cpu_usage ASC NULLS LAST", + new String[] { + "/pjwstk: php_modules: [rewrite]", + "/: php_modules: [rewrite]" + } + ); + } + + @Test + public void testOrderNullsFirst() throws Exception { + assertInterpreterRun( + "SELECT first(1, unfold(some_names)) AS some_names ORDER BY has_ups NULLS FIRST", + new String[] { + "/uw: some_names: [tola]", + "/: some_names: [tola]" + } + ); + } + + @Test + public void testOrderNullsLast() throws Exception { + assertInterpreterRun( + "SELECT last(1, unfold(some_names)) AS some_names ORDER BY has_ups NULLS LAST", + new String[] { + "/uw: some_names: [tosia]", + "/: some_names: [tosia]" + } + ); + } + private void assertInterpreterRun(String query, String[] expectedOutput) throws Exception { ByteArrayInputStream in = new ByteArrayInputStream(query.getBytes()); -- cgit v1.2.3