You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tinfoil-knight (via GitHub)" <gi...@apache.org> on 2024/03/29 19:50:35 UTC

[PR] move log2 [arrow-datafusion]

tinfoil-knight opened a new pull request, #9869:
URL: https://github.com/apache/arrow-datafusion/pull/9869

   ## 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 #9868.
   
   ## 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.  
   -->
   
   As part of #9285, `log10`, `log2` & `ln` functions should be migrated to the datafusion-functions crate.
   
   Sidenote:
   Didn't migrate `log` because some parts (eg: simplifying expressions: see `simpl_log`, `simpl_power`) of `log` & `power` functions are dependent on each other & IMO these should be migrated together.
   
   ## 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.
   -->
   
   Extend the `make_math_unary_udf` to accept a parameter for monotonicity & migrate log10, log2, ln from built-in functions to the `datafusion-functions` crate.
   
   ## 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)?
   -->
   
   Covered by existing tests.
   
   ## Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   No.
   
   <!--
   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


Re: [PR] move Log2, Log10, Ln to datafusion-functions [arrow-datafusion]

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


##########
datafusion/functions/src/math/mod.rs:
##########
@@ -24,10 +24,14 @@ mod nans;
 make_udf_function!(nans::IsNanFunc, ISNAN, isnan);
 make_udf_function!(abs::AbsFunc, ABS, abs);
 
-make_math_unary_udf!(TanhFunc, TANH, tanh, tanh);
-make_math_unary_udf!(AcosFunc, ACOS, acos, acos);
-make_math_unary_udf!(AsinFunc, ASIN, asin, asin);
-make_math_unary_udf!(TanFunc, TAN, tan, tan);
+make_math_unary_udf!(Log2Func, LOG2, log2, log2, Some(vec![Some(true)]));

Review Comment:
   @alamb 
   I tried this readability fix but Rust doesn't allow allocation (which `vec![]` needs) in `const` or `static` items. Global `let` is also not allowed.
   
   The compiler suggested this with static:
   ```
   consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell
   ```
   
   We use `once_cell` in the `physical_plan` crate but introducing it to datafusion functions just for this doesn't seem right to me.



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


Re: [PR] move Log2, Log10, Ln to datafusion-functions [arrow-datafusion]

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


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


Re: [PR] move Log2, Log10, Ln to datafusion-functions [arrow-datafusion]

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


##########
datafusion/functions/src/math/mod.rs:
##########
@@ -24,10 +24,14 @@ mod nans;
 make_udf_function!(nans::IsNanFunc, ISNAN, isnan);
 make_udf_function!(abs::AbsFunc, ABS, abs);
 
-make_math_unary_udf!(TanhFunc, TANH, tanh, tanh);
-make_math_unary_udf!(AcosFunc, ACOS, acos, acos);
-make_math_unary_udf!(AsinFunc, ASIN, asin, asin);
-make_math_unary_udf!(TanFunc, TAN, tan, tan);
+make_math_unary_udf!(Log2Func, LOG2, log2, log2, Some(vec![Some(true)]));

Review Comment:
   I wonder if we could make a constant or something that would make this easier to read
   
   For example
   ```rust
   /// Single monotonic argument
   const MONOTONIC_ONE: Option<Vec<bool>> = Some(vec![Some(true)])
   const NON_MONOTONIC: Option<Vec<bool>> = None;
   ```
   
   And then 
   
   ```suggestion
   make_math_unary_udf!(Log2Func, LOG2, log2, log2, MONOTONIC_ONE);
   ```
   
   Perhaps as a follow on PR



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


Re: [PR] move Log2, Log10, Ln to datafusion-functions [arrow-datafusion]

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

    > Note I think we can implement `simpl_log` using `ScalarUDFImpl::simplify`
    
    Yeah. I'll try this out.
   
   


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


Re: [PR] move Log2, Log10, Ln to datafusion-functions [arrow-datafusion]

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


##########
datafusion/functions/src/math/mod.rs:
##########
@@ -24,10 +24,14 @@ mod nans;
 make_udf_function!(nans::IsNanFunc, ISNAN, isnan);
 make_udf_function!(abs::AbsFunc, ABS, abs);
 
-make_math_unary_udf!(TanhFunc, TANH, tanh, tanh);
-make_math_unary_udf!(AcosFunc, ACOS, acos, acos);
-make_math_unary_udf!(AsinFunc, ASIN, asin, asin);
-make_math_unary_udf!(TanFunc, TAN, tan, tan);
+make_math_unary_udf!(Log2Func, LOG2, log2, log2, Some(vec![Some(true)]));

Review Comment:
   > We use `once_cell` in the `physical_plan` crate but introducing it to datafusion functions just for this doesn't seem right to me.
   
   That makes sense to me. We would probably have to throw in a `clone()` or something
   
   I thought about this and wrote up another API that would be much nicer https://github.com/apache/arrow-datafusion/issues/9879  (both for this callsite and montonicity in general)
   
   



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