Skip to content

Commit

Permalink
Fix TestCassandraDistributed tests affected by TestNG bug
Browse files Browse the repository at this point in the history
Extract parameterized test methods in AbstractTestQueries
to address differences between cassandra and other connectors.

See testng-team/testng#543.
  • Loading branch information
ArturGajowy authored and lucesape committed Apr 9, 2017
1 parent ead1aa5 commit f55eaf9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" +
Expand All @@ -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)
Expand All @@ -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" +
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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" +
Expand All @@ -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)
Expand All @@ -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" +
Expand All @@ -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)
Expand Down

0 comments on commit f55eaf9

Please sign in to comment.