-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-53784] Additional Source APIs needed to support RTM execution #52501
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
47 changes: 47 additions & 0 deletions
47
...yst/src/main/java/org/apache/spark/sql/connector/read/streaming/SupportsRealTimeMode.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,47 @@ | ||
| /* | ||
| * 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; | ||
| import org.apache.spark.sql.connector.read.InputPartition; | ||
|
|
||
| /** | ||
| * A {@link MicroBatchStream} for streaming queries with real time mode. | ||
| * | ||
| */ | ||
| @Evolving | ||
| public interface SupportsRealTimeMode { | ||
| /** | ||
| * Returns a list of {@link InputPartition input partitions} given the start offset. Each | ||
| * {@link InputPartition} represents a data split that can be processed by one Spark task. The | ||
| * number of input partitions returned here is the same as the number of RDD partitions | ||
| * this scan outputs. | ||
| */ | ||
| InputPartition[] planInputPartitions(Offset start); | ||
|
|
||
| /** | ||
| * Merge partitioned offsets coming from {@link SupportsRealTimeMode} instances | ||
| * for each partition to a single global offset. | ||
| */ | ||
| Offset mergeOffsets(PartitionOffset[] offsets); | ||
|
|
||
| /** | ||
| * Called during logical planning to inform the source if it's in real time mode | ||
| */ | ||
| default void prepareForRealTimeMode() {} | ||
| } | ||
86 changes: 86 additions & 0 deletions
86
...yst/src/main/java/org/apache/spark/sql/connector/read/streaming/SupportsRealTimeRead.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,86 @@ | ||
| /* | ||
| * 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 java.io.IOException; | ||
| import java.util.Optional; | ||
|
|
||
| import org.apache.spark.annotation.Evolving; | ||
| import org.apache.spark.sql.connector.read.PartitionReader; | ||
|
|
||
| /** | ||
| * A variation on {@link PartitionReader} for use with low latency streaming processing. | ||
| * | ||
| */ | ||
| @Evolving | ||
| public interface SupportsRealTimeRead<T> extends PartitionReader<T> { | ||
|
|
||
| /** | ||
| * A class to represent the status of a record to be read as the return type of nextWithTimeout. | ||
| * It contains whether the next record is available and the ingestion time of the record | ||
| * if the source connector provided relevant info. A list of source connector that has ingestion | ||
| * time is listed below: | ||
| * - Kafka when the record timestamp type is LogAppendTime | ||
| * - Kinesis has ApproximateArrivalTimestamp | ||
| */ | ||
| class RecordStatus { | ||
| private final boolean hasRecord; | ||
| private final Optional<Long> recArrivalTime; | ||
|
|
||
| private RecordStatus(boolean hasRecord, Optional<Long> recArrivalTime) { | ||
| this.hasRecord = hasRecord; | ||
| this.recArrivalTime = recArrivalTime; | ||
| } | ||
|
|
||
| // Public factory methods to control instance creation | ||
| public static RecordStatus newStatusWithoutArrivalTime(boolean hasRecord) { | ||
| return new RecordStatus(hasRecord, Optional.empty()); | ||
| } | ||
|
|
||
| public static RecordStatus newStatusWithArrivalTimeMs(Long recArrivalTime) { | ||
| return new RecordStatus(true, Optional.of(recArrivalTime)); | ||
| } | ||
|
|
||
| public boolean hasRecord() { | ||
| return hasRecord; | ||
| } | ||
|
|
||
| public Optional<Long> recArrivalTime() { | ||
| return recArrivalTime; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the offset of the next record, or the start offset if no records have been read. | ||
| * <p> | ||
| * The execution engine will call this method along with get() to keep track of the current | ||
| * offset. When a task ends, the offset in each partition will be passed back to the driver. | ||
| * They will be used as the start offsets of the next batch. | ||
| */ | ||
| PartitionOffset getOffset(); | ||
|
|
||
| /** | ||
| * Alternative function to be called than next(), that proceed to the next record. The different | ||
| * from next() is that, if there is no more records, the call needs to keep waiting until | ||
| * the timeout. | ||
| * @param timeout if no result is available after this timeout (milliseconds), return | ||
| * @return {@link RecordStatus} describing whether a record is available and its arrival time | ||
| * @throws IOException | ||
| */ | ||
| RecordStatus nextWithTimeout(Long timeout) throws IOException; | ||
| } |
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.
Is this used to compute the start offsets of the next batch?
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.
yes essentially. It is the function used to merge offsets returned by each partition at the end of batch which is the starting offset of the batch.