HeartSaVioR commented on code in PR #60283:
URL: https://github.com/apache/spark/pull/60283#discussion_r4547003511
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -198,13 +477,80 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
}
}.reduceLeft(Add(_, _))
+ // Callers can pass only the constrained column and the opposite event
time, so a term on any
+ // other column passes the occurrence check above. Its value is unknown
here.
+ if (exprWithWatermarkSubstituted.references.nonEmpty) {
+ logDebug(s"Failed to extract state constraint: unresolved
$exprWithWatermarkSubstituted")
+ return None
+ }
+
// Calculate the constraint value
logInfo(log"Final expression to evaluate " +
log"constraint:\t${MDC(WATERMARK_CONSTRAINT,
exprWithWatermarkSubstituted)}")
val constraintValue =
exprWithWatermarkSubstituted.eval().asInstanceOf[java.lang.Double]
Some((Double2double(constraintValue) / 1000.0).toLong)
}
+ /** Whether a column of a join input can take a range cutoff: TIMESTAMP, or
a time window. */
+ def canTakeRangeCutoff(column: Attribute): Boolean =
+ column.dataType == TimestampType || windowDuration(column).isDefined
+
+ /** The length of the windows in a column built by window(), when the column
records it. */
+ private def windowDuration(column: Attribute): Option[Long] = {
+ val metadata = column.metadata
+ if (metadata.contains(TimeWindow.marker) &&
metadata.contains(TimeWindow.durationKey)) {
+ Some(metadata.getLong(TimeWindow.durationKey))
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, fixed in
[11638546d59](https://github.com/apache/spark/pull/60283/commits/11638546d5997f303277c62edcdf73bf67a4a34f).
A union's output column now keeps `spark.timeWindow.durationUs` only when
every child's column records the same length. The rule is
`TimeWindow.unionOutputMetadata`, and both `Union.mergeChildOutputs` and
`UnionExec.output` use it, so the analysis check and eviction read the same
metadata. All other metadata of the first child's column stays as it was. When
the lengths differ, or a child is a struct that records no length, the column
records no length, so a whole-window comparison gives no cutoff, as for any
window of unknown length. Unions of equal-length windows keep their cutoffs.
New tests:
- `DataFrameTimeWindowingSuite`: unions of 10-second and 20-second windows,
in either order, and of a window with a plain struct, have no length key in the
logical or the physical plan. A union of equal windows keeps it.
- `StreamingJoinNumericWatermarkSuite`: a left outer join bounded only by
`lw > rw` fails analysis when either input is such a union. Your inner-join
example, on state formats 2 to 4, still matches left window [0, 10) with the
later right window [-1, 19) after the watermark passes 15 seconds.
<!-- sp2k-review3 reply 4537867101 -->
--
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]