You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2023/01/07 15:03:43 UTC

[GitHub] [arrow-datafusion] jonmmease opened a new issue, #4843: Match Postgres for stddev and variance on less than 3 values

jonmmease opened a new issue, #4843:
URL: https://github.com/apache/arrow-datafusion/issues/4843

   **Describe the bug**
   The behavior of the stddev and variance aggregation differs from Postgres for less than three values.  DataFusion crashes in these cases, whereas Postgres computes a variance for an array with two values and returns `NULL` for an array of one value.
   
   In DataFusion CLI:
   ```sql
   ❯  select stddev(sq.column1) from (values (1.0), (2.0), (3.0)) as sq;
   +--------------------+
   | STDDEV(sq.column1) |
   +--------------------+
   | 1                  |
   +--------------------+
   
   ❯  select stddev(sq.column1) from (values (1.0), (2.0)) as sq;
   ArrowError(ExternalError(Internal("At least two values are needed to calculate variance")))
   
   ❯  select stddev(sq.column1) from (values (1.0)) as sq;
   ArrowError(ExternalError(Internal("At least two values are needed to calculate variance")))
   ```
   
   In Postgres
   ```sql
   ❯  select stddev(sq.column1) from (values (1.0), (2.0), (3.0)) as sq;
   1
   
   ❯ select stddev(sq.column1) from (values (1.0), (2.0)) as sq;
   0.7071067811865475244
   
   ❯ select stddev(sq.column1) from (values (1.0)) as sq;
   NULL
   ```
   
   I would like to suggest DataFusion match the behavior of Postgres. Otherwise every usage of the variance function risks raising an error (depending on the distribution of the groupby column).
   
   **Additional context**
   Variance was first added by @realno in https://github.com/apache/arrow-datafusion/pull/1525.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] ozankabak commented on issue #4843: Match Postgres for stddev and variance on less than 3 values

Posted by GitBox <gi...@apache.org>.
ozankabak commented on issue #4843:
URL: https://github.com/apache/arrow-datafusion/issues/4843#issuecomment-1374595943

   We should definitely calculate something for the two-sample case -- erroring simply doesn't make sense in that case. The second example has various behaviors going around, see the discussion in [Snowflake docs](https://docs.snowflake.com/en/sql-reference/functions/stddev.html). I agree with your sentiment that we should align with Postgres.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb closed issue #4843: Match Postgres for stddev and variance on less than 3 values

Posted by GitBox <gi...@apache.org>.
alamb closed issue #4843: Match Postgres for stddev and variance on less than 3 values
URL: https://github.com/apache/arrow-datafusion/issues/4843


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org