-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Kernel][Refactor] Factor out some common utils to LogDataUtils #5295
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
5 commits
Select commit
Hold shift + click to select a range
8f4906f
Impl + tests
allisonport-db ffc9b3d
Merge remote-tracking branch 'delta-io/master' into log-data-utils
allisonport-db 8d2ffac
Update for master
allisonport-db f1c48c7
Update comments
allisonport-db e5ee731
Private constructor
allisonport-db 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
87 changes: 87 additions & 0 deletions
87
kernel/kernel-api/src/main/java/io/delta/kernel/internal/files/LogDataUtils.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,87 @@ | ||
| /* | ||
| * Copyright (2025) The Delta Lake Project Authors. | ||
| * | ||
| * Licensed 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 io.delta.kernel.internal.files; | ||
|
|
||
| import static io.delta.kernel.internal.util.Preconditions.checkArgument; | ||
|
|
||
| import io.delta.kernel.internal.lang.ListUtils; | ||
| import java.util.List; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public final class LogDataUtils { | ||
|
|
||
| private LogDataUtils() {} | ||
|
|
||
| public static void validateLogDataContainsOnlyRatifiedStagedCommits( | ||
| List<? extends ParsedLogData> logDatas) { | ||
| for (ParsedLogData logData : logDatas) { | ||
| checkArgument( | ||
| logData instanceof ParsedCatalogCommitData && logData.isFile(), | ||
| "Only staged ratified commits are supported, but found: " + logData); | ||
| } | ||
| } | ||
|
|
||
| public static void validateLogDataIsSortedContiguous(List<? extends ParsedLogData> logDatas) { | ||
| if (logDatas.size() > 1) { | ||
| for (int i = 1; i < logDatas.size(); i++) { | ||
| final ParsedLogData prev = logDatas.get(i - 1); | ||
| final ParsedLogData curr = logDatas.get(i); | ||
| checkArgument( | ||
| prev.getVersion() + 1 == curr.getVersion(), | ||
| String.format( | ||
| "Log data must be sorted and contiguous, but found: %s and %s", prev, curr)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Combines a list of published Deltas and ratified Deltas into a single list of Deltas such that | ||
| * there is exactly one {@link ParsedDeltaData} per version. When there is both a published Delta | ||
| * and a ratified staged Delta for the same version, prioritizes the ratified Delta. | ||
| * | ||
| * <p>The method requires but does not validate the following: | ||
| * | ||
| * <ul> | ||
| * <li>{@code publishedDeltas} are sorted and contiguous | ||
| * <li>{@code ratifiedDeltas} are sorted and contiguous | ||
| * <li>the commit versions present in {@code publishedDeltas} and {@code ratifiedDeltas}, when | ||
| * combined, reflect a contiguous version range. In other words, if the two do not overlap, | ||
| * publishedDeltas.last = ratifiedDeltas.first + 1). | ||
| * </ul> | ||
| */ | ||
| public static List<ParsedDeltaData> combinePublishedAndRatifiedDeltasWithCatalogPriority( | ||
| List<ParsedDeltaData> publishedDeltas, List<ParsedDeltaData> ratifiedDeltas) { | ||
| if (ratifiedDeltas.isEmpty()) { | ||
| return publishedDeltas; | ||
| } | ||
|
|
||
| if (publishedDeltas.isEmpty()) { | ||
| return ratifiedDeltas; | ||
| } | ||
|
|
||
| final long firstRatified = ratifiedDeltas.get(0).getVersion(); | ||
| final long lastRatified = ListUtils.getLast(ratifiedDeltas).getVersion(); | ||
|
|
||
| return Stream.of( | ||
| publishedDeltas.stream().filter(x -> x.getVersion() < firstRatified), | ||
| ratifiedDeltas.stream(), | ||
| publishedDeltas.stream().filter(x -> x.getVersion() > lastRatified)) | ||
| .flatMap(Function.identity()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| } | ||
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.
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.
nit: private constructor