Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement power function #1493

Closed
alamb opened this issue Dec 27, 2021 · 5 comments · Fixed by #2324
Closed

Implement power function #1493

alamb opened this issue Dec 27, 2021 · 5 comments · Fixed by #2324
Labels
datafusion Changes in the datafusion crate enhancement New feature or request good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented Dec 27, 2021

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
We would like to compute a power function (like 2**4 = 2 * 2 * 2 * 2) in datafusion

@matthewmturner asks for it here: #147 (comment)

Describe the solution you'd like

Implement the power function as described in https://www.postgresql.org/docs/14/functions-math.html

power ( a numeric, b numeric ) → numeric
power ( a double precision, b double precision ) → double precision

a raised to the power of b

power(9, 3) → 729

Describe alternatives you've considered
It may also be interesting to investigate adding support for a**b as another way to write the same thing

Additional context
This is probably a good ticket to learn about the datafusion codebase and its function implementations -- one could follow the example of one of the existing functions in

https://github.com/apache/arrow-datafusion/blob/master/datafusion/src/physical_plan/functions.rs

@alamb alamb added enhancement New feature or request good first issue Good for newcomers datafusion Changes in the datafusion crate labels Dec 27, 2021
@matthewmturner
Copy link
Contributor

ill work on this

@matthewmturner
Copy link
Contributor

ive started looking into this and i think it makes sense to add power / power_scalar compute kernels to arrow first then expose it in physical_plan/expressions/binary.rs and physical_plan/expressions/functions.rs

@alamb ok with that?

@alamb
Copy link
Contributor Author

alamb commented Dec 30, 2021

@matthewmturner I think power is more like a function rather than an operator -- so in that case I think you could just add power to BuiltinScalarFunction (and then fill in the implementation):

https://github.com/apache/arrow-datafusion/blob/5668be78a9ccbf5469e9e95ad070920ca5d105ba/datafusion/src/physical_plan/functions.rs

@matthewmturner
Copy link
Contributor

@alamb ok happy to do that.

but just to show you where i was coming from, i saw both C++ (https://arrow.apache.org/docs/cpp/compute.html#arithmetic-functions) and arrow2 (https://github.com/jorgecarleitao/arrow2/blob/main/src/compute/arithmetics/basic/pow.rs) had kernels for power. so i thought we would want to do something similar and not have datafusion implement something that could / should be done downstream.

@alamb
Copy link
Contributor Author

alamb commented Dec 30, 2021

@matthewmturner -- I don't have a strong preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants