-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Parquet Manifest - POC #13769
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
Draft
RussellSpitzer
wants to merge
11
commits into
apache:main
Choose a base branch
from
RussellSpitzer:ParquetManifestsPOC
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Parquet Manifest - POC #13769
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
fc326bf
WIP
RussellSpitzer e98f4f7
WIP - Fix Most Things
RussellSpitzer 711a8a4
Spotless
RussellSpitzer 8c1d8f3
Extract Snapshot Change Utility
RussellSpitzer d59212c
Fix more core tests
RussellSpitzer 2787286
MinorFix - Test Call
RussellSpitzer 62305ff
Fix Encryption of Parquet Manifests
RussellSpitzer 230e4fb
Just in case Encryption Handling
RussellSpitzer e3c1e20
Restore some old Methods, Change some Signatures
RussellSpitzer f864a59
Fix a few more test issues
RussellSpitzer bf8b60b
Cleanup of previous refactor
RussellSpitzer 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
Some comments aren't visible on the classic Files Changed page.
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
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
154 changes: 154 additions & 0 deletions
154
core/src/main/java/org/apache/iceberg/SnapshotChanges.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,154 @@ | ||
| /* | ||
| * 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.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.exceptions.RuntimeIOException; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Objects; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Iterables; | ||
|
|
||
| /** | ||
| * A utility class to work around the current Snapshot interface and load cahnges from V4 Manfiests | ||
| * - needs to be discussed and changed | ||
| */ | ||
| public class SnapshotChanges { | ||
|
|
||
| private final Snapshot snapshot; | ||
| private final FileIO io; | ||
| private final Map<Integer, PartitionSpec> specsById; | ||
|
|
||
| // Lazy Cache | ||
| private List<DataFile> addedDataFiles = null; | ||
| private List<DataFile> removedDataFiles = null; | ||
| private List<DeleteFile> addedDeleteFiles = null; | ||
| private List<DeleteFile> removedDeleteFiles = null; | ||
|
|
||
| private SnapshotChanges(Snapshot snapshot, FileIO io, Map<Integer, PartitionSpec> specsById) { | ||
| this.snapshot = snapshot; | ||
| this.io = io; | ||
| this.specsById = specsById; | ||
| } | ||
|
|
||
| public List<DataFile> addedDataFiles() { | ||
| if (addedDataFiles == null) { | ||
| cacheDataFileChanges(); | ||
| } | ||
| return addedDataFiles; | ||
| } | ||
|
|
||
| public List<DataFile> removedDataFiles() { | ||
| if (removedDataFiles == null) { | ||
| cacheDataFileChanges(); | ||
| } | ||
| return removedDataFiles; | ||
| } | ||
|
|
||
| public List<DeleteFile> addedDeleteFiles() { | ||
| if (addedDeleteFiles == null) { | ||
| cacheDeleteFileChanges(); | ||
| } | ||
| return addedDeleteFiles; | ||
| } | ||
|
|
||
| public List<DeleteFile> removedDeleteFiles() { | ||
| if (removedDeleteFiles == null) { | ||
| cacheDeleteFileChanges(); | ||
| } | ||
| return removedDeleteFiles; | ||
| } | ||
|
|
||
| private void cacheDataFileChanges() { | ||
| ImmutableList.Builder<DataFile> addedDataFileBuilder = ImmutableList.builder(); | ||
| ImmutableList.Builder<DataFile> removedDataFileBuilder = ImmutableList.builder(); | ||
|
|
||
| // read only manifests that were created by this snapshot | ||
| Iterable<ManifestFile> changedDataManifests = | ||
| Iterables.filter( | ||
| snapshot.dataManifests(io), | ||
| manifest -> Objects.equal(manifest.snapshotId(), snapshot.snapshotId())); | ||
| try (CloseableIterable<ManifestEntry<DataFile>> entries = | ||
| new ManifestGroup(io, changedDataManifests) | ||
| .specsById(specsById) | ||
| .ignoreExisting() | ||
| .entries()) { | ||
| for (ManifestEntry<DataFile> entry : entries) { | ||
| switch (entry.status()) { | ||
| case ADDED: | ||
| addedDataFileBuilder.add(entry.file().copy()); | ||
| break; | ||
| case DELETED: | ||
| removedDataFileBuilder.add(entry.file().copyWithoutStats()); | ||
| break; | ||
| default: | ||
| throw new IllegalStateException( | ||
| "Unexpected entry status, not added or deleted: " + entry); | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| throw new RuntimeIOException(e, "Failed to close entries while caching changes"); | ||
| } | ||
|
|
||
| this.addedDataFiles = addedDataFileBuilder.build(); | ||
| this.removedDataFiles = removedDataFileBuilder.build(); | ||
| } | ||
|
|
||
| private void cacheDeleteFileChanges() { | ||
| ImmutableList.Builder<DeleteFile> addedDeleteFilesBuilder = ImmutableList.builder(); | ||
| ImmutableList.Builder<DeleteFile> removedDeleteFilesBuilder = ImmutableList.builder(); | ||
|
|
||
| Iterable<ManifestFile> changedDeleteManifests = | ||
| Iterables.filter( | ||
| snapshot.deleteManifests(io), | ||
| manifest -> Objects.equal(manifest.snapshotId(), snapshot.snapshotId())); | ||
|
|
||
| for (ManifestFile manifest : changedDeleteManifests) { | ||
| try (ManifestReader<DeleteFile> reader = | ||
| ManifestFiles.readDeleteManifest(manifest, io, specsById)) { | ||
| for (ManifestEntry<DeleteFile> entry : reader.entries()) { | ||
| switch (entry.status()) { | ||
| case ADDED: | ||
| addedDeleteFilesBuilder.add(entry.file().copy()); | ||
| break; | ||
| case DELETED: | ||
| removedDeleteFilesBuilder.add(entry.file().copyWithoutStats()); | ||
| break; | ||
| default: | ||
| // ignore existing | ||
| } | ||
| } | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException("Failed to close manifest reader", e); | ||
| } | ||
| } | ||
|
|
||
| this.addedDeleteFiles = addedDeleteFilesBuilder.build(); | ||
| this.removedDeleteFiles = removedDeleteFilesBuilder.build(); | ||
| } | ||
|
|
||
| public static SnapshotChanges changesFrom( | ||
| Snapshot snapshot, FileIO io, Map<Integer, PartitionSpec> specsById) { | ||
| return new SnapshotChanges(snapshot, io, specsById); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks a backwards compatibility, previously an input file didn't actually have to have an avro suffix