spark-test commented on code in PR #60284:
URL: https://github.com/apache/spark/pull/60284#discussion_r4523590739
##########
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:
**Blocking (P1):** Dropping a constant-only cutoff from the minimum is safe
only when another remaining cutoff is exact. In an outer join, the constant
conjunct stays in the join condition on the preserved side and doubles as its
pre-join filter, so before this change its cutoff sat below every stored row
and nothing on that side was evicted. Reading the code, with that cap gone an
over-estimating cutoff now drives eviction on its own.
Example: a left outer join on `lk = rk AND CAST(lt AS BIGINT) > 100 -
CAST(rt AS BIGINT) AND CAST(lt AS BIGINT) > 10`, with a watermark only on `rt`.
The `-rt` term passes this check, so the left cutoff is 100 s minus the
watermark. A left row `(1, 60 s)` is evicted and emitted as `(1, 60, null)`
while the watermark is at most 40 s, and a later right row `(1, 50 s)`, which
is not late and satisfies `60 > 100 - 50`, never finds it. Before this change,
and in Spark 4.3.0, that row stayed in state and the join produced `(1, 60,
50)`.
The same holds for any left, right, or full outer join whose remaining
bounds for that side can over-estimate the cutoff, for example an integral cast
of the timestamps in a `>=` or `<=` bound (`CAST(ts AS BIGINT)` floors to whole
seconds) or a whole-day interval in a daylight-saving session time zone (Spark
adds days in that zone). SPARK-61350, as the stack listing describes it,
rejects only negative watermark terms, so the other forms stay exposed after it
lands.
See **Shared repair plan 1** in the review body.
##########
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:
**Nit (P3):** This check only requires some term to reference the opposite
input's watermarked event time; it does not look at that term's sign. For
`CAST(lt AS BIGINT) > 100 - CAST(rt AS BIGINT)` the `-rt` term passes and the
solver returns 100 s minus the watermark, which falls as the watermark rises,
so the guarantee this comment states does not hold. Beside an advancing range
bound such a term still stops eviction once it becomes the minimum, as on the
base branch. The PR description defers rejecting negative watermark terms to
SPARK-61350 (#60286), but a reader of this code has no way to see that the fix
is partial.
See **Shared repair plan 1** in the review body.
##########
docs/streaming/apis-on-dataframes-and-datasets.md:
##########
@@ -1435,6 +1444,11 @@ Additional details on supported joins:
- Joins can be cascaded, that is, you can do `df1.join(df2, ...).join(df3,
...).join(df4, ....)`.
+- For stream-stream outer and semi joins, the time constraint that finalizes
an input's rows must
+ bound a timestamp column of that input by the other input's event time,
through an equality key
+ or a range condition. A bound that uses only constants, such as `leftTime >
10`, or a numeric
Review Comment:
**Nit (P3):** `leftTime` here is the input's timestamp column, and Spark has
no implicit coercion between TIMESTAMP and an integer in a comparison, so
`leftTime > 10` fails analysis with `DATATYPE_MISMATCH.BINARY_OP_DIFF_TYPES`
before the watermark admission check runs. A reader who tries the example sees
a type error instead of the rejection this bullet describes. `CAST(leftTime AS
BIGINT) > 10`, the form `StreamingJoinConstantWatermarkSuite` uses, is still
constant-only and valid.
**Verification:**
- **Inspection:** The constant-only example in the join guide compares a
numeric cast of the timestamp column with a numeric constant, so it type-checks
for a TIMESTAMP column and still illustrates a bound that uses only constants.
--
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]