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

[SPARK-20931][SQL] ABS function support string type. #18153

Closed
wants to merge 5 commits into from
Closed

[SPARK-20931][SQL] ABS function support string type. #18153

wants to merge 5 commits into from

Conversation

wangyum
Copy link
Member

@wangyum wangyum commented May 31, 2017

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

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()))")
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

How about MySQL?

Copy link
Member Author

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?

Copy link
Member

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?

Copy link
Member

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.

@SparkQA
Copy link

SparkQA commented May 31, 2017

Test build #77571 has finished for PR 18153 at commit 209dbaf.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented May 31, 2017

Test build #77576 has started for PR 18153 at commit 1b70f29.

@wangyum
Copy link
Member Author

wangyum commented May 31, 2017

Jenkins, retest this please

@SparkQA
Copy link

SparkQA commented May 31, 2017

Test build #77583 has finished for PR 18153 at commit 1b70f29.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

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 =>
Copy link
Member

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?

@SparkQA
Copy link

SparkQA commented Jun 16, 2017

Test build #78170 has finished for PR 18153 at commit afdb40d.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

LGTM pending Jenkins.

@SparkQA
Copy link

SparkQA commented Jun 16, 2017

Test build #78182 has finished for PR 18153 at commit 8405784.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

Thanks! Merging to master.

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