Skip to content

Commit

Permalink
Make functions pow and power aliases
Browse files Browse the repository at this point in the history
Currently pow() was the name of the method supported
and this commit added pow as an alias and renamed the
method as power which is consistent with ANSI.
  • Loading branch information
Akshat Nair authored and martint committed Aug 14, 2015
1 parent cc4ed2a commit 72bceb0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
6 changes: 5 additions & 1 deletion presto-docs/src/main/sphinx/functions/math.rst
Expand Up @@ -80,6 +80,10 @@ Mathematical Functions

.. function:: pow(x, p) -> double

This is an alias for :func:`power`.

.. function:: power(x, p) -> double

Returns ``x`` raised to the power of ``p``.

.. function:: radians(x) -> double
Expand All @@ -88,7 +92,7 @@ Mathematical Functions

.. function:: rand() -> double

Alias for ``random()``.
This is an alias for :func:`random()`.

.. function:: random() -> double

Expand Down
1 change: 1 addition & 0 deletions presto-docs/src/main/sphinx/release/release-0.115.rst
Expand Up @@ -7,6 +7,7 @@ General Changes

* Fix an issue with hierarchical queue rules where queries could be rejected after being accepted.
* Add :func:`sha1`, :func:`sha256` and :func:`sha512` functions.
* Add :func:`power` as an alias for :func:`pow`.

Hive Changes
------------
Expand Down
Expand Up @@ -218,9 +218,9 @@ public static double pi()
}

@Description("value raised to the power of exponent")
@ScalarFunction
@ScalarFunction(alias = "pow")
@SqlType(StandardTypes.DOUBLE)
public static double pow(@SqlType(StandardTypes.DOUBLE) double num, @SqlType(StandardTypes.DOUBLE) double exponent)
public static double power(@SqlType(StandardTypes.DOUBLE) double num, @SqlType(StandardTypes.DOUBLE) double exponent)
{
return Math.pow(num, exponent);
}
Expand Down
Expand Up @@ -285,34 +285,38 @@ public void testIsNaN()
}

@Test
public void testPow()
public void testPower()
{
for (long left : longLefts) {
for (long right : longRights) {
assertFunction("pow(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
assertFunction("power(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
}
}

for (long left : longLefts) {
for (double right : doubleRights) {
assertFunction("pow(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
assertFunction("power(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
}
}

for (double left : doubleLefts) {
for (long right : longRights) {
assertFunction("pow(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
assertFunction("power(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
}
}

for (double left : doubleLefts) {
for (double right : doubleRights) {
assertFunction("pow(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
assertFunction("power(" + left + ", " + right + ")", DOUBLE, Math.pow(left, right));
}
}
assertFunction("pow(NULL, NULL)", DOUBLE, null);
assertFunction("pow(5.0, NULL)", DOUBLE, null);
assertFunction("pow(NULL, 5.0)", DOUBLE, null);

assertFunction("power(NULL, NULL)", DOUBLE, null);
assertFunction("power(5.0, NULL)", DOUBLE, null);
assertFunction("power(NULL, 5.0)", DOUBLE, null);

// test alias
assertFunction("pow(5.0, 2.0)", DOUBLE, 25.0);
}

@Test
Expand Down

0 comments on commit 72bceb0

Please sign in to comment.