Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ private ReaderPageSourceWithRowPositions createDataPageSource(
fileSchema,
nameMapping,
partition,
dataColumns);
dataColumns,
partitionKeys);
};
}

Expand Down Expand Up @@ -1113,7 +1114,8 @@ private static ReaderPageSourceWithRowPositions createAvroPageSource(
Schema fileSchema,
Optional<NameMapping> nameMapping,
String partition,
List<IcebergColumnHandle> columns)
List<IcebergColumnHandle> columns,
Map<Integer, Optional<String>> partitionKeys)
{
InputFile file = new ForwardingInputFile(inputFile);
OptionalLong fileModifiedTime = OptionalLong.empty();
Expand Down Expand Up @@ -1146,7 +1148,13 @@ private static ReaderPageSourceWithRowPositions createAvroPageSource(

int nextOrdinal = 0;
for (IcebergColumnHandle column : columns) {
if (column.isPartitionColumn()) {
if (partitionKeys.containsKey(column.getId())) {
Type trinoType = column.getType();
transforms.constantValue(nativeValueToBlock(
trinoType,
deserializePartitionValue(trinoType, partitionKeys.get(column.getId()).orElse(null), column.getName())));
}
else if (column.isPartitionColumn()) {
transforms.constantValue(nativeValueToBlock(PARTITION.getType(), utf8Slice(partition)));
}
else if (column.isPathColumn()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import static com.google.common.collect.MoreCollectors.onlyElement;
import static io.trino.plugin.iceberg.IcebergFileFormat.AVRO;
import static io.trino.plugin.iceberg.IcebergFileFormat.ORC;
import static io.trino.plugin.iceberg.IcebergFileFormat.PARQUET;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -289,12 +291,19 @@ public static Object[][] fileFormats()

@Test
public void testMigratePartitionedTable()
{
testMigratePartitionedTable(PARQUET);
testMigratePartitionedTable(ORC);
testMigratePartitionedTable(AVRO);
}

private void testMigratePartitionedTable(IcebergFileFormat format)
{
String tableName = "test_migrate_partitioned_" + randomNameSuffix();
String hiveTableName = "hive.tpch." + tableName;
String icebergTableName = "iceberg.tpch." + tableName;

assertUpdate("CREATE TABLE " + hiveTableName + " WITH (partitioned_by = ARRAY['part_col']) AS SELECT 1 id, 'part1' part_col", 1);
assertUpdate("CREATE TABLE " + hiveTableName + " WITH (format = '" + format + "', partitioned_by = ARRAY['part_col']) AS SELECT 1 id, 'part1' part_col", 1);
assertQueryFails("SELECT * FROM " + icebergTableName, "Not an Iceberg table: .*");

assertUpdate("CALL iceberg.system.migrate('tpch', '" + tableName + "')");
Expand Down
Loading