You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "waynexia (via GitHub)" <gi...@apache.org> on 2023/09/28 07:22:05 UTC

[GitHub] [arrow-datafusion] waynexia opened a new pull request, #7682: minor: revert parsing precedence between Aggr and UDAF

waynexia opened a new pull request, #7682:
URL: https://github.com/apache/arrow-datafusion/pull/7682

   ## 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.
   -->
   
   Closes #.
   
   ## Rationale for this change
   
   <!--
    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.  
   -->
   
   Just came across these lines that UDF is parsed before scalar function:
   
   https://github.com/apache/arrow-datafusion/blob/bcc2acd8d10204b32b64fa3b77372655eaee8f06/datafusion/sql/src/expr/function.rs#L49-L61 
   
   And then find this rule doesn't hold for Aggr/UDAF
   
   ## What changes are included in this PR?
   
   <!--
   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.
   -->
   
   After this patch, UDAF can shadow builtin AggrFn if they have the same name. 
   
   ## Are these changes tested?
   
   <!--
   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)?
   -->
   
   n/a
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   It is... I think
   <!--
   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 #7682: minor: revert parsing precedence between Aggr and UDAF

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


-- 
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 #7682: minor: revert parsing precedence between Aggr and UDAF

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

   I agree it makes sense to allow UDAF to shadow built in aggregate functions (so that users can redefine the meaning of aggregates if they wanted)
   
   Is there any way we can add a test to document this behavior? Perhaps in https://github.com/apache/arrow-datafusion/blob/3f8c51222fa0aa5bb4ef7fa5cab55875bfde0a63/datafusion/core/tests/user_defined/user_defined_aggregates.rs 🤔 


-- 
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] waynexia commented on pull request #7682: minor: revert parsing precedence between Aggr and UDAF

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

   Thanks for reviewing!
   
   >Is there any way we can add a test to document this behavior
   
   Good suggestion 👍 I've added one in that file, reusing the existing `time_sum` to shadow the builtin `sum`, please take a look


-- 
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 #7682: minor: revert parsing precedence between Aggr and UDAF

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


##########
datafusion/core/tests/user_defined/user_defined_aggregates.rs:
##########
@@ -169,6 +169,37 @@ async fn test_udaf_returning_struct_subquery() {
     assert_batches_eq!(expected, &execute(&ctx, sql).await.unwrap());
 }
 
+#[tokio::test]
+async fn test_udaf_shadows_builtin_fn() {
+    let TestContext {
+        mut ctx,
+        test_state,
+    } = TestContext::new();
+    let sql = "SELECT sum(arrow_cast(time, 'Int64')) from t";
+
+    // compute with builtin `sum` aggregator
+    let expected = [
+        "+-------------+",
+        "| SUM(t.time) |",
+        "+-------------+",
+        "| 19000       |",
+        "+-------------+",
+    ];
+    assert_batches_eq!(expected, &execute(&ctx, sql).await.unwrap());
+
+    // Register `TimeSum` with name `sum`. This will shadow the builtin one

Review Comment:
   💯 



##########
datafusion/core/tests/user_defined/user_defined_aggregates.rs:
##########
@@ -169,6 +169,37 @@ async fn test_udaf_returning_struct_subquery() {
     assert_batches_eq!(expected, &execute(&ctx, sql).await.unwrap());
 }
 
+#[tokio::test]
+async fn test_udaf_shadows_builtin_fn() {
+    let TestContext {
+        mut ctx,
+        test_state,
+    } = TestContext::new();
+    let sql = "SELECT sum(arrow_cast(time, 'Int64')) from t";
+
+    // compute with builtin `sum` aggregator
+    let expected = [
+        "+-------------+",
+        "| SUM(t.time) |",
+        "+-------------+",
+        "| 19000       |",
+        "+-------------+",
+    ];
+    assert_batches_eq!(expected, &execute(&ctx, sql).await.unwrap());
+
+    // Register `TimeSum` with name `sum`. This will shadow the builtin one

Review Comment:
   💯 



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