Skip to content

branch-4.1: [Fix](variance) Fix sample variance/stddev NaN res for single value#63605#63912

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-63605-branch-4.1
Jun 1, 2026
Merged

branch-4.1: [Fix](variance) Fix sample variance/stddev NaN res for single value#63605#63912
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-63605-branch-4.1

Conversation

@linrrzqqq

Copy link
Copy Markdown
Collaborator

cherry-pick: #63605

@linrrzqqq linrrzqqq requested a review from yiguolei as a code owner May 30, 2026 15:53
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@linrrzqqq linrrzqqq force-pushed the pick-63605-branch-4.1 branch from baa03c2 to c9e7af3 Compare June 1, 2026 04:10
…pache#63605)

Problem Summary:

Fix `VAR_SAMP`, `VARIANCE_SAMP`, and `STDDEV_SAMP` to return `NaN` when
the number of valid input values is less than or equal to 1. Sample
variance/stddev are undefined for `n <= 1`, so returning `0.0` is
misleading.

before:
```sql
CREATE TABLE t (id INT, v DOUBLE) DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES('replication_num'='1');
INSERT INTO t VALUES (1, 5.0);  -- 单行

SELECT VAR_SAMP(v), STDDEV_SAMP(v) FROM t;
+-------------+----------------+
| VAR_SAMP(v) | STDDEV_SAMP(v) |
+-------------+----------------+
|           0 |              0 |
+-------------+----------------+
```

now:
```sql
SELECT VAR_SAMP(v), STDDEV_SAMP(v) FROM t;
+-------------+----------------+
| VAR_SAMP(v) | STDDEV_SAMP(v) |
+-------------+----------------+
|         NaN |            NaN |
+-------------+----------------+
```

doc: apache/doris-website#3765
@linrrzqqq linrrzqqq force-pushed the pick-63605-branch-4.1 branch from c9e7af3 to f5335f0 Compare June 1, 2026 04:11
@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@yiguolei yiguolei merged commit 01bba92 into apache:branch-4.1 Jun 1, 2026
27 of 30 checks passed
@linrrzqqq linrrzqqq deleted the pick-63605-branch-4.1 branch June 1, 2026 09:31
yiguolei pushed a commit that referenced this pull request Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants