Yaoxuan Wu created FLINK-41748:
----------------------------------
Summary: Streaming interval join drops matches for rowtimes before
1970-01-01 (negative epoch milliseconds)
Key: FLINK-41748
URL: https://issues.apache.org/jira/browse/FLINK-41748
Project: Flink
Issue Type: Bug
Components: Table SQL / Runtime
Affects Versions: 2.3.0
Reporter: Yaoxuan Wu
In streaming mode, an event-time interval join returns no joined row for rows
whose rowtime
is before the epoch: an inner join drops the pairs, an outer join emits both
rows padded
with NULLs. The same query in batch mode, and the same data shifted after
1970-01-01,
return the pairs.
Reproduction (two filesystem CSV tables with a watermark):
{code:sql}
CREATE TABLE L (k INT, ts TIMESTAMP(3), WATERMARK FOR ts AS ts - INTERVAL
'0.001' SECOND) WITH (...); -- (1, 1969-12-31 00:00:00.000)
CREATE TABLE R (k INT, ts TIMESTAMP(3), WATERMARK FOR ts AS ts - INTERVAL
'0.001' SECOND) WITH (...); -- (1, 1969-12-31 00:00:00.500)
SELECT L.k, L.ts, R.ts FROM L LEFT JOIN R ON L.k = R.k
AND R.ts BETWEEN L.ts - INTERVAL '1' SECOND AND L.ts + INTERVAL '1' SECOND;
{code}
Expected: (1, 1969-12-31 00:00:00, 1969-12-31 00:00:00.5) (batch mode returns
it, and
so does streaming mode for the same rows on 1970-01-02).
Actual (streaming): (1, 1969-12-31 00:00:00, NULL).
A TIMESTAMP(3) rowtime is the wall clock read as UTC, so this also hits rows
near the epoch
with a table.local-time-zone west of UTC, not only historical data.
Cause: RowTimeIntervalJoin#updateOperatorTime clamps the operator time at 0:
{code:java}
leftOperatorTime = ctx.timerService().currentWatermark() > 0
? ctx.timerService().currentWatermark() : 0L;
rightOperatorTime = leftOperatorTime;
{code}
In TimeIntervalJoin#processElement1/2 a row with time t is joined with the
cached rows of
the other input only if that input's expiration time (initially 0) is below t's
upper
bound, and is cached only if the other input's operator time (>= 0) is below
that bound.
For t + bound < 0 neither holds: the row is never joined, never cached, and an
outer row is
emitted padded immediately. Using the watermark itself (Long.MIN_VALUE
initially) instead
of max(watermark, 0), and initializing the expiration times accordingly, would
fix it.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)