Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Avoid extract from file footer when stats mode is none #4604

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
import org.apache.paimon.format.SimpleStatsExtractor;
import org.apache.paimon.fs.FileIO;
import org.apache.paimon.fs.Path;
import org.apache.paimon.statistics.NoneSimpleColStatsCollector;
import org.apache.paimon.statistics.SimpleColStatsCollector;
import org.apache.paimon.types.RowType;
import org.apache.paimon.utils.Preconditions;

import javax.annotation.Nullable;

import java.io.IOException;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.IntStream;

/**
* A {@link SingleFileWriter} which also produces statistics for each written field.
Expand All @@ -44,6 +47,8 @@ public abstract class StatsCollectingSingleFileWriter<T, R> extends SingleFileWr

@Nullable private final SimpleStatsExtractor simpleStatsExtractor;
@Nullable private SimpleStatsCollector simpleStatsCollector = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep it nullable, and just create a field isStatsDisabled from

Arrays.stream(statsCollectors)
                        .allMatch(p -> p instanceof NoneSimpleColStatsCollector)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@Nullable private SimpleColStats[] noneStats = null;
private final boolean isStatsDisabled;

public StatsCollectingSingleFileWriter(
FileIO fileIO,
Expand All @@ -63,6 +68,15 @@ public StatsCollectingSingleFileWriter(
Preconditions.checkArgument(
statsCollectors.length == writeSchema.getFieldCount(),
"The stats collector is not aligned to write schema.");
this.isStatsDisabled =
Arrays.stream(SimpleColStatsCollector.create(statsCollectors))
.allMatch(p -> p instanceof NoneSimpleColStatsCollector);
if (isStatsDisabled) {
this.noneStats =
IntStream.range(0, statsCollectors.length)
.mapToObj(i -> SimpleColStats.NONE)
.toArray(SimpleColStats[]::new);
}
}

@Override
Expand All @@ -85,7 +99,11 @@ public void writeBundle(BundleRecords bundle) throws IOException {
public SimpleColStats[] fieldStats() throws IOException {
Preconditions.checkState(closed, "Cannot access metric unless the writer is closed.");
if (simpleStatsExtractor != null) {
return simpleStatsExtractor.extract(fileIO, path);
if (isStatsDisabled) {
return noneStats;
} else {
return simpleStatsExtractor.extract(fileIO, path);
}
} else {
return simpleStatsCollector.extract();
}
Expand Down
Loading