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