Uh oh!
There was an error while loading. Please reload this page.
[fix](regr) Use Youngs-Cramer for REGR_SLOPE/INTERCEPT to align with PG - #55940
Conversation
Thearas
commented
Sep 12, 2025
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
| -- !regr_intercept_int -- | ||
| 1000001.0 | ||
| -9.999E9 |
There was a problem hiding this comment.
According to
- https://docs.snowflake.com/en/sql-reference/functions/regr_intercept
- https://docs.snowflake.com/en/sql-reference/functions/regr_slope
REGR_INTERCEPT(y, x) =AVG(y) - REGR_SLOPE(y, x) *AVG(x)
REGR_SLOPE(y, x) = COVAR_POP(x, y) / VAR_POP(x)Verification
select regr_intercept(col_int, col_bigint) from d_table;PostgreSQL
selectavg(col_int) - regr_slope(col_int, col_bigint) *avg(col_bigint) from d_table;
+---------------+
| ?column? |
|---------------|
| -9999000000.0 |
+---------------+Clickhouse (stable covariance/variance)
SELECTavg(col_int) - ((covarPopStable(col_bigint, col_int) / varPopStable(col_bigint)) *avg(col_bigint))
FROM d_table
┌─minus(avg(co⋯l_bigint)))─┐
1. │ -9999000000 │ -- -10.00 billion
└──────────────────────────┘
| -- !regr_slope_int -- | ||
| -0.0 | ||
| 1.0 |
There was a problem hiding this comment.
Verification
PostgreSQL
select regr_slope(col_int, col_bigint) from d_table;
+------------+
| regr_slope |
|------------|
| 1.0 |
+------------+select covar_pop(col_bigint, col_int) / var_pop(col_bigint) from d_table;
+----------+
| ?column? |
|----------|
| 1.0 |
+----------+Clickhouse (stable covariance/variance)
SELECT covarPopStable(col_bigint, col_int) / varPopStable(col_bigint)
FROM d_table
┌─divide(covar⋯ol_bigint))─┐
1. │ 1 │
└──────────────────────────┘| -- !regr_slope_largeint -- | ||
| 17725.127617654194 | ||
| 0.0 |
There was a problem hiding this comment.
Verification
PostgreSQL
select regr_slope(col_largeint, col_float) from d_table;
+------------+
| regr_slope |
|------------|
| 0.0 |
+------------+select covar_pop(col_float, col_largeint) / var_pop(col_float) from d_table;
+----------+
| ?column? |
|----------|
| 0.0 |
+----------+Clickhouse (stable covariance/variance)
SELECT covarPopStable(col_float, col_largeint) / varPopStable(col_float)
FROM d_table
┌─divide(covar⋯col_float))─┐
1. │ 0 │
└──────────────────────────┘JoverZhang
commented
Sep 14, 2025
run buildall |
doris-robot
commented
Sep 14, 2025
TPC-H: Total hot run time: 34635 ms |
doris-robot
commented
Sep 14, 2025
TPC-DS: Total hot run time: 188040 ms |
doris-robot
commented
Sep 14, 2025
ClickBench: Total hot run time: 30.12 s |
hello-stephen
commented
Sep 14, 2025
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
hello-stephen
commented
Sep 14, 2025
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
zclllyybb
commented
Sep 15, 2025
Thanks for your contribution. we are busy in these few days. When I have time I will prioritize reviewing it. |
JoverZhang
commented
Sep 15, 2025
Got it, thanks! |
JoverZhang
commented
Dec 9, 2025
run buildall |
doris-robot
commented
Dec 9, 2025
TPC-DS: Total hot run time: 182964 ms |
doris-robot
commented
Dec 9, 2025
ClickBench: Total hot run time: 27.35 s |
doris-robot
commented
Dec 9, 2025
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
zclllyybb
commented
Dec 9, 2025
run buildall |
doris-robot
commented
Dec 9, 2025
TPC-H: Total hot run time: 36219 ms |
doris-robot
commented
Dec 9, 2025
TPC-DS: Total hot run time: 179217 ms |
doris-robot
commented
Dec 9, 2025
ClickBench: Total hot run time: 27.26 s |
doris-robot
commented
Dec 9, 2025
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
hello-stephen
commented
Dec 9, 2025
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
JoverZhang
commented
Dec 10, 2025
run buildall |
doris-robot
commented
Dec 10, 2025
TPC-H: Total hot run time: 35694 ms |
doris-robot
commented
Dec 10, 2025
TPC-DS: Total hot run time: 181004 ms |
doris-robot
commented
Dec 10, 2025
ClickBench: Total hot run time: 27.3 s |
doris-robot
commented
Dec 10, 2025
TPC-H: Total hot run time: 35067 ms |
doris-robot
commented
Dec 10, 2025
TPC-DS: Total hot run time: 181646 ms |
doris-robot
commented
Dec 10, 2025
ClickBench: Total hot run time: 27.47 s |
doris-robot
commented
Dec 10, 2025
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
JoverZhang
commented
Dec 10, 2025
I’m seeing a CI failure that seems related to an OSS download in the pipeline. Error snippet: I tried updating the branch several times, but the CI still fails with the same 404 error. It looks like the OSS object Any guidance would be appreciated. Thanks! |
PR approved by anyone and no changes requested. |
zclllyybb
commented
Dec 10, 2025
I will look into it. |
hello-stephen
commented
Dec 10, 2025
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
PR approved by at least one committer and no changes requested. |
Uh oh!
There was an error while loading. Please reload this page.
…PG (#55940) This PR reimplements `REGR_SLOPE` and `REGR_INTERCEPT` using the Youngs–Cramer algorithm to align with PostgreSQL. It also extends `AggregateFunctionRegrData<T>` so it can be reused by all `REGR_*` functions (`SXX`, `SYY`, `SXY`, `R2`, etc.). ```sql -- Copy from `regression-test/suites/query_p0/aggregate/support_type/regr_slope/regr_slope.groovy` -- dataset (PostgreSQL) drop table if exists d_table; create table d_table ( k1 int, k2 int not null, k3 bigint, col_tinyint smallint, col_smallint smallint, col_int int, col_bigint bigint, col_largeint numeric(38,0), col_float real, col_double double precision ); insert into d_table values (1, 1, 1, 100, 10000, 1000000, 10000000000, 100000000000000000000, 3.14, 2.718281828), (2, 2, 2, 101, 10001, 1000001, 10000000001, 100000000000000000001, 6.28, 3.141592653), (3, 3, 3, 102, 10002, 1000002, 10000000002, 100000000000000000002, 9.42, 1.618033988); select regr_slope(col_tinyint, col_smallint) from d_table; -- 1.0 select regr_slope(col_smallint, col_int) from d_table; -- 1.0 select regr_slope(col_int, col_bigint) from d_table; -- 1.0 select regr_slope(col_bigint, col_largeint) from d_table; -- <null> select regr_slope(col_largeint, col_float) from d_table; -- 0.0 select regr_slope(col_float, col_double) from d_table; -- -2.7928921351549283 select regr_slope(col_double, col_tinyint) from d_table; -- -0.5501239200000003 select regr_intercept(col_tinyint, col_smallint) from d_table; -- -9900.0 select regr_intercept(col_smallint, col_int) from d_table; -- -990000.0 select regr_intercept(col_int, col_bigint) from d_table; -- -9999000000.0 select regr_intercept(col_bigint, col_largeint) from d_table; -- <null> select regr_intercept(col_largeint, col_float) from d_table; -- 1e+20 select regr_intercept(col_float, col_double) from d_table; -- 13.241664047161668 select regr_intercept(col_double, col_tinyint) from d_table; -- 58.055152076333364 ```
…PG (#55940) This PR reimplements `REGR_SLOPE` and `REGR_INTERCEPT` using the Youngs–Cramer algorithm to align with PostgreSQL. It also extends `AggregateFunctionRegrData<T>` so it can be reused by all `REGR_*` functions (`SXX`, `SYY`, `SXY`, `R2`, etc.). ```sql -- Copy from `regression-test/suites/query_p0/aggregate/support_type/regr_slope/regr_slope.groovy` -- dataset (PostgreSQL) drop table if exists d_table; create table d_table ( k1 int, k2 int not null, k3 bigint, col_tinyint smallint, col_smallint smallint, col_int int, col_bigint bigint, col_largeint numeric(38,0), col_float real, col_double double precision ); insert into d_table values (1, 1, 1, 100, 10000, 1000000, 10000000000, 100000000000000000000, 3.14, 2.718281828), (2, 2, 2, 101, 10001, 1000001, 10000000001, 100000000000000000001, 6.28, 3.141592653), (3, 3, 3, 102, 10002, 1000002, 10000000002, 100000000000000000002, 9.42, 1.618033988); select regr_slope(col_tinyint, col_smallint) from d_table; -- 1.0 select regr_slope(col_smallint, col_int) from d_table; -- 1.0 select regr_slope(col_int, col_bigint) from d_table; -- 1.0 select regr_slope(col_bigint, col_largeint) from d_table; -- <null> select regr_slope(col_largeint, col_float) from d_table; -- 0.0 select regr_slope(col_float, col_double) from d_table; -- -2.7928921351549283 select regr_slope(col_double, col_tinyint) from d_table; -- -0.5501239200000003 select regr_intercept(col_tinyint, col_smallint) from d_table; -- -9900.0 select regr_intercept(col_smallint, col_int) from d_table; -- -990000.0 select regr_intercept(col_int, col_bigint) from d_table; -- -9999000000.0 select regr_intercept(col_bigint, col_largeint) from d_table; -- <null> select regr_intercept(col_largeint, col_float) from d_table; -- 1e+20 select regr_intercept(col_float, col_double) from d_table; -- 13.241664047161668 select regr_intercept(col_double, col_tinyint) from d_table; -- 58.055152076333364 ```
…PG (apache#55940) This PR reimplements `REGR_SLOPE` and `REGR_INTERCEPT` using the Youngs–Cramer algorithm to align with PostgreSQL. It also extends `AggregateFunctionRegrData<T>` so it can be reused by all `REGR_*` functions (`SXX`, `SYY`, `SXY`, `R2`, etc.). ```sql -- Copy from `regression-test/suites/query_p0/aggregate/support_type/regr_slope/regr_slope.groovy` -- dataset (PostgreSQL) drop table if exists d_table; create table d_table ( k1 int, k2 int not null, k3 bigint, col_tinyint smallint, col_smallint smallint, col_int int, col_bigint bigint, col_largeint numeric(38,0), col_float real, col_double double precision ); insert into d_table values (1, 1, 1, 100, 10000, 1000000, 10000000000, 100000000000000000000, 3.14, 2.718281828), (2, 2, 2, 101, 10001, 1000001, 10000000001, 100000000000000000001, 6.28, 3.141592653), (3, 3, 3, 102, 10002, 1000002, 10000000002, 100000000000000000002, 9.42, 1.618033988); select regr_slope(col_tinyint, col_smallint) from d_table; -- 1.0 select regr_slope(col_smallint, col_int) from d_table; -- 1.0 select regr_slope(col_int, col_bigint) from d_table; -- 1.0 select regr_slope(col_bigint, col_largeint) from d_table; -- <null> select regr_slope(col_largeint, col_float) from d_table; -- 0.0 select regr_slope(col_float, col_double) from d_table; -- -2.7928921351549283 select regr_slope(col_double, col_tinyint) from d_table; -- -0.5501239200000003 select regr_intercept(col_tinyint, col_smallint) from d_table; -- -9900.0 select regr_intercept(col_smallint, col_int) from d_table; -- -990000.0 select regr_intercept(col_int, col_bigint) from d_table; -- -9999000000.0 select regr_intercept(col_bigint, col_largeint) from d_table; -- <null> select regr_intercept(col_largeint, col_float) from d_table; -- 1e+20 select regr_intercept(col_float, col_double) from d_table; -- 13.241664047161668 select regr_intercept(col_double, col_tinyint) from d_table; -- 58.055152076333364 ```
…onRegrData (#59224) ### What problem does this PR solve? Issue Number: close#38977 Problem Summary: This PR migrates regr_sxx/syy/sxy onto the shared Moment(AggregateFunctionRegrData) introduced in #55940. The original implementation and tests were done in #39187 by @wyxxxcat. This PR builds on top of that work, refactoring it to reuse the same state and merge logic. --------- Co-authored-by: wyxxxcat <1520358997@qq.com>
…and REGR_R2 aggregate functions (#61352) Issue Number: #38974, #38976 Related PR: #55940 Problem Summary: This PR completes the remaining statistical regression aggregate functions (`REGR_*`) by adding support for `REGR_AVGX`, `REGR_AVGY`, `REGR_COUNT`, and `REGR_R2`, based on the unified Regr aggregate function approach introduced in #55940.
What problem does this PR solve?
Issue Number: #38975
Problem Summary:
This PR reimplements
REGR_SLOPEandREGR_INTERCEPTusing the Youngs–Cramer algorithm to align with PostgreSQL.It also extends
AggregateFunctionRegrData<T>so it can be reused by allREGR_*functions (SXX,SYY,SXY,R2, etc.).Next step:
Refactor
REGR_SXX/REGR_SYY/REGR_SXY/REGR_R2to reuse the sameAggregateFunctionRegrData<T>state(n, sx, sy, sxx, syy, sxy)and Youngs–Cramer merge. This ensures consistent numerics and associative merges across allREGR_*functions, and aligns results with PostgreSQL.regr_sxx = sxxregr_syy = syyregr_sxy = sxyregr_r2 = (sxy * sxy) / (sxx * syy)Release note
None
Check List (For Author)
Test
Behavior changed:
REGR_SLOPE/REGR_INTERCEPTnow follow PostgreSQL / SQL:2003 semantics:slope = sxy / sxx,intercept = (sy - sx * sxy/sxx) / n.Does this need documentation?
Check List (For Reviewer who merge this PR)