Skip to content

Implement power function #1493

Closed
Closed

Description

@alamb

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

Activity

  1. matthewmturner commented on Dec 28, 2021

    @matthewmturner
    Contributor

    ill work on this

  2. matthewmturner commented on Dec 29, 2021

    @matthewmturner
    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?

  3. alamb commented on Dec 30, 2021

    @alamb
    ContributorAuthor

    @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

  4. matthewmturner commented on Dec 30, 2021

    @matthewmturner
    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.

  5. alamb commented on Dec 30, 2021

    @alamb
    ContributorAuthor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions