Skip to content

Commit

Permalink
Avoid type coercion when a dereferenced field is same type
Browse files Browse the repository at this point in the history
  • Loading branch information
laurachenyu authored and ebyhr committed Aug 6, 2020
1 parent 8131d34 commit 039d3a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ public HivePageSource(
.orElse(ImmutableList.of());
HiveType fromType = columnMapping.getBaseTypeCoercionFrom().get().getHiveTypeForDereferences(dereferenceIndices).get();
HiveType toType = columnMapping.getHiveColumnHandle().getHiveType();
coercers.add(Optional.of(createCoercer(typeManager, fromType, toType)));
if (!fromType.equals(toType)) {
coercers.add(Optional.of(createCoercer(typeManager, fromType, toType)));
}
else {
coercers.add(Optional.empty());
}
}
else {
coercers.add(Optional.empty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4336,6 +4336,19 @@ private void schemaMismatchesWithDereferenceProjections(HiveStorageFormat format
finally {
assertUpdate("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 (1, 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 (2, row(2, 'def', 2), 2)", 1);
assertQuery("SELECT a.b FROM evolve_test", "VALUES 1, 2");
}
finally {
assertUpdate("DROP TABLE IF EXISTS evolve_test");
}
}

@Test
Expand Down

0 comments on commit 039d3a6

Please sign in to comment.