Skip to content

Commit 37d1917

Browse files
committed
Core: Make totalRecordCount optional in PartitionStats
1 parent 31e9dc7 commit 37d1917

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class PartitionStats implements StructLike {
3333
private int positionDeleteFileCount;
3434
private long equalityDeleteRecordCount;
3535
private int equalityDeleteFileCount;
36-
private long totalRecordCount;
36+
private Long totalRecordCount; // null by default
3737
private Long lastUpdatedAt; // null by default
3838
private Long lastUpdatedSnapshotId; // null by default
3939

@@ -78,7 +78,16 @@ public int equalityDeleteFileCount() {
7878
return equalityDeleteFileCount;
7979
}
8080

81+
/**
82+
* @deprecated since 1.8.0, will be removed in 1.9.0, use {@link #totalRecordCountOptional()}
83+
* instead.
84+
*/
85+
@Deprecated
8186
public long totalRecordCount() {
87+
return totalRecordCount == null ? 0 : totalRecordCount;
88+
}
89+
90+
public Long totalRecordCountOptional() {
8291
return totalRecordCount;
8392
}
8493

@@ -150,7 +159,12 @@ public void appendStats(PartitionStats entry) {
150159
this.positionDeleteFileCount += entry.positionDeleteFileCount;
151160
this.equalityDeleteRecordCount += entry.equalityDeleteRecordCount;
152161
this.equalityDeleteFileCount += entry.equalityDeleteFileCount;
153-
this.totalRecordCount += entry.totalRecordCount;
162+
163+
if (totalRecordCount == null) {
164+
this.totalRecordCount = entry.totalRecordCount;
165+
} else {
166+
this.totalRecordCount += entry.totalRecordCount;
167+
}
154168

155169
if (entry.lastUpdatedAt != null) {
156170
updateSnapshotInfo(entry.lastUpdatedSnapshotId, entry.lastUpdatedAt);
@@ -236,8 +250,7 @@ public <T> void set(int pos, T value) {
236250
this.equalityDeleteFileCount = value == null ? 0 : (int) value;
237251
break;
238252
case 9:
239-
// optional field as per spec, implementation initialize to 0 for counters
240-
this.totalRecordCount = value == null ? 0L : (long) value;
253+
this.totalRecordCount = (Long) value;
241254
break;
242255
case 10:
243256
this.lastUpdatedAt = (Long) value;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private static void computeAndValidatePartitionStats(Table testTable, Tuple... e
417417
PartitionStats::positionDeleteFileCount,
418418
PartitionStats::equalityDeleteRecordCount,
419419
PartitionStats::equalityDeleteFileCount,
420-
PartitionStats::totalRecordCount,
420+
PartitionStats::totalRecordCountOptional,
421421
PartitionStats::lastUpdatedAt,
422422
PartitionStats::lastUpdatedSnapshotId)
423423
.containsExactlyInAnyOrder(expectedValues);

0 commit comments

Comments
 (0)