-
Notifications
You must be signed in to change notification settings - Fork 29.4k
[SPARK-59698][SQL][SS] Reject ASOF joins with streaming right side #58950
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
6 commits
Select commit
Hold shift + click to select a range
9708a92
[MINOR][SQL] Reject ASOF joins with streaming right side
HeartSaVioR 0e1fe75
[MINOR][SQL] Test stream-static ASOF joins
HeartSaVioR 4e5adba
[MINOR][SQL] Fix streaming ASOF test DataFrame conversion
HeartSaVioR 19ab660
[MINOR][SQL] Test unmatched stream-static ASOF rows
HeartSaVioR d9a200e
[SPARK-59698][SQL][SS] Address ASOF join review comments
HeartSaVioR 9755467
[SPARK-59698][SQL][SS] Document ASOF join streaming modes
HeartSaVioR 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
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
139 changes: 139 additions & 0 deletions
139
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingAsOfJoinSuite.scala
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,139 @@ | ||
| /* | ||
| * 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.streaming | ||
|
|
||
| import java.sql.Timestamp | ||
|
|
||
| import org.apache.spark.sql.{AnalysisException, Row} | ||
| import org.apache.spark.sql.execution.streaming.runtime.MemoryStream | ||
| import org.apache.spark.sql.internal.SQLConf | ||
|
|
||
| class StreamingAsOfJoinSuite extends StreamTest { | ||
|
|
||
| import testImplicits._ | ||
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
| spark.conf.set(SQLConf.SQL_ASOF_JOIN_ENABLED.key, "true") | ||
| } | ||
|
|
||
| override def afterAll(): Unit = { | ||
| spark.conf.unset(SQLConf.SQL_ASOF_JOIN_ENABLED.key) | ||
| super.afterAll() | ||
| } | ||
|
|
||
| private def timestamp(value: String): Timestamp = Timestamp.valueOf(value) | ||
|
|
||
| private def withTradeQuoteViews( | ||
| testCode: MemoryStream[(Timestamp, String, Int)] => Unit): Unit = { | ||
| withTempView("streaming_trades", "static_quotes") { | ||
| val input = MemoryStream[(Timestamp, String, Int)] | ||
| input.toDF().toDF("trade_time", "symbol", "quantity") | ||
| .createOrReplaceTempView("streaming_trades") | ||
| sql( | ||
| """ | ||
| |CREATE TEMP VIEW static_quotes(quote_time, symbol, bid_price) AS | ||
| |VALUES (TIMESTAMP '2026-06-29 10:00:00', 'AAPL', 18010), | ||
| | (TIMESTAMP '2026-06-29 10:00:07', 'AAPL', 18015), | ||
| | (TIMESTAMP '2026-06-29 10:00:08', 'MSFT', 42050) | ||
| |""".stripMargin) | ||
| testCode(input) | ||
| } | ||
| } | ||
|
|
||
| test("stream-static ASOF join matches against the static snapshot") { | ||
| withTradeQuoteViews { input => | ||
| val joined = sql( | ||
| """ | ||
| |SELECT t.trade_time, t.symbol, t.quantity, q.bid_price | ||
| |FROM streaming_trades t ASOF JOIN static_quotes q | ||
| | MATCH_CONDITION (t.trade_time >= q.quote_time) | ||
| | ON t.symbol = q.symbol | ||
| |""".stripMargin) | ||
|
|
||
| testStream(joined)( | ||
| AddData(input, | ||
| (timestamp("2026-06-29 10:00:05"), "AAPL", 100), | ||
| (timestamp("2026-06-29 10:00:09"), "MSFT", 50)), | ||
| CheckNewAnswer( | ||
| (timestamp("2026-06-29 10:00:05"), "AAPL", 100, 18010), | ||
| (timestamp("2026-06-29 10:00:09"), "MSFT", 50, 42050)), | ||
| AddData(input, (timestamp("2026-06-29 10:00:11"), "AAPL", 200)), | ||
| CheckNewAnswer((timestamp("2026-06-29 10:00:11"), "AAPL", 200, 18015))) | ||
| } | ||
| } | ||
|
|
||
| test("stream-static LEFT ASOF join preserves unmatched streaming rows") { | ||
| withTradeQuoteViews { input => | ||
| val joined = sql( | ||
| """ | ||
| |SELECT t.trade_time, t.symbol, t.quantity, q.bid_price | ||
| |FROM streaming_trades t LEFT ASOF JOIN static_quotes q | ||
| | MATCH_CONDITION (t.trade_time >= q.quote_time) | ||
| | ON t.symbol = q.symbol | ||
| |""".stripMargin) | ||
|
|
||
| testStream(joined)( | ||
| AddData(input, | ||
| (timestamp("2026-06-29 09:59:59"), "AAPL", 30), | ||
| (timestamp("2026-06-29 10:00:09"), "GOOG", 40), | ||
| (timestamp("2026-06-29 10:00:11"), "AAPL", 200)), | ||
| CheckNewAnswer( | ||
| Row(timestamp("2026-06-29 09:59:59"), "AAPL", 30, null), | ||
| Row(timestamp("2026-06-29 10:00:09"), "GOOG", 40, null), | ||
| Row(timestamp("2026-06-29 10:00:11"), "AAPL", 200, 18015))) | ||
| } | ||
| } | ||
|
|
||
| Seq("INNER", "LEFT").foreach { joinType => | ||
| Seq(false, true).foreach { isLeftStreaming => | ||
| val inputType = if (isLeftStreaming) "stream-stream" else "static-stream" | ||
|
|
||
| test(s"$inputType $joinType ASOF join is not supported") { | ||
| withTempView("trades", "quotes") { | ||
| val quotesInput = MemoryStream[(Timestamp, String, Int)] | ||
| quotesInput.toDF().toDF("quote_time", "symbol", "bid_price") | ||
| .createOrReplaceTempView("quotes") | ||
|
|
||
| if (isLeftStreaming) { | ||
| val tradesInput = MemoryStream[(Timestamp, String, Int)] | ||
| tradesInput.toDF().toDF("trade_time", "symbol", "quantity") | ||
| .createOrReplaceTempView("trades") | ||
| } else { | ||
| Seq((timestamp("2026-06-29 10:00:05"), "AAPL", 100)) | ||
| .toDF("trade_time", "symbol", "quantity") | ||
| .createOrReplaceTempView("trades") | ||
| } | ||
|
|
||
| val joined = sql( | ||
| s""" | ||
| |SELECT t.trade_time, t.symbol, t.quantity, q.bid_price | ||
| |FROM trades t $joinType ASOF JOIN quotes q | ||
| | MATCH_CONDITION (t.trade_time >= q.quote_time) | ||
| | ON t.symbol = q.symbol | ||
| |""".stripMargin) | ||
| val error = intercept[AnalysisException] { | ||
| joined.writeStream.format("noop").start() | ||
| } | ||
| assert(error.getMessage.contains( | ||
| "ASOF join with a streaming DataFrame/Dataset on the right is not supported")) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.
Could we also add a SQL-level rejection test in
StreamingAsOfJoinSuitefor static-stream and stream-stream ASOF joins, asserting thatwriteStream.start()fails with the expected message?These tests cover the checker directly, while the execution tests cover only the supported stream-static path. A SQL-level negative test would also protect the integration between SQL analysis and the streaming unsupported-operation check. This could be parameterized over INNER and LEFT ASOF.
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.
Will do. Though maybe I'd take a shortcut on using temp view rather than SDP to create a streaming table.
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.
Addressed in d9a200e. Added SQL-level
writeStream.start()rejection tests for INNER/LEFT across static-stream and stream-stream inputs, asserting the expected message.DISCLAIMER: This reply was posted by an LLM (OpenAI Codex).
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.
Thanks, this covers the SQL-to-streaming-check integration I had in mind. Using temporary views over the streaming inputs is sufficient; no need to introduce SDP for this test.