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

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

Closed
stuartcarnie opened this issue Feb 6, 2023 · 7 comments · Fixed by #5245
Closed

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

stuartcarnie opened this issue Feb 6, 2023 · 7 comments · Fixed by #5245
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@stuartcarnie
Copy link
Contributor

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

@stuartcarnie stuartcarnie added the enhancement New feature or request label Feb 6, 2023
@alamb alamb added the good first issue Good for newcomers label Feb 7, 2023
@stuartcarnie stuartcarnie 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$ Feb 9, 2023
@stuartcarnie stuartcarnie 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 Feb 9, 2023
@stuartcarnie stuartcarnie 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 Feb 9, 2023
@comphead
Copy link
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

@stuartcarnie
Copy link
Contributor Author

@comphead there are already examples in DF of this, for example the ltrim function takes 1 or 2 arguments:

https://github.com/apache/arrow-datafusion/blob/ac876dbc9729b16e272e00496c51e53d9f649173/datafusion/physical-expr/src/string_expressions.rs#L355-L369

@comphead
Copy link
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

@stuartcarnie
Copy link
Contributor Author

stuartcarnie commented Feb 10, 2023

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

@stuartcarnie
Copy link
Contributor Author

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

@comphead
Copy link
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

@stuartcarnie
Copy link
Contributor Author

@comphead awesome, thanks for doing that!

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

Successfully merging a pull request may close this issue.

3 participants