HeartSaVioR commented on code in PR #60705:
URL: https://github.com/apache/spark/pull/60705#discussion_r4662100175
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -117,6 +117,35 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
allStateWatermarks.reduceOption((x, y) => Math.min(x, y))
}
+ /**
+ * Get the column that evicts the state of an input with its own watermark,
with its state value
+ * watermark. That is the event time if the condition bounds it, then the
first other TIMESTAMP
+ * column in input order that the condition bounds, and then the first cast
of another column
+ * to TIMESTAMP, such as a DATE column, that the condition bounds. Each
column is solved on its
+ * own, so the cutoff applies to the column that the condition bounds. A
cast is returned as it
+ * is in the condition, so eviction evaluates it with the same time zone.
+ */
+ def getStateValueWatermarkColumn(
+ inputAttributes: Seq[Attribute],
+ attributesWithEventWatermark: AttributeSet,
+ joinCondition: Option[Expression],
+ eventWatermark: Option[Long]): Option[(Expression, Long)] = {
+ val eventTime = inputAttributes.find(_.metadata.contains(delayKey))
+ val references =
joinCondition.map(_.references).getOrElse(AttributeSet.empty)
+ val candidates = eventTime.toSeq ++ inputAttributes.filter { a =>
+ a.dataType == TimestampType && !eventTime.exists(_.semanticEquals(a)) &&
+ references.contains(a)
+ }
+ val casts = joinCondition.toSeq.flatMap(_.collect {
+ case c @ Cast(a: Attribute, TimestampType, _, _)
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.
Right, and this PR caused it: once picked, the cast is evaluated on every
row by the NULL test, the eviction predicate and the state format 4 ordering. A
cast that can fail is now not picked: a cast to TIMESTAMP from STRING, FLOAT or
DOUBLE in ANSI mode (the only sources whose cast to TIMESTAMP can throw). Such
an input keeps master's eviction by its event time, and its cast is evaluated
only by the join condition, against rows of the other input with the same key.
New tests on state formats 2 and 4, ANSI on: a STRING column with 'n/a' and a
DOUBLE column with NaN, cast to TIMESTAMP, in a left outer join with no
matching right row; the query keeps running and emits the row unmatched once
its event time passes the cutoff, as master does. They fail before this change.
The column-pick test now checks that the same STRING cast is picked in LEGACY
mode and not in ANSI mode.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -156,6 +156,73 @@ object UnsupportedOperationChecker extends Logging {
}
}
+ /**
+ * Checks, in append mode, for an operator that drops late rows after a
stream-stream join whose
+ * state of an input has no cutoff, as
[[checkStreamingQueryGlobalWatermarkLimit]] does for other
+ * operators. It takes the optimized plan, whose join conditions eviction
uses. A query from a
+ * checkpoint without `STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK` only
logs a warning.
+ */
+ def checkStreamStreamJoinOutputWatermark(plan: LogicalPlan, outputMode:
OutputMode): Unit = {
+ val failWhenDetected = SQLConf.get.statefulOperatorCorrectnessCheckEnabled
&&
+
SQLConf.get.getConf(SQLConf.STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK)
+ try {
+ plan.foreach { subPlan =>
+ // TODO: Update mode is not checked, although its aggregations also
drop late rows.
+ if (outputMode == InternalOutputModes.Append &&
dropsLateRows(subPlan)) {
+ subPlan.foreach {
+ case j: Join if j ne subPlan =>
+ joinInputWithoutStateCutoff(j).foreach { side =>
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 in #60713: the check now traces the event-time column that the later
operator filters by down to the join, through projections, filters, watermarks
and the expansion of a sliding window, and rejects only when it can come from
an input without a cutoff, or when the path has any other node. So your
`leftKey = rightKey AND rightTime <= leftTime + INTERVAL 10 SECONDS` before a
window on `leftTime` runs.
#60713's round 5,
[e4ec72eccf8](https://github.com/apache/spark/pull/60713/commits/e4ec72eccf83367ee1a8d59de8182b7ed170e1ee),
fixes the two cases of the trace that were still open: an aggregation's trace
now starts from its grouping columns, so a window on one input's time that also
aggregates the other input's time runs, and the trace follows nodes that pass
their input's columns through unchanged, such as a repartition or a join with a
static table. This branch does not include that commit yet; if this review
raises those cases again, they are fixed in #60713.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/checkpointing/OffsetSeq.scala:
##########
@@ -273,9 +275,11 @@ object OffsetSeqMetadata extends Logging {
StreamingAggregationStateManager.legacyVersion.toString,
STREAMING_JOIN_STATE_FORMAT_VERSION.key ->
SymmetricHashJoinStateManager.legacyVersion.toString,
+ STREAMING_JOIN_STATE_V4_INDEX_VERSION.key -> "0",
STATE_STORE_COMPRESSION_CODEC.key -> CompressionCodec.LZ4,
STATEFUL_OPERATOR_USE_STRICT_DISTRIBUTION.key -> "false",
PRUNE_FILTERS_CAN_PRUNE_STREAMING_SUBPLAN.key -> "true",
+ STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK.key -> "false",
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 in #60667, which this PR is stacked on: a query restarted from a
checkpoint written before the check keeps the earlier eviction by the event
time for an input that would be evicted by another column or by a cast, so the
later operator receives what it received before the upgrade.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -117,6 +117,35 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
allStateWatermarks.reduceOption((x, y) => Math.min(x, y))
}
+ /**
+ * Get the column that evicts the state of an input with its own watermark,
with its state value
+ * watermark. That is the event time if the condition bounds it, then the
first other TIMESTAMP
+ * column in input order that the condition bounds, and then the first cast
of another column
+ * to TIMESTAMP, such as a DATE column, that the condition bounds. Each
column is solved on its
+ * own, so the cutoff applies to the column that the condition bounds. A
cast is returned as it
+ * is in the condition, so eviction evaluates it with the same time zone.
+ */
+ def getStateValueWatermarkColumn(
+ inputAttributes: Seq[Attribute],
+ attributesWithEventWatermark: AttributeSet,
+ joinCondition: Option[Expression],
+ eventWatermark: Option[Long]): Option[(Expression, Long)] = {
+ val eventTime = inputAttributes.find(_.metadata.contains(delayKey))
+ val references =
joinCondition.map(_.references).getOrElse(AttributeSet.empty)
+ val candidates = eventTime.toSeq ++ inputAttributes.filter { a =>
+ a.dataType == TimestampType && !eventTime.exists(_.semanticEquals(a)) &&
+ references.contains(a)
+ }
+ val casts = joinCondition.toSeq.flatMap(_.collect {
+ case c @ Cast(a: Attribute, TimestampType, _, _)
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.
Right that the pick covers only a cast of a column. A cast of arithmetic
over a column, such as `CAST(leftExpirySec + 3600 AS TIMESTAMP)`, keeps
master's eviction by the event time with the cutoff solved over the whole
input, so the query behaves as on master, not worse. I added a TODO at the
fallback that names it and left it to a follow-up: picking it means evicting by
a cast built from the column, with its own tests for each arithmetic shape,
which is more than this PR's fix for a cast of a column.
--
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]