You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "2010YOUY01 (via GitHub)" <gi...@apache.org> on 2023/08/06 00:45:45 UTC

[GitHub] [arrow-datafusion] 2010YOUY01 opened a new pull request, #7211: Add regr_*() aggregate functions

2010YOUY01 opened a new pull request, #7211:
URL: https://github.com/apache/arrow-datafusion/pull/7211

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   NA
   
   ## Rationale for this change
   
   A previous PR first implemented `regr_slope(y, x)` linear regression aggregate function https://github.com/apache/arrow-datafusion/pull/7135
   This PR wants to extend the previous one to implement all PostgreSQL's linear regression aggregate functions like `regr_intercept(y, x)`
   https://www.postgresql.org/docs/9.4/functions-aggregate.html
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   Extend `RegrAccumulator` to support other `regr_*(y, x)` aggregate functions
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   All end-to-end tests have the same result compared to PostgreSQL
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   No
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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 merged pull request #7211: Add linear regression aggregate functions

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7211:
URL: https://github.com/apache/arrow-datafusion/pull/7211


-- 
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 commented on a diff in pull request #7211: Add linear regression aggregate functions

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7211:
URL: https://github.com/apache/arrow-datafusion/pull/7211#discussion_r1287034286


##########
datafusion/physical-expr/src/aggregate/regr.rs:
##########
@@ -316,12 +415,42 @@ impl Accumulator for RegrSlopeAccumulator {
     fn evaluate(&self) -> Result<ScalarValue> {
         let cov_pop_x_y = self.algo_const / self.count as f64;
         let var_pop_x = self.m2_x / self.count as f64;
+        let var_pop_y = self.m2_y / self.count as f64;
+
+        let nullif_or_stat = |cond: bool, stat: f64| {
+            if cond {
+                Ok(ScalarValue::Float64(None))
+            } else {
+                Ok(ScalarValue::Float64(Some(stat)))
+            }
+        };
 
-        // Only 0/1 point or slope is infinite
-        if self.count <= 1 || var_pop_x == 0.0 {
-            Ok(ScalarValue::Float64(None))
-        } else {
-            Ok(ScalarValue::Float64(Some(cov_pop_x_y / var_pop_x)))
+        match self.regr_type {

Review Comment:
   Nice



-- 
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 commented on pull request #7211: Add linear regression aggregate functions

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7211:
URL: https://github.com/apache/arrow-datafusion/pull/7211#issuecomment-1668575689

   Thank you @2010YOUY01  -- this looks awesome. I plan to review it carefully tomorrow


-- 
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