Skip to content

Conversation

@kelvincesar
Copy link

This implementation computes the sample standard deviation, which is the same convention used by most SQL engines (e.g. PostgreSQL).

Description

  • Extends the percentile extension by adding a stddev aggregation;
  • Implements the stddev(expr) aggregate using Welford’s algorithm;
  • Adds extension tests for stddev in both grouped and ungrouped queries.

Motivation and context

Standard deviation is a common statistical measure that can be helpful in many use cases.

This resolves #1060.

* Implement stddev aggregate using Welford’s algorithm (stddev(expr));
* Add extension tests for stddev in grouped and ungrouped queries.
Copy link

@turso-bot turso-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review @pedrocarlo

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a stddev aggregate function to the percentile extension, implementing sample standard deviation using Welford's online algorithm. This is consistent with the convention used by most SQL engines like PostgreSQL.

  • Implements stddev(expr) aggregate function using Welford's algorithm for numerical stability
  • Adds comprehensive test coverage for both grouped and ungrouped queries
  • Returns NULL for datasets with fewer than 2 values (sample stddev requires at least 2 observations)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
extensions/percentile/src/lib.rs Implements the StandardDeviation aggregate function using Welford's algorithm, correctly computing sample standard deviation
testing/cli_tests/extensions.py Adds comprehensive test coverage for stddev including edge cases (single row, two rows) and grouped aggregates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standard deviation aggregate function

2 participants