-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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-20931][SQL] ABS function support string type. #18153
Conversation
case dt: DecimalType => | ||
defineCodeGen(ctx, ev, c => s"$c.abs()") | ||
case dt: NumericType => | ||
defineCodeGen(ctx, ev, c => s"(${ctx.javaType(dt)})(java.lang.Math.abs($c))") | ||
case dt: StringType => | ||
defineCodeGen(ctx, ev, c => s"java.lang.Math.abs(Double.valueOf($c.toString()))") |
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.
How should it work when a given string includes non-numerical character?
e.g. https://zohoreportsapi.wiki.zoho.com/MySQL-Math-Functions.html
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.
NumberFormatException
will throw, Hive does not support non-numerical character also.
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.
How about MySQL?
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.
MySQL support it, do we need to support this feature?
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 would like to hear @gatorsmile 's opinion. Which specification should Spark support?
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.
Thanks for ping me. To be consistent with the other mathematic expressions in Spark SQL, let us just convert it to Double.
Test build #77571 has finished for PR 18153 at commit
|
Test build #77576 has started for PR 18153 at commit |
Jenkins, retest this please |
Test build #77583 has finished for PR 18153 at commit
|
case dt: DecimalType => | ||
defineCodeGen(ctx, ev, c => s"$c.abs()") | ||
case dt: NumericType => | ||
defineCodeGen(ctx, ev, c => s"(${ctx.javaType(dt)})(java.lang.Math.abs($c))") | ||
case dt: StringType => |
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.
Could we move the type promotion to the rule PromoteStrings?
Test build #78170 has finished for PR 18153 at commit
|
LGTM pending Jenkins. |
Test build #78182 has finished for PR 18153 at commit
|
Thanks! Merging to master. |
What changes were proposed in this pull request?
ABS function support string type. Hive/MySQL support this feature.
Ref: https://github.com/apache/hive/blob/4ba713ccd85c3706d195aeef9476e6e6363f1c21/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFAbs.java#L93
How was this patch tested?
unit tests