forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-46641][SS] Add maxBytesPerTrigger threshold
### What changes were proposed in this pull request? This PR adds [Input Streaming Source's](https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#input-sources) option `maxBytesPerTrigger` for limiting the total size of input files in a streaming batch. Semantics of `maxBytesPerTrigger` is very close to already existing one `maxFilesPerTrigger` option. #### How a feature was implemented? Because `maxBytesPerTrigger` is semantically close to `maxFilesPerTrigger` I used all the `maxFilesPerTrigger` usages in the whole repository as a potential places that requires changes, that includes: - Option paramater definition - Option related logic - Option related ScalaDoc and MD files - Option related test I went over the usage of all usages of `maxFilesPerTrigger` in `FileStreamSourceSuite` and implemented `maxBytesPerTrigger` in the same fashion as those two are pretty close in their nature. From the structure and elements of ReadLimit I've concluded that current design implies only one simple rule for ReadLimit, so I openly prohibited the setting of both maxFilesPerTrigger and maxBytesPerTrigger at the same time. ### Why are the changes needed? This feature is useful for our and our sister teams and we expect it will find a broad acceptance among Spark users. We have a use-case in a few of the Spark pipelines we support when we use Available-now trigger for periodic processing using Spark Streaming. We use `maxFilesPerTrigger` threshold for now, but this is not ideal as Input file size might change with the time which requires periodic configuration adjustment of `maxFilesPerTrigger`. Computational complexity of the job depends on the event count/total size of the input and `maxBytesPerTrigger` is a better predictor of that than `maxFilesPerTrigger`. ### Does this PR introduce _any_ user-facing change? Yes ### How was this patch tested? New unit tests were added or existing `maxFilesPerTrigger` test were extended. I searched `maxFilesPerTrigger` related test and added new tests or extended existing ones trying to minimize and simplify the changes. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#44636 from MaxNevermind/streaming-add-maxBytesPerTrigger-option. Lead-authored-by: maxim_konstantinov <[email protected]> Co-authored-by: Max Konstantinov <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
- Loading branch information
1 parent
8603ed5
commit 3f5faaa
Showing
8 changed files
with
279 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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 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
56 changes: 56 additions & 0 deletions
56
sql/catalyst/src/main/java/org/apache/spark/sql/connector/read/streaming/ReadMaxBytes.java
This file contains 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,56 @@ | ||
/* | ||
* 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.spark.sql.connector.read.streaming; | ||
|
||
import org.apache.spark.annotation.Evolving; | ||
|
||
/** | ||
* Represents a {@link ReadLimit} where the {@link MicroBatchStream} should scan files which total | ||
* size doesn't go beyond a given maximum total size. Always reads at least one file so a stream | ||
* can make progress and not get stuck on a file larger than a given maximum. | ||
* | ||
* @see SupportsAdmissionControl#latestOffset(Offset, ReadLimit) | ||
* @since 4.0.0 | ||
*/ | ||
@Evolving | ||
public class ReadMaxBytes implements ReadLimit { | ||
private long bytes; | ||
|
||
ReadMaxBytes(long bytes) { | ||
this.bytes = bytes; | ||
} | ||
|
||
/** Maximum total size of files to scan. */ | ||
public long maxBytes() { return this.bytes; } | ||
|
||
@Override | ||
public String toString() { | ||
return "MaxBytes: " + maxBytes(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ReadMaxBytes other = (ReadMaxBytes) o; | ||
return other.maxBytes() == maxBytes(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { return Long.hashCode(bytes); } | ||
} |
This file contains 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 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.