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

feat: add Logarithm, Exponential and Sqrt functions #3091

Merged
merged 3 commits into from
Jul 19, 2019

Conversation

big-andy-coates
Copy link
Contributor

Description

Add Log, Exp and SQRT UDFS.

As originally proposed in #2302 by @chappers

Co-authored-by: chappers [email protected]

Testing done

Added suitable unit and QTT

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

Copy link
Contributor

@rodesai rodesai left a 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.
Copy link
Contributor

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) {
Copy link
Contributor

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",
Copy link
Contributor

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.

Copy link
Member

@JimGalasyn JimGalasyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@agavra agavra left a 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. |
Copy link
Contributor

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 |

Copy link
Contributor Author

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");
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

@big-andy-coates big-andy-coates merged commit a4ca934 into confluentinc:master Jul 19, 2019
@big-andy-coates big-andy-coates deleted the log branch July 19, 2019 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants