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: Support aggregated basic stats in partition summary #11669

Closed
wants to merge 1 commit into from
Closed
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
34 changes: 31 additions & 3 deletions core/src/main/java/org/apache/iceberg/SnapshotProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.iceberg.metrics.Timer.Timed;
import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.base.Splitter;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.relocated.com.google.common.collect.Lists;
Expand All @@ -92,6 +93,9 @@ abstract class SnapshotProducer<ThisT> implements SnapshotUpdate<ThisT> {
static final int MIN_FILE_GROUP_SIZE = 10_000;
static final Set<ManifestFile> EMPTY_SET = Sets.newHashSet();

private static final Splitter.MapSplitter PARTITION_SUMMARY_PROP_SPLITTER =
Splitter.on(",").withKeyValueSeparator("=");

/** Default callback used to delete files. */
private final Consumer<String> defaultDelete =
new Consumer<String>() {
Expand Down Expand Up @@ -301,6 +305,7 @@ private Map<String, String> summary(TableMetadata previous) {

Map<String, String> previousSummary;
SnapshotRef previousBranchHead = previous.ref(targetBranch);

if (previousBranchHead != null) {
if (previous.snapshot(previousBranchHead.snapshotId()).summary() != null) {
previousSummary = previous.snapshot(previousBranchHead.snapshotId()).summary();
Expand All @@ -325,7 +330,32 @@ private Map<String, String> summary(TableMetadata previous) {

// copy all summary properties from the implementation
builder.putAll(summary);
aggregatedSummary(builder, previousSummary, summary);

if (Boolean.parseBoolean(summary.get(SnapshotSummary.PARTITION_SUMMARY_PROP))) {
summary.keySet().stream()
.filter(key -> key.startsWith(SnapshotSummary.CHANGED_PARTITION_PREFIX))
.forEach(
key -> {
Map<String, String> map = PARTITION_SUMMARY_PROP_SPLITTER.split(summary.get(key));
builder.put(
key,
SnapshotSummary.MAP_JOINER.join(
aggregatedSummary(
ImmutableMap.<String, String>builder().putAll(map),
previousSummary,
map)
.build()));
});
}
builder.putAll(EnvironmentContext.get());
return builder.buildKeepingLast();
}

private static ImmutableMap.Builder<String, String> aggregatedSummary(
ImmutableMap.Builder<String, String> builder,
Map<String, String> previousSummary,
Map<String, String> summary) {
updateTotal(
builder,
previousSummary,
Expand Down Expand Up @@ -368,9 +398,7 @@ private Map<String, String> summary(TableMetadata previous) {
summary,
SnapshotSummary.ADDED_EQ_DELETES_PROP,
SnapshotSummary.REMOVED_EQ_DELETES_PROP);

builder.putAll(EnvironmentContext.get());
return builder.build();
return builder;
}

protected TableMetadata current() {
Expand Down
Loading