-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
[SPARK-13332][SQL] Decimal datatype support for SQL pow #11212
Conversation
Can one of the admins verify this patch? |
@adrian-wang could you help review? Much thanks! |
@@ -103,8 +103,7 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper { | |||
} | |||
} else { | |||
domain.foreach { case (v1, v2) => | |||
checkEvaluation(c(Literal(v1), Literal(v2)), f(v1 + 0.0, v2 + 0.0), EmptyRow) | |||
checkEvaluation(c(Literal(v2), Literal(v1)), f(v2 + 0.0, v1 + 0.0), EmptyRow) | |||
checkEvaluation(c(Literal(v1), Literal(v2)), f(v1, v2), EmptyRow) |
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.
keep the test of f(v2, v1)
@@ -351,6 +350,20 @@ class MathFunctionsSuite extends SparkFunSuite with ExpressionEvalHelper { | |||
} | |||
|
|||
test("pow") { | |||
testBinary(Pow, (d: Decimal, n: Byte) => d.pow(n), | |||
(-5 to 5).map(v => (Decimal(v * 1.0), v.toByte))) |
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 v.toDouble
is better
I think it'd be a lot simpler if we create a separate Pow for Decimal, and handle byte/short/etc to integer in type coercion, rather than in the PowDecimal class. |
OK, let me try this solution. |
@rxin I tried your suggestion like creating PowDecimal for Decimal specially like below:
But one concern is when "select pow(cast(2 as decimal(5,2)), 3)", how to make the "PowDecimal" node created? The current path will create "Pow" node anyway. So we think of maybe we can still put Decimal processing in "Pow", but byte/short/etc. to integer in type coercion, like below:
In HiveTypeCoercion:
How do you think of this way? |
Thanks for the pull request. I'm going through a list of pull requests to cut them down since the sheer number is breaking some of the tooling we have. Due to lack of activity on this pull request, I'm going to push a commit to close it. Feel free to reopen it or create a new one. We can also continue the discussion on the JIRA ticket. |
Decimal datatype support for SQL pow
https://issues.apache.org/jira/browse/SPARK-13332