Commit d7c033f
authored
[Fix](variance) Fix sample variance/stddev NaN res for single value (#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#37651 parent 3c9c40f commit d7c033f
11 files changed
Lines changed: 988 additions & 1006 deletions
File tree
- be/src/exprs/aggregate
- regression-test
- data
- correctness_p0
- function_p0
- nereids_function_p0/agg_function
- nereids_rules_p0/normalize_window
- nereids_syntax_p0/mv/aggregate
- query_p0
- aggregate
- sql_functions/window_functions
- suites/query_p0/aggregate
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | | - | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | 29 | | |
32 | 30 | | |
33 | 31 | | |
| |||
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | | - | |
41 | | - | |
42 | 38 | | |
43 | 39 | | |
44 | 40 | | |
| |||
71 | 67 | | |
72 | 68 | | |
73 | 69 | | |
74 | | - | |
| 70 | + | |
75 | 71 | | |
76 | 72 | | |
77 | 73 | | |
| |||
125 | 121 | | |
126 | 122 | | |
127 | 123 | | |
128 | | - | |
129 | 124 | | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 125 | + | |
| 126 | + | |
136 | 127 | | |
137 | 128 | | |
138 | 129 | | |
| |||
144 | 135 | | |
145 | 136 | | |
146 | 137 | | |
147 | | - | |
148 | 138 | | |
149 | | - | |
| 139 | + | |
150 | 140 | | |
151 | | - | |
| 141 | + | |
152 | 142 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 143 | + | |
158 | 144 | | |
159 | 145 | | |
160 | 146 | | |
| |||
0 commit comments