|
29 | 29 | import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
|
30 | 30 | import org.apache.iceberg.types.Types;
|
31 | 31 | import org.apache.iceberg.util.ParallelIterable;
|
| 32 | +import org.apache.iceberg.util.PartitionMap; |
32 | 33 | import org.apache.iceberg.util.PartitionUtil;
|
33 |
| -import org.apache.iceberg.util.StructLikeMap; |
34 | 34 |
|
35 | 35 | // TODO: remove class once upgraded to Iceberg v1.7.0
|
36 | 36 |
|
@@ -168,21 +168,26 @@ private static StaticDataTask.Row convertPartition(Partition partition) {
|
168 | 168 |
|
169 | 169 | private static Iterable<Partition> partitions(Table table, StaticTableScan scan) {
|
170 | 170 | Types.StructType partitionType = Partitioning.partitionType(table);
|
171 |
| - PartitionMap partitions = new PartitionMap(partitionType); |
| 171 | + PartitionMap<Partition> partitions = PartitionMap.create(table.specs()); |
172 | 172 | try (CloseableIterable<ManifestEntry<? extends ContentFile<?>>> entries = planEntries(scan)) {
|
173 | 173 | for (ManifestEntry<? extends ContentFile<?>> entry : entries) {
|
174 | 174 | Snapshot snapshot = table.snapshot(entry.snapshotId());
|
175 | 175 | ContentFile<?> file = entry.file();
|
176 | 176 | StructLike partition =
|
177 | 177 | PartitionUtil.coercePartition(
|
178 | 178 | 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); |
180 | 185 | }
|
181 | 186 | } catch (IOException e) {
|
182 | 187 | throw new UncheckedIOException(e);
|
183 | 188 | }
|
184 | 189 |
|
185 |
| - return partitions.all(); |
| 190 | + return partitions.values(); |
186 | 191 | }
|
187 | 192 |
|
188 | 193 | @VisibleForTesting
|
@@ -241,29 +246,6 @@ private class PartitionsScan extends StaticTableScan {
|
241 | 246 | }
|
242 | 247 | }
|
243 | 248 |
|
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 |
| - |
267 | 249 | static class Partition {
|
268 | 250 | private final PartitionData partitionData;
|
269 | 251 | private int specId;
|
|
0 commit comments