From 014befb26884d6690fa414e5a672d634fc87be90 Mon Sep 17 00:00:00 2001 From: Artur Gajowy Date: Mon, 23 Jan 2017 08:59:26 +0100 Subject: [PATCH] Fix TestCassandraDistributed tests affected by TestNG bug Extract parameterized test methods in AbstractTestQueries to address differences between cassandra and other connectors. See https://github.com/cbeust/testng/issues/543. --- .../cassandra/TestCassandraDistributed.java | 32 ++++++++++++++++ .../presto/tests/AbstractTestQueries.java | 38 ++++++++++++++++--- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraDistributed.java b/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraDistributed.java index 5aba7a7dbb8..4bf0283cc01 100644 --- a/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraDistributed.java +++ b/presto-cassandra/src/test/java/com/facebook/presto/cassandra/TestCassandraDistributed.java @@ -17,6 +17,8 @@ import com.facebook.presto.tests.AbstractTestDistributedQueries; import org.testng.annotations.Test; +import static com.facebook.presto.spi.type.BigintType.BIGINT; +import static com.facebook.presto.spi.type.DoubleType.DOUBLE; import static com.facebook.presto.spi.type.VarcharType.VARCHAR; import static com.facebook.presto.testing.MaterializedResult.resultBuilder; import static org.testng.Assert.assertEquals; @@ -124,4 +126,34 @@ public void testDescribeOutputNamedAndUnnamed() { // this connector uses a non-canonical type for varchar columns in tpch } + + @Override + public void testWindowFunctionsFromAggregate() + { + testWindowFunctionsFromAggregate(VARCHAR, VARCHAR, DOUBLE, BIGINT); + } + + @Override + public void testFullyPartitionedAndPartiallySortedWindowFunction() + { + testFullyPartitionedAndPartiallySortedWindowFunction(BIGINT, BIGINT, VARCHAR, BIGINT); + } + + @Override + public void testValueWindowFunctions() + { + testValueWindowFunctions(BIGINT, VARCHAR, BIGINT, BIGINT); + } + + @Override + public void testWindowFrames() + { + testWindowFrames(BIGINT, VARCHAR, BIGINT); + } + + @Override + public void testWindowFunctionsExpressions() + { + testWindowFunctionsExpressions(BIGINT, VARCHAR, BIGINT); + } } diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java index 4a748504b60..8e973d998b0 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java @@ -19,6 +19,7 @@ import com.facebook.presto.spi.session.PropertyMetadata; import com.facebook.presto.spi.type.Decimals; import com.facebook.presto.spi.type.TimeZoneKey; +import com.facebook.presto.spi.type.Type; import com.facebook.presto.sql.analyzer.SemanticException; import com.facebook.presto.testing.Arguments; import com.facebook.presto.testing.MaterializedResult; @@ -3976,9 +3977,14 @@ public void testWindowFunctionWithImplicitCoercion() assertQuery("SELECT *, 1.0 * sum(x) OVER () FROM (VALUES 1) t(x)", "SELECT 1, 1.0"); } - @SuppressWarnings("PointlessArithmeticExpression") @Test public void testWindowFunctionsExpressions() + { + testWindowFunctionsExpressions(BIGINT, createVarcharType(1), BIGINT); + } + + @SuppressWarnings("PointlessArithmeticExpression") + protected void testWindowFunctionsExpressions(Type... expectedTypes) { MaterializedResult actual = computeActual("" + "SELECT orderkey, orderstatus\n" + @@ -3987,7 +3993,7 @@ public void testWindowFunctionsExpressions() "FROM (SELECT * FROM orders ORDER BY orderkey LIMIT 10) x\n" + "ORDER BY orderkey LIMIT 5"); - MaterializedResult expected = resultBuilder(getSession(), BIGINT, createVarcharType(1), BIGINT) + MaterializedResult expected = resultBuilder(getSession(), expectedTypes) .row(1L, "O", (1L * 10) + 100) .row(2L, "O", (2L * 9) + 100) .row(3L, "F", (3L * 8) + 100) @@ -4000,6 +4006,11 @@ public void testWindowFunctionsExpressions() @Test public void testWindowFunctionsFromAggregate() + { + testWindowFunctionsFromAggregate(createVarcharType(1), createVarcharType(15), DOUBLE, BIGINT); + } + + protected void testWindowFunctionsFromAggregate(Type... expectedTypes) { MaterializedResult actual = computeActual("" + "SELECT * FROM (\n" + @@ -4014,7 +4025,7 @@ public void testWindowFunctionsFromAggregate() "WHERE rnk <= 2\n" + "ORDER BY orderstatus, rnk"); - MaterializedResult expected = resultBuilder(getSession(), createVarcharType(1), createVarcharType(15), DOUBLE, BIGINT) + MaterializedResult expected = resultBuilder(getSession(), expectedTypes) .row("F", "Clerk#000000090", 2784836.61, 1L) .row("F", "Clerk#000000084", 2674447.15, 2L) .row("O", "Clerk#000000500", 2569878.29, 1L) @@ -4572,13 +4583,18 @@ public void testFullPreSortedWindowFunction() @Test public void testFullyPartitionedAndPartiallySortedWindowFunction() + { + testFullyPartitionedAndPartiallySortedWindowFunction(BIGINT, BIGINT, createVarcharType(15), BIGINT); + } + + protected void testFullyPartitionedAndPartiallySortedWindowFunction(Type... expectedTypes) { MaterializedResult actual = computeActual("" + "SELECT orderkey, custkey, orderPriority, COUNT(*) OVER (PARTITION BY orderkey ORDER BY custkey, orderPriority)\n" + "FROM (SELECT * FROM orders ORDER BY orderkey, custkey LIMIT 10)\n" + "ORDER BY orderkey LIMIT 5"); - MaterializedResult expected = resultBuilder(getSession(), BIGINT, BIGINT, createVarcharType(15), BIGINT) + MaterializedResult expected = resultBuilder(getSession(), expectedTypes) .row(1L, 370L, "5-LOW", 1L) .row(2L, 781L, "1-URGENT", 1L) .row(3L, 1234L, "5-LOW", 1L) @@ -4660,6 +4676,11 @@ public void testOrderByWindowFunctionWithNulls() @Test public void testValueWindowFunctions() + { + testValueWindowFunctions(BIGINT, createVarcharType(1), BIGINT, BIGINT); + } + + protected void testValueWindowFunctions(Type... expectedTypes) { MaterializedResult actual = computeActual("SELECT * FROM (\n" + " SELECT orderkey, orderstatus\n" + @@ -4670,7 +4691,7 @@ public void testValueWindowFunctions() " ) x\n" + "ORDER BY orderkey LIMIT 5"); - MaterializedResult expected = resultBuilder(getSession(), BIGINT, createVarcharType(1), BIGINT, BIGINT) + MaterializedResult expected = resultBuilder(getSession(), expectedTypes) .row(1L, "O", 1001L, 1002L) .row(2L, "O", 1001L, 1002L) .row(3L, "F", 1003L, 1005L) @@ -4683,6 +4704,11 @@ public void testValueWindowFunctions() @Test public void testWindowFrames() + { + testWindowFrames(BIGINT, createVarcharType(1), BIGINT); + } + + protected void testWindowFrames(Type... expectedTypes) { MaterializedResult actual = computeActual("SELECT * FROM (\n" + " SELECT orderkey, orderstatus\n" + @@ -4692,7 +4718,7 @@ public void testWindowFrames() " ) x\n" + "ORDER BY orderkey LIMIT 5"); - MaterializedResult expected = resultBuilder(getSession(), BIGINT, createVarcharType(1), BIGINT) + MaterializedResult expected = resultBuilder(getSession(), expectedTypes) .row(1L, "O", 1001L) .row(2L, "O", 3007L) .row(3L, "F", 3014L)