HeartSaVioR commented on code in PR #60713:
URL: https://github.com/apache/spark/pull/60713#discussion_r4661577368
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -156,6 +157,80 @@ object UnsupportedOperationChecker extends Logging {
}
}
+ /**
+ * Checks, in append mode, for an operator that drops late rows after a
stream-stream join that
+ * emits the rows of an input whose state has no cutoff, as
+ * [[checkStreamingQueryGlobalWatermarkLimit]] does for other operators. It
takes the optimized
+ * plan, whose join conditions eviction uses, with its CTE references
inlined: the optimizer
+ * keeps some CTE definitions, such as MATERIALIZED ones, whose joins would
be missed. A query
+ * from a checkpoint without `STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK`
only logs a warning.
+ */
+ def checkStreamStreamJoinOutputWatermark(plan: LogicalPlan, outputMode:
OutputMode): Unit = {
+ // A stream-stream join without an equality predicate fails in planning
with its own error.
+ val hasJoinWithoutEquality = plan.exists {
+ case j @ Join(l, r, _, _, _) => l.isStreaming && r.isStreaming &&
+ ExtractEquiJoinKeys.unapply(j).isEmpty
+ case _ => false
+ }
+ if (hasJoinWithoutEquality) {
+ return
+ }
+ 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)) {
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: the check returns before its first traversal outside append mode, with
the Update-mode TODO there, and `dropsLateRows` now matches the operator type
only.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/IncrementalExecution.scala:
##########
@@ -158,6 +159,12 @@ class IncrementalExecution(
// query started, which the plan must still apply to all the rows that it
reads, see
// StreamingV2ScanPushDown.
StreamingV2ScanPushDown.checkPushedFilters(sparkSession, optimized,
pushedFilterRewrites)
+ // Unlike the other unsupported operation checks, which run when the query
starts, this one
+ // runs once the confs of the checkpoint are restored, on the plan that
eviction derives from.
+ if (isFirstBatch &&
sparkSession.sessionState.conf.isUnsupportedOperationCheckEnabled) {
+ UnsupportedOperationChecker.checkStreamStreamJoinOutputWatermark(
+ InlineCTE(alwaysInline = true).apply(optimized), outputMode)
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: the optimizer already replaces every CTE reference, MATERIALIZED ones
included. Removed the InlineCTE call and fixed the scaladoc. The new
MATERIALIZED CTE test is checked through the repartition that the optimizer
plans for it, on the optimized plan as it is.
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingJoinOutputWatermarkSuite.scala:
##########
@@ -0,0 +1,254 @@
+/*
+ * 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.io.File
+import java.sql.Timestamp
+
+import org.apache.hadoop.fs.Path
+import org.apache.logging.log4j.Level
+
+import org.apache.spark.sql.{AnalysisException, DataFrame}
+import org.apache.spark.sql.execution.streaming.checkpointing.{OffsetMap,
OffsetSeq, OffsetSeqLog}
+import org.apache.spark.sql.execution.streaming.runtime.MemoryStream
+import org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider
+import org.apache.spark.sql.functions._
+import org.apache.spark.sql.internal.SQLConf
+
+/**
+ * A stateful operator after a stream-stream join whose state of an input has
no cutoff. The join
+ * forwards its input watermark, so the operator would drop the old rows that
the join emits.
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 with your wording.
--
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]