Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add STD alias to stddevPop function for MySQL compatibility #54382

Merged
merged 2 commits into from Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,6 +7,10 @@ sidebar_position: 30

The result is equal to the square root of [varPop](../../../sql-reference/aggregate-functions/reference/varpop.md).

:::note
Alias:
- `STD`
- `STDDEV_POP`

:::note
This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `stddevPopStable` function. It works slower but provides a lower computational error.
:::
Expand Up @@ -7,6 +7,8 @@ sidebar_position: 31

The result is equal to the square root of [varSamp](../../../sql-reference/aggregate-functions/reference/varsamp.md).

:::note
Alias: `STDDEV_SAMP`.

:::note
This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `stddevSampStable` function. It works slower but provides a lower computational error.
:::
Expand Up @@ -9,6 +9,8 @@ Calculates the amount `Σ((x - x̅)^2) / n`, where `n` is the sample size and `x

In other words, dispersion for a set of values. Returns `Float64`.

:::note
Alias: `VAR_POP`.

:::note
This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `varPopStable` function. It works slower but provides a lower computational error.
:::
Expand Up @@ -11,6 +11,8 @@ It represents an unbiased estimate of the variance of a random variable if passe

Returns `Float64`. When `n <= 1`, returns `+∞`.

:::note
Alias: `VAR_SAMP`.

:::note
This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the `varSampStable` function. It works slower but provides a lower computational error.
:::
1 change: 1 addition & 0 deletions src/AggregateFunctions/AggregateFunctionSecondMoment.cpp
Expand Up @@ -19,6 +19,7 @@ void registerAggregateFunctionsStatisticsSecondMoment(AggregateFunctionFactory &
factory.registerAlias("VAR_POP", "varPop", AggregateFunctionFactory::CaseInsensitive);
factory.registerAlias("STDDEV_SAMP", "stddevSamp", AggregateFunctionFactory::CaseInsensitive);
factory.registerAlias("STDDEV_POP", "stddevPop", AggregateFunctionFactory::CaseInsensitive);
factory.registerAlias("STD", "stddevPop", AggregateFunctionFactory::CaseInsensitive);
}

}
2 changes: 2 additions & 0 deletions tests/queries/0_stateless/02833_std_alias.reference
@@ -0,0 +1,2 @@
6.408619196051518 5.848925577403085
6.408619196051518 5.848925577403085
8 changes: 8 additions & 0 deletions tests/queries/0_stateless/02833_std_alias.sql
@@ -0,0 +1,8 @@
DROP TABLE IF EXISTS series;
CREATE TABLE series(i UInt32, x Float64, y Float64) ENGINE = Memory;
INSERT INTO series(i, x, y) VALUES (1, 5.6,-4.4),(2, -9.6,3),(3, -1.3,-4),(4, 5.3,9.7),(5, 4.4,0.037),(6, -8.6,-7.8),(7, 5.1,9.3),(8, 7.9,-3.6),(9, -8.2,0.62),(10, -3,7.3);

SELECT std(x), std(y) FROM series;
SELECT stddevPop(x), stddevPop(y) FROM series;

DROP TABLE series;