spark-test commented on code in PR #60284:
URL: https://github.com/apache/spark/pull/60284#discussion_r4531208064
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -186,6 +297,22 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
return None
}
+ // State eviction compares this cutoff in timestamp units against the
constrained column.
+ val hasTimestampStateAttribute = constraintTerm.exists {
+ case a: AttributeReference =>
+ attributesToFindStateWatermarkFor.contains(a) && a.dataType ==
TimestampType
+ case _ => false
+ }
+ if (!hasTimestampStateAttribute) return None
+
+ // A bound must advance with the opposite watermark. The occurrence check
above limits
+ // each input to one attribute, so there can be at most one opposite
watermark term.
+ val watermarkTerms =
terms.filter(_.references.exists(attributesWithEventWatermark.contains))
+ if (watermarkTerms.isEmpty ||
Review Comment:
Thanks for checking this. One update to my example first: since the
SPARK-61347 review fix (4000ae8f0c6) was merged into this branch after I posted
it, the query with a watermark only on `rt` and BIGINT casts fails analysis,
because a truncating cast now gives an unwatermarked `lt` no cutoff. With a
watermark on `lt` as well, it still evicts the 60 s row as described.
We still see a correctness problem here, and it comes from what the constant
did on the base branch. There, and in Spark 4.3.0, the constant's cutoff stayed
below every stored row, so these outer joins held back their unmatched rows but
returned every match. With the constant ignored, a cutoff the solver
over-estimates now decides eviction on its own, so a row is emitted with NULLs
while a later row that is not late can still match it. SPARK-61350 covers the
negative-term form, and SPARK-61347 drops inexact cutoffs only for a column
without its own watermark, so the truncating-cast and whole-day forms on a
column that has its own watermark stay exposed after the stack.
For example, take a left outer join with 0-second watermarks on both inputs
on `lk = rk AND CAST(lt AS BIGINT) >= CAST(rt AS BIGINT) + 5 AND CAST(lt AS
BIGINT) > 10`. A left row at 15.5 s is evicted at eviction watermark 10.9 s,
where the cutoff is 15.899 s, and is emitted with NULLs, but a right row at
10.95 s, which is not late, still matches it (15 >= 10 + 5).
Keeping the constant's cutoff in the minimum unless another conjunct gives
the same column an exact cutoff would keep this PR's fix for its target case,
where the range bound is exact.
<!-- SPARK_DEV_REVIEW_REPLY
{"feedback_id":"inline:4523590739","thread_id":"inline:4523590739","verdict_sha256":"0892dc5020677de484217540e5fbdb6c90ad67245e1329696952e91158ea8b30"}
-->
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -186,6 +297,22 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
return None
}
+ // State eviction compares this cutoff in timestamp units against the
constrained column.
+ val hasTimestampStateAttribute = constraintTerm.exists {
+ case a: AttributeReference =>
+ attributesToFindStateWatermarkFor.contains(a) && a.dataType ==
TimestampType
+ case _ => false
+ }
+ if (!hasTimestampStateAttribute) return None
+
+ // A bound must advance with the opposite watermark. The occurrence check
above limits
Review Comment:
Thanks, the comment now matches what the check does. We would still add a
one-line TODO at the check: at this commit a conjunct whose watermark term has
a negative coefficient passes it, and beside an advancing range bound it still
stops eviction once it becomes the minimum, which is the failure this PR fixes
for constants. Until #60286 lands, nothing in the code says that case is
deferred. A TODO naming negative watermark terms and SPARK-61350 is enough, and
#60286 can remove it.
<!-- SPARK_DEV_REVIEW_REPLY
{"feedback_id":"inline:4523590747","thread_id":"inline:4523590747","verdict_sha256":"0892dc5020677de484217540e5fbdb6c90ad67245e1329696952e91158ea8b30"}
-->
--
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]