Skip to content

Commit

Permalink
Use assertThatThrownBy in TestHiveConnectorTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Damans227 authored and findepi committed Oct 30, 2021
1 parent b37ebe8 commit 2dc0062
Showing 1 changed file with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public void testRequiredPartitionFilterInferred(String queryPartitionFilterRequi
@DataProvider
public Object[][] queryPartitionFilterRequiredSchemasDataProvider()
{
return new Object[][]{
return new Object[][] {
{"[]"},
{"[\"tpch\"]"}
};
Expand Down Expand Up @@ -1840,61 +1840,73 @@ public void testPropertiesTable()
assertUpdate("DROP TABLE test_show_properties");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Partition keys must be the last columns in the table and in the same order as the table properties.*")
@Test
public void testCreatePartitionedTableInvalidColumnOrdering()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_invalid_column_ordering\n" +
"(grape bigint, apple varchar, orange bigint, pear varchar)\n" +
"WITH (partitioned_by = ARRAY['apple'])");
"WITH (partitioned_by = ARRAY['apple'])"))
.isInstanceOf(RuntimeException.class)
.hasMessageMatching("Partition keys must be the last columns in the table and in the same order as the table properties.*");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Partition keys must be the last columns in the table and in the same order as the table properties.*")
@Test
public void testCreatePartitionedTableAsInvalidColumnOrdering()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_as_invalid_column_ordering " +
"WITH (partitioned_by = ARRAY['SHIP_PRIORITY', 'ORDER_STATUS']) " +
"AS " +
"SELECT shippriority AS ship_priority, orderkey AS order_key, orderstatus AS order_status " +
"FROM tpch.tiny.orders");
"FROM tpch.tiny.orders"))
.isInstanceOf(RuntimeException.class)
.hasMessageMatching("Partition keys must be the last columns in the table and in the same order as the table properties.*");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Table contains only partition columns")
@Test
public void testCreateTableOnlyPartitionColumns()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_only_partition_columns\n" +
"(grape bigint, apple varchar, orange bigint, pear varchar)\n" +
"WITH (partitioned_by = ARRAY['grape', 'apple', 'orange', 'pear'])");
"WITH (partitioned_by = ARRAY['grape', 'apple', 'orange', 'pear'])"))
.isInstanceOf(RuntimeException.class)
.hasMessage("Table contains only partition columns");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Partition columns .* not present in schema")
@Test
public void testCreateTableNonExistentPartitionColumns()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_nonexistent_partition_columns\n" +
"(grape bigint, apple varchar, orange bigint, pear varchar)\n" +
"WITH (partitioned_by = ARRAY['dragonfruit'])");
"WITH (partitioned_by = ARRAY['dragonfruit'])"))
.isInstanceOf(RuntimeException.class)
.hasMessageMatching("Partition columns .* not present in schema");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Unsupported type .* for partition: .*")
@Test
public void testCreateTableUnsupportedPartitionType()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_unsupported_partition_type " +
"(foo bigint, bar ARRAY(varchar)) " +
"WITH (partitioned_by = ARRAY['bar'])");
"WITH (partitioned_by = ARRAY['bar'])"))
.isInstanceOf(RuntimeException.class)
.hasMessageMatching("Unsupported type .* for partition: .*");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Unsupported type .* for partition: a")
@Test
public void testCreateTableUnsupportedPartitionTypeAs()
{
assertUpdate("" +
assertThatThrownBy(() -> getQueryRunner().execute("" +
"CREATE TABLE test_create_table_unsupported_partition_type_as " +
"WITH (partitioned_by = ARRAY['a']) " +
"AS " +
"SELECT 123 x, ARRAY ['foo'] a");
"SELECT 123 x, ARRAY ['foo'] a"))
.isInstanceOf(RuntimeException.class)
.hasMessageMatching("Unsupported type .* for partition: a");
}

@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "Unsupported Hive type: varchar\\(65536\\)\\. Supported VARCHAR types: VARCHAR\\(<=65535\\), VARCHAR\\.")
Expand Down

0 comments on commit 2dc0062

Please sign in to comment.