Skip to content

Conversation

@beliefer
Copy link
Contributor

@beliefer beliefer commented May 28, 2022

What changes were proposed in this pull request?

REGR_INTERCEPT is an ANSI aggregate functions

Syntax: REGR_INTERCEPT(y, x)
Arguments:

  • y:The dependent variable. This must be an expression that can be evaluated to a numeric type.
  • x:The independent variable. This must be an expression that can be evaluated to a numeric type.

Examples:
select k, regr_intercept(v, v2) from aggr group by k;

k regr_intercept(v, v2)
1 [NULL]
2 1.154734411

The algorithm refers https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance

The mainstream database supports regr_intercept show below:
Teradata
https://docs.teradata.com/r/kmuOwjp1zEYg98JsB8fu_A/MpkZBV~MSTZ~I84I~ezxNg
Snowflake
https://docs.snowflake.com/en/sql-reference/functions/regr_intercept.html
Oracle
https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/REGR_-Linear-Regression-Functions.html#GUID-A675B68F-2A88-4843-BE2C-FCDE9C65F9A9
DB2
https://www.ibm.com/docs/en/db2/11.5?topic=af-regression-functions-regr-avgx-regr-avgy-regr-count
H2
http://www.h2database.com/html/functions-aggregate.html#regr_intercept
Postgresql
https://www.postgresql.org/docs/8.4/functions-aggregate.html
Sybase
https://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.sqlanywhere.12.0.0/dbreference/regr-intercept-function.html
Presto
https://prestodb.io/docs/current/functions/aggregate.html
Exasol
https://docs.exasol.com/sql_references/functions/alphabeticallistfunctions/regr_function.htm

Why are the changes needed?

REGR_INTERCEPT is very useful.

Does this PR introduce any user-facing change?

'No'. New feature.

How was this patch tested?

New tests.

@github-actions github-actions bot added the SQL label May 28, 2022
@beliefer
Copy link
Contributor Author

ping @MaxGekk cc @cloud-fan

@MaxGekk
Copy link
Member

MaxGekk commented Jun 3, 2022

+1, LGTM. Merging to master.
Thank you, @beliefer and @cloud-fan for review.

@MaxGekk MaxGekk closed this in 873ad55 Jun 3, 2022
@beliefer
Copy link
Contributor Author

beliefer commented Jun 4, 2022

@MaxGekk @cloud-fan Thank you for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants