Skip to content

Commit 3cd276e

Browse files
committed
Iceberg: PartitionsTable#partitions returns incomplete list in case of partition evolution and null partition values
1 parent 4108ec4 commit 3cd276e

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

iceberg/iceberg-handler/src/test/results/positive/llap/iceberg_major_compaction_partition_evolution.q.out

+1
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ POSTHOOK: type: SHOW COMPACTIONS
447447
CompactionId Database Table Partition Type State Worker host Worker Enqueue Time Start Time Duration(ms) HadoopJobId Error message Initiator host Initiator Pool name TxnId Next TxnId Commit Time Highest WriteId
448448
#Masked# default ice_orc company_id=100/dept_id=1 MAJOR succeeded #Masked# manual iceberg 0 0 0 ---
449449
#Masked# default ice_orc company_id=100/dept_id=2 MAJOR succeeded #Masked# manual iceberg 0 0 0 ---
450+
#Masked# default ice_orc company_id=null/dept_id=null MAJOR refused MacBook-Pro.local 360 1742034058581 1742034062982 119 --- --- MacBook-Pro.local manual iceberg 0 0 0 ---
450451
#Masked# default ice_orc --- MAJOR succeeded #Masked# manual iceberg 0 0 0 ---
451452
PREHOOK: query: select `partition`, spec_id, content, record_count
452453
from default.ice_orc.files

iceberg/patched-iceberg-core/src/main/java/org/apache/iceberg/PartitionsTable.java

+9-27
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
3030
import org.apache.iceberg.types.Types;
3131
import org.apache.iceberg.util.ParallelIterable;
32+
import org.apache.iceberg.util.PartitionMap;
3233
import org.apache.iceberg.util.PartitionUtil;
33-
import org.apache.iceberg.util.StructLikeMap;
3434

3535
// TODO: remove class once upgraded to Iceberg v1.7.0
3636

@@ -168,21 +168,26 @@ private static StaticDataTask.Row convertPartition(Partition partition) {
168168

169169
private static Iterable<Partition> partitions(Table table, StaticTableScan scan) {
170170
Types.StructType partitionType = Partitioning.partitionType(table);
171-
PartitionMap partitions = new PartitionMap(partitionType);
171+
PartitionMap<Partition> partitions = PartitionMap.create(table.specs());
172172
try (CloseableIterable<ManifestEntry<? extends ContentFile<?>>> entries = planEntries(scan)) {
173173
for (ManifestEntry<? extends ContentFile<?>> entry : entries) {
174174
Snapshot snapshot = table.snapshot(entry.snapshotId());
175175
ContentFile<?> file = entry.file();
176176
StructLike partition =
177177
PartitionUtil.coercePartition(
178178
partitionType, table.specs().get(file.specId()), file.partition());
179-
partitions.get(partition).update(file, snapshot);
179+
partitions
180+
.computeIfAbsent(
181+
file.specId(),
182+
((PartitionData) file.partition()).copy(),
183+
() -> new Partition(partition, partitionType))
184+
.update(file, snapshot);
180185
}
181186
} catch (IOException e) {
182187
throw new UncheckedIOException(e);
183188
}
184189

185-
return partitions.all();
190+
return partitions.values();
186191
}
187192

188193
@VisibleForTesting
@@ -241,29 +246,6 @@ private class PartitionsScan extends StaticTableScan {
241246
}
242247
}
243248

244-
static class PartitionMap {
245-
private final StructLikeMap<Partition> partitions;
246-
private final Types.StructType keyType;
247-
248-
PartitionMap(Types.StructType type) {
249-
this.partitions = StructLikeMap.create(type);
250-
this.keyType = type;
251-
}
252-
253-
Partition get(StructLike key) {
254-
Partition partition = partitions.get(key);
255-
if (partition == null) {
256-
partition = new Partition(key, keyType);
257-
partitions.put(key, partition);
258-
}
259-
return partition;
260-
}
261-
262-
Iterable<Partition> all() {
263-
return partitions.values();
264-
}
265-
}
266-
267249
static class Partition {
268250
private final PartitionData partitionData;
269251
private int specId;

0 commit comments

Comments
 (0)