Skip to content

Commit

Permalink
Fix incorrect result when filtering partitions on Delta checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ebyhr committed Nov 13, 2024
1 parent 70ed876 commit 00a538f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,15 @@ private TupleDomain<HiveColumnHandle> buildTupleDomainColumnHandle(EntryType ent

private static HiveColumnHandle toPartitionValuesParsedField(HiveColumnHandle addColumn, DeltaLakeColumnHandle partitionColumn)
{
checkArgument(partitionColumn.isBaseColumn(), "partitionColumn must be a base column: %s", partitionColumn);
return new HiveColumnHandle(
addColumn.getBaseColumnName(),
addColumn.getBaseHiveColumnIndex(),
addColumn.getBaseHiveType(),
addColumn.getBaseType(),
Optional.of(new HiveColumnProjectionInfo(
ImmutableList.of(0, 0), // hiveColumnIndex; we provide fake value because we always find columns by name
ImmutableList.of("partitionvalues_parsed", partitionColumn.columnName()),
ImmutableList.of("partitionvalues_parsed", partitionColumn.basePhysicalColumnName()),
DeltaHiveTypeTranslator.toHiveType(partitionColumn.type()),
partitionColumn.type())),
HiveColumnHandle.ColumnType.REGULAR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,29 @@ private void testCreateTableWithCommentsForColumnMappingMode(ColumnMappingMode m
assertUpdate("DROP TABLE " + tableName);
}

@Test
void testPartitionPredicateOnCheckpointWithColumnMappingMode()
{
testPartitionPredicateOnCheckpointWithColumnMappingMode(ColumnMappingMode.ID);
testPartitionPredicateOnCheckpointWithColumnMappingMode(ColumnMappingMode.NAME);
testPartitionPredicateOnCheckpointWithColumnMappingMode(ColumnMappingMode.NONE);
}

private void testPartitionPredicateOnCheckpointWithColumnMappingMode(ColumnMappingMode mode)
{
try (TestTable table = new TestTable(
getQueryRunner()::execute,
"test_partition_checkpoint_with_column_mapping_mode",
"(x int, part int) WITH (column_mapping_mode='" + mode + "', checkpoint_interval = 3, partitioned_by = ARRAY['part'])")) {
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 10)", 1);
assertUpdate("INSERT INTO " + table.getName() + " VALUES (2, 20)", 1);
assertUpdate("INSERT INTO " + table.getName() + " VALUES (3, 30)", 1);

assertThat(query("SELECT * FROM " + table.getName() + " WHERE part = 10"))
.matches("VALUES (1, 10)");
}
}

@Test
public void testSpecialCharacterColumnNamesWithColumnMappingMode()
{
Expand Down

0 comments on commit 00a538f

Please sign in to comment.