Skip to content

Commit 3baa8db

Browse files
committed
fix
1 parent 5be8cbb commit 3baa8db

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

paimon-core/src/main/java/org/apache/paimon/io/SimpleStatsProducer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public boolean requirePerRecord() {
8383
}
8484

8585
@Override
86-
public void collect(InternalRow row) {}
86+
public void collect(InternalRow row) {
87+
throw new IllegalStateException();
88+
}
8789

8890
@Override
8991
public SimpleColStats[] extract(FileIO fileIO, Path path, long length)

paimon-core/src/main/java/org/apache/paimon/io/StatsCollectingSingleFileWriter.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,38 @@
3838
*/
3939
public abstract class StatsCollectingSingleFileWriter<T, R> extends SingleFileWriter<T, R> {
4040

41+
private final RowType rowType;
4142
private final SimpleStatsProducer statsProducer;
42-
private final SimpleColStats[] noneStats;
43+
private final boolean isStatsDisabled;
44+
private final boolean statsRequirePerRecord;
4345

4446
public StatsCollectingSingleFileWriter(
4547
FileIO fileIO,
4648
FormatWriterFactory factory,
4749
Path path,
4850
Function<T, InternalRow> converter,
49-
RowType writeSchema,
51+
RowType rowType,
5052
SimpleStatsProducer statsProducer,
5153
String compression,
5254
boolean asyncWrite) {
5355
super(fileIO, factory, path, converter, compression, asyncWrite);
56+
this.rowType = rowType;
5457
this.statsProducer = statsProducer;
55-
if (statsProducer.isStatsDisabled()) {
56-
this.noneStats =
57-
IntStream.range(0, writeSchema.getFieldCount())
58-
.mapToObj(i -> SimpleColStats.NONE)
59-
.toArray(SimpleColStats[]::new);
60-
} else {
61-
this.noneStats = null;
62-
}
58+
this.isStatsDisabled = statsProducer.isStatsDisabled();
59+
this.statsRequirePerRecord = statsProducer.requirePerRecord();
6360
}
6461

6562
@Override
6663
public void write(T record) throws IOException {
6764
InternalRow rowData = writeImpl(record);
68-
if (noneStats == null) {
65+
if (!isStatsDisabled && statsRequirePerRecord) {
6966
statsProducer.collect(rowData);
7067
}
7168
}
7269

7370
@Override
7471
public void writeBundle(BundleRecords bundle) throws IOException {
75-
if (statsProducer.requirePerRecord()) {
72+
if (statsRequirePerRecord) {
7673
throw new IllegalArgumentException(
7774
String.format(
7875
"Can't write bundle for %s, we may lose all the statistical information.",
@@ -83,8 +80,10 @@ public void writeBundle(BundleRecords bundle) throws IOException {
8380

8481
public SimpleColStats[] fieldStats(long fileSize) throws IOException {
8582
Preconditions.checkState(closed, "Cannot access metric unless the writer is closed.");
86-
if (noneStats != null) {
87-
return noneStats;
83+
if (isStatsDisabled) {
84+
return IntStream.range(0, rowType.getFieldCount())
85+
.mapToObj(i -> SimpleColStats.NONE)
86+
.toArray(SimpleColStats[]::new);
8887
}
8988

9089
return statsProducer.extract(fileIO, path, fileSize);

0 commit comments

Comments
 (0)