Skip to content

Commit c2f2fd3

Browse files
committed
Address new comments
1 parent 271a970 commit c2f2fd3

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,7 @@ private PartitionStatsHandler() {}
108108
@Deprecated
109109
public static Schema schema(StructType unifiedPartitionType) {
110110
Preconditions.checkState(!unifiedPartitionType.fields().isEmpty(), "Table must be partitioned");
111-
return new Schema(
112-
NestedField.required(PARTITION_FIELD_ID, PARTITION_FIELD_NAME, unifiedPartitionType),
113-
SPEC_ID,
114-
DATA_RECORD_COUNT,
115-
DATA_FILE_COUNT,
116-
TOTAL_DATA_FILE_SIZE_IN_BYTES,
117-
POSITION_DELETE_RECORD_COUNT,
118-
POSITION_DELETE_FILE_COUNT,
119-
EQUALITY_DELETE_RECORD_COUNT,
120-
EQUALITY_DELETE_FILE_COUNT,
121-
TOTAL_RECORD_COUNT,
122-
LAST_UPDATED_AT,
123-
LAST_UPDATED_SNAPSHOT_ID);
111+
return v2Schema(unifiedPartitionType);
124112
}
125113

126114
/**
@@ -133,11 +121,35 @@ public static Schema schema(StructType unifiedPartitionType) {
133121
*/
134122
public static Schema schema(StructType unifiedPartitionType, int formatVersion) {
135123
Preconditions.checkState(!unifiedPartitionType.fields().isEmpty(), "Table must be partitioned");
124+
Preconditions.checkState(
125+
formatVersion > 0 && formatVersion <= TableMetadata.SUPPORTED_TABLE_FORMAT_VERSION,
126+
"Invalid format version: %d",
127+
formatVersion);
136128

137129
if (formatVersion <= 2) {
138-
return schema(unifiedPartitionType);
130+
return v2Schema(unifiedPartitionType);
139131
}
140132

133+
return v3Schema(unifiedPartitionType);
134+
}
135+
136+
private static Schema v2Schema(StructType unifiedPartitionType) {
137+
return new Schema(
138+
NestedField.required(PARTITION_FIELD_ID, PARTITION_FIELD_NAME, unifiedPartitionType),
139+
SPEC_ID,
140+
DATA_RECORD_COUNT,
141+
DATA_FILE_COUNT,
142+
TOTAL_DATA_FILE_SIZE_IN_BYTES,
143+
POSITION_DELETE_RECORD_COUNT,
144+
POSITION_DELETE_FILE_COUNT,
145+
EQUALITY_DELETE_RECORD_COUNT,
146+
EQUALITY_DELETE_FILE_COUNT,
147+
TOTAL_RECORD_COUNT,
148+
LAST_UPDATED_AT,
149+
LAST_UPDATED_SNAPSHOT_ID);
150+
}
151+
152+
private static Schema v3Schema(StructType unifiedPartitionType) {
141153
return new Schema(
142154
NestedField.required(PARTITION_FIELD_ID, PARTITION_FIELD_NAME, unifiedPartitionType),
143155
SPEC_ID,

core/src/test/java/org/apache/iceberg/PartitionStatsHandlerTestBase.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
5858
import org.apache.iceberg.types.Comparators;
5959
import org.apache.iceberg.types.Types;
60+
import org.apache.iceberg.util.ContentFileUtil;
6061
import org.assertj.core.groups.Tuple;
6162
import org.junit.jupiter.api.Test;
6263
import org.junit.jupiter.api.TestTemplate;
@@ -414,9 +415,8 @@ public void testPartitionStats() throws Exception {
414415
0));
415416

416417
DeleteFile posDeletes = null;
417-
DeleteFile deleteVectors = null;
418-
if (formatVersion == 3) {
419-
deleteVectors = commitDVs(testTable, dataFile3);
418+
if (formatVersion >= 3) {
419+
posDeletes = commitDVs(testTable, dataFile3);
420420
} else if (formatVersion == 2) {
421421
posDeletes = commitPositionDeletes(testTable);
422422
}
@@ -463,14 +463,14 @@ public void testPartitionStats() throws Exception {
463463
3 * dataFile3.recordCount(),
464464
3,
465465
3 * dataFile3.fileSizeInBytes(),
466-
formatVersion == 3 ? deleteVectors.recordCount() : posDeletes.recordCount(),
467-
formatVersion == 3 ? 0 : 1, // pos delete file count
466+
posDeletes.recordCount(),
467+
ContentFileUtil.isDV(posDeletes) ? 0 : 1, // pos delete file count
468468
0L,
469469
0,
470470
null,
471471
snapshot2.timestampMillis(),
472472
snapshot2.snapshotId(),
473-
formatVersion == 3 ? 1 : 0), // dv count
473+
ContentFileUtil.isDV(posDeletes) ? 1 : 0), // dv count
474474
Tuple.tuple(
475475
partitionRecord(partitionType, "bar", "B"),
476476
0,

0 commit comments

Comments
 (0)