Skip to content

Conversation

@github-actions
Copy link
Contributor

Cherry-picked from #55940

…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
```
@github-actions github-actions bot requested a review from yiguolei as a code owner December 10, 2025 15:17
@hello-stephen
Copy link
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?

@dataroaring dataroaring reopened this Dec 10, 2025
@hello-stephen
Copy link
Contributor

run buildall

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 0.00% (0/140) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 53.16% (18350/34520)
Line Coverage 38.77% (168789/435411)
Region Coverage 33.55% (130580/389249)
Branch Coverage 34.45% (56314/163488)

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Dec 11, 2025
@github-actions
Copy link
Contributor Author

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor Author

PR approved by anyone and no changes requested.

@yiguolei yiguolei merged commit 1362c00 into branch-4.0 Dec 11, 2025
24 of 27 checks passed
@github-actions github-actions bot deleted the auto-pick-55940-branch-4.0 branch December 11, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants