Skip to content

Commit ee3b273

Browse files
committed
Assert partition type must be Record
1 parent becf073 commit ee3b273

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/src/main/java/org/apache/iceberg/PartitionStats.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
package org.apache.iceberg;
2020

2121
import java.util.Objects;
22+
import org.apache.iceberg.data.Record;
2223
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
2324

2425
public class PartitionStats implements StructLike {
2526

2627
private static final int STATS_COUNT = 12;
2728

29+
// Storing as StructLike instead of Record as
30+
// internal parquet writers can be used in future without modifying the members of this class.
2831
private StructLike partition;
2932
private int specId;
3033
private long dataRecordCount;
@@ -39,6 +42,8 @@ public class PartitionStats implements StructLike {
3942
private Long lastUpdatedSnapshotId; // null by default
4043

4144
public PartitionStats(StructLike partition, int specId) {
45+
Preconditions.checkArgument(
46+
partition instanceof Record, "Partition must be an instance of Record");
4247
this.partition = partition;
4348
this.specId = specId;
4449
}
@@ -206,6 +211,8 @@ public <T> T get(int pos, Class<T> javaClass) {
206211
public <T> void set(int pos, T value) {
207212
switch (pos) {
208213
case 0:
214+
Preconditions.checkArgument(
215+
partition instanceof Record, "Partition must be an instance of Record");
209216
this.partition = (StructLike) value;
210217
break;
211218
case 1:

data/src/main/java/org/apache/iceberg/data/PartitionStatsHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Collection;
2828
import java.util.Iterator;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.function.BiFunction;
3132
import org.apache.iceberg.FileFormat;
3233
import org.apache.iceberg.HasTableOperations;
@@ -232,7 +233,8 @@ private static OutputFile newPartitionStatsFile(Table table, long snapshotId) {
232233
((HasTableOperations) table)
233234
.operations()
234235
.metadataFileLocation(
235-
fileFormat.addExtension(String.format("partition-stats-%d", snapshotId))));
236+
fileFormat.addExtension(
237+
String.format(Locale.ROOT, "partition-stats-%d", snapshotId))));
236238
}
237239

238240
private static PartitionStatsRecord recordToPartitionStatsRecord(Record record) {

0 commit comments

Comments
 (0)