-
Notifications
You must be signed in to change notification settings - Fork 186
Support mathematical functions: conv, crc32, mod, pow/power, round, sign, sqrt, truncate #577
Support mathematical functions: conv, crc32, mod, pow/power, round, sign, sqrt, truncate #577
Conversation
# Conflicts: # sql/src/main/antlr/OpenDistroSQLParser.g4
Could you check if we can avoid and fix this issue in new engine? #331 |
I think the description of this PR should be added to our doc. Could you add it and make this a doctest file: https://github.com/opendistro-for-elasticsearch/sql/blob/master/docs/user/dql/functions.rst |
...test/src/test/java/com/amazon/opendistroforelasticsearch/sql/sql/MathematicalFunctionIT.java
Show resolved
Hide resolved
...mazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java
Outdated
Show resolved
Hide resolved
...mazon/opendistroforelasticsearch/sql/expression/operator/arthmetic/MathematicalFunction.java
Show resolved
Hide resolved
MySQL returns |
Sounds good! I just tested |
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. Thanks for the changes!
Issue #, if available:
Description of changes:
conv
usage: conv(x, a, b) converts the number x from a base to b base
argument type: x: string, a: integer, b: integer
return type: string
crc32
usage: calculates a cyclic redundancy check value and returns a 32-bit unsigned value
argument type: string
return type: long
mod
usage: mod(n, m) calculates the remainder of the number n divided by m
argument type: integer/long/float/double
return type: widen type between types of n and m
pow/power
usage: pow(x, y) calculates the value of x raised to the power of y
argument type: integer/long/float/double
return type: double
round
usage: round(x, d) rounds the argument x to d decimal places, d defaults to 0 if not specified
argument type: integer/long/float/double
return type map:
(integer/long [,integer]) -> long
(float/double [,integer]) -> double
sign
usage: returns the sign of the argument as -1, 0, or 1, depending on whether the number is negative, zero, or positive
argument type: integer/long/float/double
return type: integer
sqrt
usage: calculate the square root of a nonnegative number
argument type: integer/long/float/double
return type map:
(nonnegative) integer/long/float/double -> double
(negative) integer/long/float/double -> null
truncate
usage: truncate(x, d) returns the number x, truncated to d decimal places
argument type: integer/long/float/double
return type map:
integer/long -> long
float/double -> double
Reference
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.