-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: add Logarithm, Exponential and Sqrt functions #3091
Conversation
Co-authored-by: chappers <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some stuff in-line I'll leave up to you
@@ -0,0 +1,63 @@ | |||
/* | |||
* Copyright 2018 Confluent Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: year
description = "the exponent to raise e to." | ||
) final Double exponent | ||
) { | ||
if (exponent == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: return exponent == null ? null : Math.exp(exponent);
import io.confluent.ksql.util.KsqlConstants; | ||
|
||
@UdfDescription( | ||
name = "log", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should name this function ln
and use log
for a function that accepts a base? I don't really have a strong preference though - different systems seem to do different things here. Postgres uses ln. Mysql uses both ln and log, and log w/ 1 parameter takes a natural log logarithm - so we're consistent with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - one question about exceptions
@@ -1581,6 +1583,8 @@ Scalar functions | |||
+------------------------+---------------------------------------------------------------------------+---------------------------------------------------+ | |||
| LEN | ``LEN(col1)`` | The length of a string. | | |||
+------------------------+---------------------------------------------------------------------------+---------------------------------------------------+ | |||
| LOG | ``LOG(col1)`` | The natural logarithm of a value. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have a too many spaces for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
|
||
final double result = Math.log(value); | ||
if (Double.isNaN(result)) { | ||
throw new KsqlFunctionException("Result was NaN"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why should these throw exceptions instead of leaving it up to the serialization format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed
Description
Add
Log
,Exp
andSQRT
UDFS.As originally proposed in #2302 by @chappers
Co-authored-by: chappers [email protected]
Testing done
Added suitable unit and QTT
Reviewer checklist