HeartSaVioR commented on code in PR #60667:
URL: https://github.com/apache/spark/pull/60667#discussion_r4621514761
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinHelper.scala:
##########
@@ -262,27 +262,34 @@ object StreamingSymmetricHashJoinHelper extends Logging {
prevStateKeyWatermark)
}
} else if (isWatermarkDefinedOnInput) { // case 2 in the
StreamingSymmetricHashJoinExec docs
- val stateValueWatermark = StreamingJoinHelper.getStateValueWatermark(
- attributesToFindStateWatermarkFor =
AttributeSet(oneSideInputAttributes),
- attributesWithEventWatermark =
AttributeSet(otherSideInputAttributes),
- condition,
- eventTimeWatermarkForEviction)
- // A row can pass late-input filtering but already be eligible for
eviction in this batch.
- // When the previous join-derived state cutoff is ahead of the
late-input watermark, a new
- // row can fall at or below that cutoff. V4 must scan from the
beginning to find such rows.
- val prevStateValueWatermark = eventTimeWatermarkForLateEvents.flatMap
{ lateWatermark =>
- StreamingJoinHelper.getStateValueWatermark(
- attributesToFindStateWatermarkFor =
AttributeSet(oneSideInputAttributes),
- attributesWithEventWatermark =
AttributeSet(otherSideInputAttributes),
- condition,
- eventTimeWatermarkForLateEvents).filter(_ <= lateWatermark)
- }
- val inputAttributeWithWatermark =
oneSideInputAttributes.find(_.metadata.contains(delayKey))
- val expr = watermarkExpression(inputAttributeWithWatermark,
stateValueWatermark)
- expr.map { e =>
- // watermarkExpression only provides the expression when
eventTimeWatermarkForEviction
- // is defined
- JoinStateValueWatermarkPredicate(e, stateValueWatermark.get,
prevStateValueWatermark)
+ val eventTime =
oneSideInputAttributes.find(_.metadata.contains(delayKey))
+ // The legacy mode with a single global watermark keeps applying a
cutoff on any column of
+ // this input to the event time.
+ def solve(watermark: Option[Long]): Option[(Attribute, Long)] =
+ if (useFirstEventTimeColumn) {
+ StreamingJoinHelper.getStateValueWatermark(
+ attributesToFindStateWatermarkFor =
AttributeSet(oneSideInputAttributes),
+ attributesWithEventWatermark =
AttributeSet(otherSideInputAttributes),
+ condition,
+ watermark).map(eventTime.get -> _)
+ } else {
+
StreamingJoinHelper.getStateValueWatermarkColumn(oneSideInputAttributes,
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.
Reproduced: with `groupBy(window(leftTime, "1 minute")).count()` after this
join, master counts [60 s, 2], [360 s, 1], [960 s, 1], and this PR counts only
[960 s, 1]. The join's own rows are now right, but they arrive below its output
watermark, which still assumes eviction by the event time. Master's counts are
right here only by chance: one of the two rows at 60 s is a wrong early NULL
row. The output watermark is out of scope for this PR and tracked in
SPARK-62001. The migration guide now says that a stateful operator after such a
join can drop these rows.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -722,6 +744,16 @@ case class StreamingSymmetricHashJoinExec(
private[this] val allowMultipleStatefulOperators: Boolean =
conf.getConf(SQLConf.STATEFUL_OPERATOR_ALLOW_MULTIPLE)
+ // The join condition bounds the column that the value predicate tests, so
a row with a NULL
+ // in it can never match, and the predicate never evicts it. The legacy
mode tests the event
+ // time even when the condition bounds another column.
+ private[this] val isEvictionColumnNull: UnsafeRow => Boolean =
stateWatermarkPredicate match {
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 catch, reproduced on state formats 2 and 3 with a row stored in legacy
mode and a restart in the default mode: the row stayed in state and its outer
row was never emitted. Fixed: in the default mode, the eviction predicate also
evicts a stored row whose eviction column is NULL. State format 4 is not
affected, as its restart check or index handles these rows.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -708,20 +708,23 @@ object UnsupportedOperationChecker extends Logging {
private def checkForStreamStreamJoinWatermark(join: Join): Unit = {
val watermarkInJoinKeys = StreamingJoinHelper.isWatermarkInJoinKeys(join)
+ // Execution evicts the state of an input with its own watermark only by
the column that
+ // getStateValueWatermarkColumn picks, such as not by a DATE column cast
to TIMESTAMP.
+ def hasValidRange(input: LogicalPlan, other: LogicalPlan): Boolean =
+ if
(input.output.exists(_.metadata.contains(EventTimeWatermark.delayKey))) {
+ StreamingJoinHelper.getStateValueWatermarkColumn(
+ input.output, other.outputSet, join.condition,
Some(1000000)).isDefined
+ } else {
+ StreamingJoinHelper.getStateValueWatermark(
+ input.outputSet, other.outputSet, join.condition,
Some(1000000)).isDefined
+ }
+
// Check if the nullable side has a watermark, and there's a range
condition which
// implies a state value watermark on the first side.
val hasValidWatermarkRange = join.joinType match {
- case LeftOuter | LeftSemi => StreamingJoinHelper.getStateValueWatermark(
- join.left.outputSet, join.right.outputSet, join.condition,
Some(1000000)).isDefined
- case RightOuter => StreamingJoinHelper.getStateValueWatermark(
- join.right.outputSet, join.left.outputSet, join.condition,
Some(1000000)).isDefined
- case FullOuter =>
- Seq((join.left.outputSet, join.right.outputSet),
- (join.right.outputSet, join.left.outputSet)).exists {
- case (attributesToFindStateWatermarkFor,
attributesWithEventWatermark) =>
-
StreamingJoinHelper.getStateValueWatermark(attributesToFindStateWatermarkFor,
- attributesWithEventWatermark, join.condition,
Some(1000000)).isDefined
- }
+ case LeftOuter | LeftSemi => hasValidRange(join.left, join.right)
+ case RightOuter => hasValidRange(join.right, join.left)
+ case FullOuter => hasValidRange(join.left, join.right) ||
hasValidRange(join.right, join.left)
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.
Fixed differently: this PR no longer changes the eviction of an input
bounded only through a cast column, so such a full outer join evicts it and
emits its unmatched rows as master does. The new analysis rule is gone. Master
evicts such an input too early (by the event time, with the cutoff solved for
the cast column); that bug predates this PR and is now
[SPARK-62044](https://issues.apache.org/jira/browse/SPARK-62044), with a
reproducer.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -708,20 +708,23 @@ object UnsupportedOperationChecker extends Logging {
private def checkForStreamStreamJoinWatermark(join: Join): Unit = {
val watermarkInJoinKeys = StreamingJoinHelper.isWatermarkInJoinKeys(join)
+ // Execution evicts the state of an input with its own watermark only by
the column that
+ // getStateValueWatermarkColumn picks, such as not by a DATE column cast
to TIMESTAMP.
+ def hasValidRange(input: LogicalPlan, other: LogicalPlan): Boolean =
+ if
(input.output.exists(_.metadata.contains(EventTimeWatermark.delayKey))) {
+ StreamingJoinHelper.getStateValueWatermarkColumn(
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.
No longer applies: the checker change is reverted, so both the legacy mode
and the default mode keep master's check.
--
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]