Skip to content

Commit

Permalink
Refactor testSchemaMismatchesWithDereferenceProjections
Browse files Browse the repository at this point in the history
Utilize existing test helper for iterating over storage formats.
  • Loading branch information
findepi committed Aug 14, 2023
1 parent c0a1858 commit 9e02c42
Showing 1 changed file with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5523,52 +5523,50 @@ public void testBucketFilteringByInPredicate()
@Test
public void testSchemaMismatchesWithDereferenceProjections()
{
for (TestingHiveStorageFormat format : getAllTestingHiveStorageFormat()) {
testSchemaMismatchesWithDereferenceProjections(format.getFormat());
}
testWithAllStorageFormats(this::testSchemaMismatchesWithDereferenceProjections);
}

private void testSchemaMismatchesWithDereferenceProjections(HiveStorageFormat format)
private void testSchemaMismatchesWithDereferenceProjections(Session session, HiveStorageFormat format)
{
// Verify reordering of subfields between a partition column and a table column is not supported
// eg. table column: a row(c varchar, b bigint), partition column: a row(b bigint, c varchar)
try {
assertUpdate("CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate("INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1);
assertUpdate("ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate("ALTER TABLE evolve_test ADD COLUMN a row(c varchar, b bigint)");
assertUpdate("INSERT INTO evolve_test values (20, row('def', 2), 2)", 1);
assertQueryFails("SELECT a.b FROM evolve_test where d = 1", ".*There is a mismatch between the table and partition schemas.*");
assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate(session, "INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1);
assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(c varchar, b bigint)");
assertUpdate(session, "INSERT INTO evolve_test values (20, row('def', 2), 2)", 1);
assertQueryFails(session, "SELECT a.b FROM evolve_test where d = 1", ".*There is a mismatch between the table and partition schemas.*");
}
finally {
assertUpdate("DROP TABLE IF EXISTS evolve_test");
assertUpdate(session, "DROP TABLE IF EXISTS evolve_test");
}

// Subfield absent in partition schema is reported as null
// i.e. "a.c" produces null for rows that were inserted before type of "a" was changed
try {
assertUpdate("CREATE TABLE evolve_test (dummy bigint, a row(b bigint), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate("INSERT INTO evolve_test values (10, row(1), 1)", 1);
assertUpdate("ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate("ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar)");
assertUpdate("INSERT INTO evolve_test values (20, row(2, 'def'), 2)", 1);
assertQuery("SELECT a.c FROM evolve_test", "SELECT 'def' UNION SELECT null");
assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate(session, "INSERT INTO evolve_test values (10, row(1), 1)", 1);
assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar)");
assertUpdate(session, "INSERT INTO evolve_test values (20, row(2, 'def'), 2)", 1);
assertQuery(session, "SELECT a.c FROM evolve_test", "SELECT 'def' UNION SELECT null");
}
finally {
assertUpdate("DROP TABLE IF EXISTS evolve_test");
assertUpdate(session, "DROP TABLE IF EXISTS evolve_test");
}

// Verify field access when the row evolves without changes to field type
try {
assertUpdate("CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate("INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1);
assertUpdate("ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate("ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar, e int)");
assertUpdate("INSERT INTO evolve_test values (20, row(2, 'def', 2), 2)", 1);
assertQuery("SELECT a.b FROM evolve_test", "VALUES 1, 2");
assertUpdate(session, "CREATE TABLE evolve_test (dummy bigint, a row(b bigint, c varchar), d bigint) with (format = '" + format + "', partitioned_by=array['d'])");
assertUpdate(session, "INSERT INTO evolve_test values (10, row(1, 'abc'), 1)", 1);
assertUpdate(session, "ALTER TABLE evolve_test DROP COLUMN a");
assertUpdate(session, "ALTER TABLE evolve_test ADD COLUMN a row(b bigint, c varchar, e int)");
assertUpdate(session, "INSERT INTO evolve_test values (20, row(2, 'def', 2), 2)", 1);
assertQuery(session, "SELECT a.b FROM evolve_test", "VALUES 1, 2");
}
finally {
assertUpdate("DROP TABLE IF EXISTS evolve_test");
assertUpdate(session, "DROP TABLE IF EXISTS evolve_test");
}
}

Expand Down

0 comments on commit 9e02c42

Please sign in to comment.