-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Spark 3.3: support rate limit in Spark Streaming #4479
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
jackye1995
merged 8 commits into
apache:master
from
singhpk234:feature/support-rate-limiting-ss
Apr 22, 2023
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e95957
Initial commit to support rate limit in SS
6ccdd99
spotless apply
362fd71
rebase changes
singhpk234 3b5e684
add justification to update Microbatch in rev-api
singhpk234 5a60aee
Address review feedback
f23cefd
Address review feedback
54cfc5d
remove left over code
a29f84c
Update existing function doc
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
123 changes: 123 additions & 0 deletions
123
core/src/main/java/org/apache/iceberg/MicroBatchesUtil.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,123 @@ | ||
| /* | ||
| * 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.stream.Collectors; | ||
| import org.apache.iceberg.io.CloseableIterable; | ||
| import org.apache.iceberg.io.FileIO; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.util.Pair; | ||
|
|
||
| public class MicroBatchesUtil { | ||
|
singhpk234 marked this conversation as resolved.
Outdated
|
||
|
|
||
| private MicroBatchesUtil() {} | ||
|
|
||
| public static List<Pair<ManifestFile, Integer>> skippedManifestIndexesFromSnapshot( | ||
| FileIO io, Snapshot snapshot, long startFileIndex, boolean scanAllFiles) { | ||
| // Preconditions.checkArgument(startFileIndex >= 0, "startFileIndex is unexpectedly smaller | ||
| // than 0"); | ||
| List<ManifestFile> manifests = | ||
| scanAllFiles | ||
| ? snapshot.dataManifests(io) | ||
| : snapshot.dataManifests(io).stream() | ||
| .filter(m -> m.snapshotId().equals(snapshot.snapshotId())) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| List<Pair<ManifestFile, Integer>> manifestIndexes = MicroBatchesUtil.indexManifests(manifests); | ||
|
|
||
| return MicroBatchesUtil.skipManifests(manifestIndexes, startFileIndex); | ||
| } | ||
|
|
||
| public static CloseableIterable<FileScanTask> openManifestFile( | ||
| FileIO io, | ||
| Map<Integer, PartitionSpec> specsById, | ||
| boolean caseSensitive, | ||
| Snapshot snapshot, | ||
| ManifestFile manifestFile, | ||
| boolean scanAllFiles) { | ||
|
|
||
| ManifestGroup manifestGroup = | ||
| new ManifestGroup(io, ImmutableList.of(manifestFile)) | ||
| .specsById(specsById) | ||
| .caseSensitive(caseSensitive); | ||
| if (!scanAllFiles) { | ||
| manifestGroup = | ||
| manifestGroup | ||
| .filterManifestEntries( | ||
| entry -> | ||
| entry.snapshotId() == snapshot.snapshotId() | ||
| && entry.status() == ManifestEntry.Status.ADDED) | ||
| .ignoreDeleted(); | ||
| } | ||
|
|
||
| return manifestGroup.planFiles(); | ||
| } | ||
|
|
||
| /** | ||
| * Method to index the data files for each manifest. For example, if manifest m1 has 3 data files, | ||
| * manifest m2 has 2 data files, manifest m3 has 1 data file, then the index will be (m1, 0), (m2, | ||
| * 3), (m3, 5). | ||
| * | ||
| * @param manifestFiles List of input manifests used to index. | ||
| * @return a list of manifest index with key as manifest file, value as file counts. | ||
| */ | ||
| private static List<Pair<ManifestFile, Integer>> indexManifests( | ||
| List<ManifestFile> manifestFiles) { | ||
| int currentFileIndex = 0; | ||
| List<Pair<ManifestFile, Integer>> manifestIndexes = Lists.newArrayList(); | ||
|
|
||
| for (ManifestFile manifest : manifestFiles) { | ||
| manifestIndexes.add(Pair.of(manifest, currentFileIndex)); | ||
| currentFileIndex += manifest.addedFilesCount() + manifest.existingFilesCount(); | ||
| } | ||
|
|
||
| return manifestIndexes; | ||
| } | ||
|
|
||
| /** | ||
| * Method to skip the manifest file in which the index is smaller than startFileIndex. For | ||
| * example, if the index list is : (m1, 0), (m2, 3), (m3, 5), and startFileIndex is 4, then the | ||
| * returned manifest index list is: (m2, 3), (m3, 5). | ||
| * | ||
| * @param indexedManifests List of input manifests. | ||
| * @param startFileIndex Index used to skip the processed manifests. | ||
| * @return a sub-list of manifest file index which only contains the manifest indexes larger than | ||
| * the startFileIndex. | ||
| */ | ||
| private static List<Pair<ManifestFile, Integer>> skipManifests( | ||
| List<Pair<ManifestFile, Integer>> indexedManifests, long startFileIndex) { | ||
| if (startFileIndex == 0) { | ||
| return indexedManifests; | ||
| } | ||
|
|
||
| int manifestIndex = 0; | ||
| for (Pair<ManifestFile, Integer> manifest : indexedManifests) { | ||
| if (manifest.second() > startFileIndex) { | ||
| break; | ||
| } | ||
|
|
||
| manifestIndex++; | ||
| } | ||
|
|
||
| return indexedManifests.subList(Math.max(manifestIndex - 1, 0), indexedManifests.size()); | ||
| } | ||
| } | ||
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.