Hi Sepuri,

Thanks for reproducing this and explaining the cast behavior. I understand that 
the range-check issue is already tracked by FLINK-24420 and FLINK-24847, so I 
won't open a new ticket for this case. I'll cast the input to DOUBLE when I 
need the wider variance result.

Best regards,

Suweiwei
------
??????:                                                                         
                                               "dev"                            
                                                        
<[email protected]&gt;;
????????:&nbsp;2026??11??16??(??????) ????0:59
??????:&nbsp;"dev"<[email protected]&gt;;
????:&nbsp;"2024??????"<[email protected]&gt;;
????:&nbsp;Re: [BUG] VAR_SAMP(BIGINT) silently saturates at Long.MAX_VALUE in 
Flink 2.3.0



Hi Suweiwei,

I can reproduce this on 2.3.0 and on a recent master build. For a BIGINT
input, VAR_SAMP returns BIGINT, like AVG does. The variance is computed as
DOUBLE and then cast to BIGINT, and that cast does not check the range.
CAST(d AS BIGINT) on a DOUBLE column holding 1.25E19 gives the same
9223372036854775807.

Range checks for such casts are already tracked in FLINK-24420 and
FLINK-24847, so I don't think a new bug ticket is needed. Casting to DOUBLE
first, as in your second column, gives the right value.

Best,
Sepuri Sai Krishna

On Sun, Nov 15, 2026 at 7:49?6?2PM 2024???????????? via dev 
<[email protected]&gt;
wrote:

&gt; Hi Flink developers,
&gt;
&gt; I found a reproducible correctness issue with VAR_SAMP on BIGINT values in
&gt; Apache Flink 2.3.0.
&gt;
&gt; Environment:
&gt;
&gt;
&gt; Apache Flink 2.3.0
&gt;
&gt;
&gt;
&gt; Official Docker image: flink:2.3.0-scala_2.12-java17
&gt;
&gt;
&gt;
&gt; Batch runtime mode
&gt;
&gt;
&gt;
&gt; Local execution with parallelism 1
&gt;
&gt;
&gt; Minimal reproducer:
&gt;
&gt; SET 'execution.runtime-mode' = 'batch';
&gt;
&gt; SELECT VAR_SAMP(x) AS variance_bigint,
&gt; VAR_SAMP(CAST(x AS DOUBLE)) AS variance_double
&gt; FROM (VALUES
&gt; (CAST(0 AS BIGINT)),
&gt; (CAST(5000000000 AS BIGINT))
&gt; ) AS t(x);
&gt;
&gt; Actual result:
&gt;
&gt; variance_bigint: 9223372036854775807
&gt; variance_double: 1.25E19
&gt;
&gt; The BIGINT result silently saturates at Long.MAX_VALUE. The exact sample
&gt; variance is 1.25E19, which exceeds the BIGINT range. I would expect either
&gt; a wider result type or an explicit overflow error instead of a silently
&gt; incorrect value.
&gt;
&gt; I searched the existing Flink Jira issues but did not find an exact
&gt; duplicate. My Apache Jira account request is still pending, so I am
&gt; discussing the issue here first as recommended.
&gt;
&gt; Could you please confirm whether this should be reported as a new Jira
&gt; issue? If appropriate, I can create the issue once my Jira account is
&gt; approved.
&gt;
&gt; Best regards,
&gt; Suweiwei

Reply via email to