HeartSaVioR commented on code in PR #60666:
URL: https://github.com/apache/spark/pull/60666#discussion_r4621770451
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -733,5 +734,55 @@ object UnsupportedOperationChecker extends Logging {
"is not supported without a watermark in the join keys, or a
watermark on " +
"the nullable side and an appropriate range condition")(join)
}
+
+ if
(SQLConf.get.getConf(SQLConf.STREAMING_JOIN_CHECK_WATERMARK_DIRECTION_ENABLED))
{
+ checkStreamStreamJoinWatermarkDirection(join)
+ }
+ }
+
+ /**
+ * When the join evicts an unmatched row of an input, an outer join outputs
it with NULLs and a
+ * left semi join drops it. Both are final only if later rows of the other
input cannot match
+ * the row. So the other input's watermark must bound this input's state,
through the
+ * equality key that eviction uses or through a range condition.
+ */
+ private def checkStreamStreamJoinWatermarkDirection(join: Join): Unit = {
+ val (leftKeys, rightKeys) = join match {
+ case ExtractEquiJoinKeys(_, leftKeys, rightKeys, _, _, _, _, _) =>
(leftKeys, rightKeys)
+ case _ => (Nil, Nil)
+ }
+ val keyOrdinal =
StreamingJoinHelper.findJoinKeyOrdinalForWatermark(leftKeys, rightKeys)
+
+ def checkInput(
+ stateSide: String,
+ state: LogicalPlan,
+ otherSide: String,
+ other: LogicalPlan,
+ otherKeys: Seq[Expression]): Unit = {
+ val boundedByKey = keyOrdinal.exists { ordinal =>
+ StreamingJoinHelper.isKeyBoundedByWatermark(otherKeys(ordinal),
other.outputSet)
+ }
+ lazy val boundedByRange = StreamingJoinHelper.getStateValueWatermark(
+ state.outputSet, other.outputSet, join.condition,
Some(1000000)).isDefined
+ if (!boundedByKey && !boundedByRange) {
+ val confKey =
SQLConf.STREAMING_JOIN_CHECK_WATERMARK_DIRECTION_ENABLED.key
+ throwError(
+ s"Stream-stream ${join.joinType} join between two streaming
DataFrame/Datasets " +
+ s"is not supported without a watermark on the $otherSide input
that bounds the " +
+ s"state of the $stateSide input, through an equality on the
$otherSide input's " +
+ "event-time column or a range condition. Otherwise, a later row of
the " +
+ s"$otherSide input can match a $stateSide row that the join
already evicted. To " +
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks, you're right. Without a watermarked key, the join never evicts that
input, so nothing is lost; its unmatched rows are just never output. The
message and the conf doc now give that reason for joins without a watermarked
key, and keep the old reason for keyed joins. The keyless full outer test row
checks the new wording.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -733,5 +734,55 @@ object UnsupportedOperationChecker extends Logging {
"is not supported without a watermark in the join keys, or a
watermark on " +
"the nullable side and an appropriate range condition")(join)
}
+
+ if
(SQLConf.get.getConf(SQLConf.STREAMING_JOIN_CHECK_WATERMARK_DIRECTION_ENABLED))
{
+ checkStreamStreamJoinWatermarkDirection(join)
+ }
+ }
+
+ /**
+ * When the join evicts an unmatched row of an input, an outer join outputs
it with NULLs and a
+ * left semi join drops it. Both are final only if later rows of the other
input cannot match
+ * the row. So the other input's watermark must bound this input's state,
through the
+ * equality key that eviction uses or through a range condition.
+ */
+ private def checkStreamStreamJoinWatermarkDirection(join: Join): Unit = {
+ val (leftKeys, rightKeys) = join match {
+ case ExtractEquiJoinKeys(_, leftKeys, rightKeys, _, _, _, _, _) =>
(leftKeys, rightKeys)
+ case _ => (Nil, Nil)
+ }
+ val keyOrdinal =
StreamingJoinHelper.findJoinKeyOrdinalForWatermark(leftKeys, rightKeys)
+
+ def checkInput(
+ stateSide: String,
+ state: LogicalPlan,
+ otherSide: String,
+ other: LogicalPlan,
+ otherKeys: Seq[Expression]): Unit = {
+ val boundedByKey = keyOrdinal.exists { ordinal =>
+ StreamingJoinHelper.isKeyBoundedByWatermark(otherKeys(ordinal),
other.outputSet)
+ }
+ lazy val boundedByRange = StreamingJoinHelper.getStateValueWatermark(
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Done. There is now a TODO at the range arm naming
[SPARK-62002](https://issues.apache.org/jira/browse/SPARK-62002) and
[SPARK-61989](https://issues.apache.org/jira/browse/SPARK-61989). It says that
a keyed join is still accepted when a range condition bounds the input,
although eviction uses the key.
##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,16 @@ Please refer [Migration Guide: SQL, Datasets and
DataFrame](../sql-migration-gui
## Upgrading from Structured Streaming 4.3 to 4.4
+- Since Spark 4.4, a stream-stream left outer, left semi, right outer or full
outer join fails
+ analysis unless the watermark of the other input bounds the state of each
input whose rows the
+ join outputs once, as the join support table of the programming guide
requires. For example,
+ a left outer join on `leftTime = rightTime` with a watermark only on
`leftTime` is rejected:
+ a later right row could match a left row that was already output with NULLs.
So is a key
+ shifted backward, such as `leftTime = rightTime - INTERVAL 10 SECONDS`, and
a key in a form
+ other than the event-time column shifted forward by constants, such as a UDF
of that column.
+ A full outer join needs watermarks on both inputs. To restore the earlier
check, set
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Good point, added. The note now says that existing queries with such joins
fail to restart, and that the conf must be set at each restart because the
checkpoint does not record it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]