-
Notifications
You must be signed in to change notification settings - Fork 3k
Move manifest factory methods #925
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dbb0c52
Move manifest factory methods to ManifestFiles.
rdblue 689c370
Move copyManifest methods and add format version argument.
rdblue 72bd99d
Fix tests added in #845.
rdblue c565af5
Deprecate ManifestWriter.write method.
rdblue 3ebeb7b
Add old ManifestReader.read method and remove deprecated uses.
rdblue ff8e182
Fix tests.
rdblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
core/src/main/java/org/apache/iceberg/ManifestFiles.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* | ||
| * 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 com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Sets; | ||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import org.apache.iceberg.exceptions.RuntimeIOException; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.io.InputFile; | ||
| import org.apache.iceberg.io.OutputFile; | ||
|
|
||
| public class ManifestFiles { | ||
| private ManifestFiles() { | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new {@link ManifestReader} for a {@link ManifestFile}. | ||
| * <p> | ||
| * <em>Note:</em> Callers should use {@link ManifestFiles#read(ManifestFile, FileIO, Map)} to ensure | ||
| * the schema used by filters is the latest table schema. This should be used only when reading | ||
| * a manifest without filters. | ||
| * | ||
| * @param manifest a ManifestFile | ||
| * @param io a FileIO | ||
| * @return a manifest reader | ||
| */ | ||
| public static ManifestReader read(ManifestFile manifest, FileIO io) { | ||
| return read(manifest, io, null); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new {@link ManifestReader} for a {@link ManifestFile}. | ||
| * | ||
| * @param manifest a {@link ManifestFile} | ||
| * @param io a {@link FileIO} | ||
| * @param specsById a Map from spec ID to partition spec | ||
| * @return a {@link ManifestReader} | ||
| */ | ||
| public static ManifestReader read(ManifestFile manifest, FileIO io, Map<Integer, PartitionSpec> specsById) { | ||
| InputFile file = io.newInputFile(manifest.path()); | ||
| InheritableMetadata inheritableMetadata = InheritableMetadataFactory.fromManifest(manifest); | ||
| return new ManifestReader(file, specsById, inheritableMetadata); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new {@link ManifestWriter}. | ||
| * <p> | ||
| * Manifests created by this writer have all entry snapshot IDs set to null. | ||
| * All entries will inherit the snapshot ID that will be assigned to the manifest on commit. | ||
| * | ||
| * @param spec {@link PartitionSpec} used to produce {@link DataFile} partition tuples | ||
| * @param outputFile the destination file location | ||
| * @return a manifest writer | ||
| */ | ||
| public static ManifestWriter write(PartitionSpec spec, OutputFile outputFile) { | ||
| // always use a v1 writer for appended manifests because sequence number must be inherited | ||
| return write(1, spec, outputFile, null); | ||
| } | ||
|
|
||
| /** | ||
| * Create a new {@link ManifestWriter} for the given format version. | ||
| * | ||
| * @param formatVersion a target format version | ||
| * @param spec a {@link PartitionSpec} | ||
| * @param outputFile an {@link OutputFile} where the manifest will be written | ||
| * @param snapshotId a snapshot ID for the manifest entries, or null for an inherited ID | ||
| * @return a manifest writer | ||
| */ | ||
| static ManifestWriter write(int formatVersion, PartitionSpec spec, OutputFile outputFile, Long snapshotId) { | ||
| switch (formatVersion) { | ||
| case 1: | ||
| return new ManifestWriter.V1Writer(spec, outputFile, snapshotId); | ||
| } | ||
| throw new UnsupportedOperationException("Cannot write manifest for table version: " + formatVersion); | ||
| } | ||
|
|
||
| static ManifestFile copyAppendManifest(int formatVersion, ManifestReader reader, OutputFile outputFile, | ||
| long snapshotId, SnapshotSummary.Builder summaryBuilder) { | ||
| return copyManifest( | ||
| formatVersion, reader, outputFile, snapshotId, summaryBuilder, Sets.newHashSet(ManifestEntry.Status.ADDED)); | ||
| } | ||
|
|
||
| static ManifestFile copyManifest(int formatVersion, ManifestReader reader, OutputFile outputFile, long snapshotId, | ||
| SnapshotSummary.Builder summaryBuilder, | ||
| Set<ManifestEntry.Status> allowedEntryStatuses) { | ||
| ManifestWriter writer = write(formatVersion, reader.spec(), outputFile, snapshotId); | ||
| boolean threw = true; | ||
| try { | ||
| for (ManifestEntry entry : reader.entries()) { | ||
| Preconditions.checkArgument( | ||
| allowedEntryStatuses.contains(entry.status()), | ||
| "Invalid manifest entry status: %s (allowed statuses: %s)", | ||
| entry.status(), allowedEntryStatuses); | ||
| switch (entry.status()) { | ||
| case ADDED: | ||
| summaryBuilder.addedFile(reader.spec(), entry.file()); | ||
| writer.add(entry); | ||
| break; | ||
| case EXISTING: | ||
| writer.existing(entry); | ||
| break; | ||
| case DELETED: | ||
| summaryBuilder.deletedFile(reader.spec(), entry.file()); | ||
| writer.delete(entry); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| threw = false; | ||
|
|
||
| } finally { | ||
| try { | ||
| writer.close(); | ||
| } catch (IOException e) { | ||
| if (!threw) { | ||
| throw new RuntimeIOException(e, "Failed to close manifest: %s", outputFile); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return writer.toManifestFile(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.