Skip to content

Add SQL function overload LOG(base, x) for logarithm of x to base #5206

Closed

Description

@stuartcarnie

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

As a user, I would like to determine the logarithm of a value, $x$ to base $b$.

Describe the solution you'd like

Add an overload to the log function, which takes two arguments. Using PostgreSQL for inspiration per the documentation:

log ( b numeric, x numeric ) → numeric
Logarithm of $x$ to base $b$
log(2.0, 64.0) → 6.0000000000000000

Describe alternatives you've considered

DataFusion strives for PostgreSQL compatibility, so it makes sense to use the PostgreSQL solution.

Additional context

Activity

  1. changed the title [-]Add SQL function overload log(b,x) for logarithm of x to base b[/-] [+]Add SQL function overload `LOG(x, base)` for logarithm of $x$ to base $b$[/+] on Feb 9, 2023
  2. changed the title [-]Add SQL function overload `LOG(x, base)` for logarithm of $x$ to base $b$[/-] [+]Add SQL function overload `LOG(x, base)` for logarithm of x to base[/+] on Feb 9, 2023
  3. changed the title [-]Add SQL function overload `LOG(x, base)` for logarithm of x to base[/-] [+]Add SQL function overload `LOG(base, x)` for logarithm of x to base[/+] on Feb 9, 2023
  4. comphead commented on Feb 10, 2023

    @comphead
    Contributor

    @alamb on top of my head we dont have overloaded scalar functions yet?
    We know how to to create different aliases for the same function, but not overloading

  5. comphead commented on Feb 10, 2023

    @comphead
    Contributor

    Thanks @stuartcarnie with log I came out to the similar solution, inspecting len() :) but was wondering if we already have something more elegant to provide default values, seems we dont have it yet

  6. stuartcarnie commented on Feb 10, 2023

    @stuartcarnie
    ContributorAuthor

    In the case of the LOG function, if there is a single argument, it is assumed to be LOG $x$ base 10:

    log ( numeric ) → numeric
    log ( double precision ) → double precision
         Base 10 logarithm
         log(100) → 2
    
  7. stuartcarnie commented on Feb 10, 2023

    @stuartcarnie
    ContributorAuthor

    @comphead no worries – I looked for other solutions too, but that is all I could find for now.

  8. comphead commented on Feb 10, 2023

    @comphead
    Contributor

    Thats okay, I'll implement it using len() but going forward probably we may want to think how we can substitute default values, in case of different signatures for the same scalar function

  9. stuartcarnie commented on Feb 10, 2023

    @stuartcarnie
    ContributorAuthor

    @comphead awesome, thanks for doing that!

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