-
Notifications
You must be signed in to change notification settings - Fork 3k
Add table metadata changes for statistics information in table metadata #5450
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** A metadata about a statistics or indices blob. */ | ||
| public interface BlobMetadata { | ||
| /** Type of the blob. Never null */ | ||
| String type(); | ||
|
|
||
| /** ID of the Iceberg table's snapshot the blob was computed from */ | ||
| long sourceSnapshotId(); | ||
|
|
||
| /** Sequence number of the Iceberg table's snapshot the blob was computed from */ | ||
| long sourceSnapshotSequenceNumber(); | ||
|
|
||
| /** Ordered list of fields the blob was calculated from. Never null */ | ||
| List<Integer> fields(); | ||
|
|
||
| /** Additional properties of the blob, specific to the blob type. Never null */ | ||
| Map<String, String> properties(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Represents a statistics file in the Puffin format, that can be used to read table data more | ||
| * efficiently. | ||
| * | ||
| * <p>Statistics are informational. A reader can choose to ignore statistics information. Statistics | ||
| * support is not required to read the table correctly. | ||
| */ | ||
| public interface StatisticsFile { | ||
| /** ID of the Iceberg table's snapshot the statistics were computed from. */ | ||
| long snapshotId(); | ||
|
|
||
| /** | ||
| * Returns fully qualified path to the file, suitable for constructing a Hadoop Path. Never null. | ||
| */ | ||
| String path(); | ||
|
|
||
| /** Size of the file */ | ||
| long fileSizeInBytes(); | ||
|
|
||
| /** Size of the Puffin footer. */ | ||
| long fileFooterSizeInBytes(); | ||
|
|
||
| /** List of statistics contained in the file. Never null. */ | ||
| List<BlobMetadata> blobMetadata(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.StringJoiner; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; | ||
|
|
||
| public class GenericBlobMetadata implements BlobMetadata { | ||
| private final String type; | ||
| private final long sourceSnapshotId; | ||
| private final long sourceSnapshotSequenceNumber; | ||
| private final List<Integer> fields; | ||
| private final Map<String, String> properties; | ||
|
|
||
| public GenericBlobMetadata( | ||
| String type, | ||
| long sourceSnapshotId, | ||
| long sourceSnapshotSequenceNumber, | ||
| List<Integer> fields, | ||
| Map<String, String> properties) { | ||
| Preconditions.checkNotNull(type, "type is null"); | ||
| Preconditions.checkNotNull(fields, "fields is null"); | ||
| Preconditions.checkNotNull(properties, "properties is null"); | ||
| this.type = type; | ||
| this.sourceSnapshotId = sourceSnapshotId; | ||
| this.sourceSnapshotSequenceNumber = sourceSnapshotSequenceNumber; | ||
| this.fields = ImmutableList.copyOf(fields); | ||
| this.properties = ImmutableMap.copyOf(properties); | ||
| } | ||
|
|
||
| @Override | ||
| public String type() { | ||
| return type; | ||
| } | ||
|
|
||
| @Override | ||
| public long sourceSnapshotId() { | ||
| return sourceSnapshotId; | ||
| } | ||
|
|
||
| @Override | ||
| public long sourceSnapshotSequenceNumber() { | ||
| return sourceSnapshotSequenceNumber; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Integer> fields() { | ||
| return fields; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> properties() { | ||
| return properties; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| GenericBlobMetadata that = (GenericBlobMetadata) o; | ||
| return sourceSnapshotId == that.sourceSnapshotId | ||
| && sourceSnapshotSequenceNumber == that.sourceSnapshotSequenceNumber | ||
| && Objects.equals(type, that.type) | ||
| && Objects.equals(fields, that.fields) | ||
| && Objects.equals(properties, that.properties); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(type, sourceSnapshotId, sourceSnapshotSequenceNumber, fields, properties); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return new StringJoiner(", ", GenericBlobMetadata.class.getSimpleName() + "[", "]") | ||
| .add("type='" + type + "'") | ||
| .add("sourceSnapshotId=" + sourceSnapshotId) | ||
| .add("sourceSnapshotSequenceNumber=" + sourceSnapshotSequenceNumber) | ||
| .add("fields=" + fields) | ||
| .add("properties=" + properties) | ||
| .toString(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.iceberg; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.StringJoiner; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
|
|
||
| public class GenericStatisticsFile implements StatisticsFile { | ||
| private final long snapshotId; | ||
| private final String path; | ||
| private final long fileSizeInBytes; | ||
| private final long fileFooterSizeInBytes; | ||
| private final List<BlobMetadata> blobMetadata; | ||
|
|
||
| public GenericStatisticsFile( | ||
| long snapshotId, | ||
| String path, | ||
| long fileSizeInBytes, | ||
| long fileFooterSizeInBytes, | ||
| List<BlobMetadata> blobMetadata) { | ||
| Preconditions.checkNotNull(path, "path is null"); | ||
| Preconditions.checkNotNull(blobMetadata, "blobMetadata is null"); | ||
| this.snapshotId = snapshotId; | ||
| this.path = path; | ||
| this.fileSizeInBytes = fileSizeInBytes; | ||
| this.fileFooterSizeInBytes = fileFooterSizeInBytes; | ||
| this.blobMetadata = ImmutableList.copyOf(blobMetadata); | ||
| } | ||
|
|
||
| @Override | ||
| public long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
|
|
||
| @Override | ||
| public String path() { | ||
| return path; | ||
| } | ||
|
|
||
| @Override | ||
| public long fileSizeInBytes() { | ||
| return fileSizeInBytes; | ||
| } | ||
|
|
||
| @Override | ||
| public long fileFooterSizeInBytes() { | ||
| return fileFooterSizeInBytes; | ||
| } | ||
|
|
||
| @Override | ||
| public List<BlobMetadata> blobMetadata() { | ||
| return blobMetadata; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| GenericStatisticsFile that = (GenericStatisticsFile) o; | ||
| return snapshotId == that.snapshotId | ||
| && fileSizeInBytes == that.fileSizeInBytes | ||
| && fileFooterSizeInBytes == that.fileFooterSizeInBytes | ||
| && Objects.equals(path, that.path) | ||
| && Objects.equals(blobMetadata, that.blobMetadata); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(snapshotId, path, fileSizeInBytes, fileFooterSizeInBytes, blobMetadata); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return new StringJoiner(", ", GenericStatisticsFile.class.getSimpleName() + "[", "]") | ||
| .add("snapshotId=" + snapshotId) | ||
| .add("path='" + path + "'") | ||
| .add("fileSizeInBytes=" + fileSizeInBytes) | ||
| .add("fileFooterSizeInBytes=" + fileFooterSizeInBytes) | ||
| .add("blobMetadata=" + blobMetadata) | ||
| .toString(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,6 +178,46 @@ public void applyTo(TableMetadata.Builder metadataBuilder) { | |
| } | ||
| } | ||
|
|
||
| class SetStatistics implements MetadataUpdate { | ||
findepi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final long snapshotId; | ||
| private final StatisticsFile statisticsFile; | ||
|
|
||
| public SetStatistics(long snapshotId, StatisticsFile statisticsFile) { | ||
| this.snapshotId = snapshotId; | ||
| this.statisticsFile = statisticsFile; | ||
| } | ||
|
|
||
| public long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
|
|
||
| public StatisticsFile statisticsFile() { | ||
| return statisticsFile; | ||
| } | ||
|
|
||
| @Override | ||
| public void applyTo(TableMetadata.Builder metadataBuilder) { | ||
| metadataBuilder.setStatistics(snapshotId, statisticsFile); | ||
| } | ||
| } | ||
|
|
||
| class RemoveStatistics implements MetadataUpdate { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this going to be used? Should we have a single
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When working on Trino stats support in Hive and Delta we found out that ability to remove stats is useful. We need a way to remove statistics from a table, for example if we detect that application that wrote stats did it incorrectly, or when stats are correct, but a query engine makes wrong conclusions using those stats and plans are bad in practice. @rdblue how would you want to model this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds good to me. Is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
| private final long snapshotId; | ||
|
|
||
| public RemoveStatistics(long snapshotId) { | ||
| this.snapshotId = snapshotId; | ||
| } | ||
|
|
||
| public long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
|
|
||
| @Override | ||
| public void applyTo(TableMetadata.Builder metadataBuilder) { | ||
| metadataBuilder.removeStatistics(snapshotId); | ||
| } | ||
| } | ||
|
|
||
| class AddSnapshot implements MetadataUpdate { | ||
| private final Snapshot snapshot; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.