Skip to content

Commit

Permalink
Remove usage of @test with exceptions in planner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Damans227 authored and phd3 committed Oct 10, 2021
1 parent c8cfaa8 commit 73ad472
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,24 @@ public void testValues()
values(ImmutableMap.of("VALUE", 0))));
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = ".* doesn't have column .*")
@Test
public void testAliasNonexistentColumn()
{
assertMinimallyOptimizedPlan("SELECT orderkey FROM lineitem",
assertThatThrownBy(() -> assertMinimallyOptimizedPlan("SELECT orderkey FROM lineitem",
node(OutputNode.class,
node(TableScanNode.class).withAlias("ORDERKEY", columnReference("lineitem", "NXCOLUMN"))));
node(TableScanNode.class).withAlias("ORDERKEY", columnReference("lineitem", "NXCOLUMN")))))
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching(".* doesn't have column .*");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "missing expression for alias .*")
@Test
public void testReferenceNonexistentAlias()
{
assertMinimallyOptimizedPlan("SELECT orderkey FROM lineitem",
assertThatThrownBy(() -> assertMinimallyOptimizedPlan("SELECT orderkey FROM lineitem",
output(ImmutableList.of("NXALIAS"),
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))));
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))))
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching("missing expression for alias .*");
}

@Test
Expand Down Expand Up @@ -233,27 +237,31 @@ public void testStrictProjectExtraSymbols()
.hasMessageStartingWith("Plan does not match");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = ".*already bound to expression.*")
@Test
public void testDuplicateAliases()
{
assertPlan(
assertThatThrownBy(() -> assertPlan(
"SELECT o.orderkey FROM orders o, lineitem l WHERE l.orderkey = o.orderkey",
noJoinReordering(),
anyTree(
join(INNER, ImmutableList.of(equiJoinClause("LINEITEM_OK", "ORDERS_OK")),
anyTree(
tableScan("orders").withAlias("ORDERS_OK", columnReference("orders", "orderkey"))),
anyTree(
tableScan("lineitem").withAlias("ORDERS_OK", columnReference("lineitem", "orderkey"))))));
tableScan("lineitem").withAlias("ORDERS_OK", columnReference("lineitem", "orderkey")))))))
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching(".*already bound to expression.*");
}

@Test(expectedExceptions = IllegalStateException.class, expectedExceptionsMessageRegExp = "missing expression for alias .*")
@Test
public void testProjectLimitsScope()
{
assertMinimallyOptimizedPlan("SELECT 1 + orderkey FROM lineitem",
assertThatThrownBy(() -> assertMinimallyOptimizedPlan("SELECT 1 + orderkey FROM lineitem",
output(ImmutableList.of("ORDERKEY"),
project(ImmutableMap.of("EXPRESSION", expression("CAST(1 AS bigint) + ORDERKEY")),
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey")))));
tableScan("lineitem", ImmutableMap.of("ORDERKEY", "orderkey"))))))
.isInstanceOf(IllegalStateException.class)
.hasMessageMatching("missing expression for alias .*");
}

private Session noJoinReordering()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import static io.trino.sql.planner.plan.AggregationNode.Step.SINGLE;
import static io.trino.sql.planner.plan.AggregationNode.singleGroupingSet;
import static io.trino.testing.TestingHandles.TEST_TABLE_HANDLE;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Test(singleThreaded = true)
public class TestTypeValidator
Expand Down Expand Up @@ -212,7 +213,7 @@ public void testValidTypeOnlyCoercion()
assertTypesValid(node);
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
@Test
public void testInvalidProject()
{
Expression expression1 = new Cast(columnB.toSymbolReference(), toSqlType(INTEGER));
Expand All @@ -226,10 +227,12 @@ public void testInvalidProject()
baseTableScan,
assignments);

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer");
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
@Test
public void testInvalidAggregationFunctionCall()
{
Symbol aggregationSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
Expand All @@ -250,10 +253,12 @@ public void testInvalidAggregationFunctionCall()
Optional.empty(),
Optional.empty());

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint");
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be bigint, but the actual type is double")
@Test
public void testInvalidAggregationFunctionSignature()
{
Symbol aggregationSymbol = symbolAllocator.newSymbol("sum", BIGINT);
Expand All @@ -274,10 +279,12 @@ public void testInvalidAggregationFunctionSignature()
Optional.empty(),
Optional.empty());

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'sum(_[0-9]+)?' is expected to be bigint, but the actual type is double");
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
@Test
public void testInvalidWindowFunctionCall()
{
Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
Expand Down Expand Up @@ -307,10 +314,12 @@ public void testInvalidWindowFunctionCall()
ImmutableSet.of(),
0);

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint");
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be bigint, but the actual type is double")
@Test
public void testInvalidWindowFunctionSignature()
{
Symbol windowSymbol = symbolAllocator.newSymbol("sum", BIGINT);
Expand Down Expand Up @@ -340,10 +349,12 @@ public void testInvalidWindowFunctionSignature()
ImmutableSet.of(),
0);

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'sum(_[0-9]+)?' is expected to be bigint, but the actual type is double");
}

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint")
@Test
public void testInvalidUnion()
{
Symbol outputSymbol = symbolAllocator.newSymbol("output", DATE);
Expand All @@ -358,7 +369,9 @@ public void testInvalidUnion()
mappings,
ImmutableList.copyOf(mappings.keySet()));

assertTypesValid(node);
assertThatThrownBy(() -> assertTypesValid(node))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageMatching("type of symbol 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint");
}

private void assertTypesValid(PlanNode node)
Expand Down

0 comments on commit 73ad472

Please sign in to comment.