You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/03/15 08:09:57 UTC

[GitHub] [spark] gengliangwang opened a new pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

gengliangwang opened a new pull request #31836:
URL: https://github.com/apache/spark/pull/31836


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   For the following cases, ABS should throw exceptions since the results are out of the range of the result data types in ANSI mode.
   ```
   SELECT abs(${Int.MinValue});
   SELECT abs(${Long.MinValue});
   ```
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Better ANSI compliance 
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   Yes, Abs throws an exception if input is out of range in ANSI mode
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Unit test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800079736


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40686/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800237945


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40696/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800236839


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136114/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799566252


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40655/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r595684119



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,39 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)
   extends UnaryExpression with ExpectsInputTypes with NullIntolerant {
 
+  def this(child: Expression) = this(child, SQLConf.get.ansiEnabled)
+
   override def inputTypes: Seq[AbstractDataType] = Seq(NumericType)
 
   override def dataType: DataType = child.dataType
 
-  private lazy val numeric = TypeUtils.getNumeric(dataType)
+  private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
 
   override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = dataType match {
     case _: DecimalType =>
       defineCodeGen(ctx, ev, c => s"$c.abs()")
+
+    case ByteType | ShortType if failOnError =>
+      val javaBoxedType = CodeGenerator.boxedType(dataType)
+      val javaType = CodeGenerator.javaType(dataType)
+      nullSafeCodeGen(ctx, ev, eval =>
+        s"""
+          |if ($eval == $javaBoxedType.MIN_VALUE) {
+          |  throw QueryExecutionErrors.unaryMinusCauseOverflowError($eval);
+          |} else if ($eval < 0) {
+          |  ${ev.value} = ($javaType)-$eval;

Review comment:
       You are right. Added test for this.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799525480


   **[Test build #136072 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136072/testReport)** for PR 31836 at commit [`3bc3b7e`](https://github.com/apache/spark/commit/3bc3b7ea412b5cd63ff8ba30bc3d80aac4086de0).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799270921






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799238784


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40639/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800237945


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40696/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799240054


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136056/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800776335


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136136/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799238784






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799612844


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136072/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800063620


   It is hard to make a decision in #31840. Let's focus on this one first.
   cc @cloud-fan @MaxGekk @maropu 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799499260


   Mark this as WIP until https://github.com/apache/spark/pull/31840 is merged.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800845750


   the scala 2.13 failure is unrelated, I'm merging it to master, thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA removed a comment on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799525480


   **[Test build #136072 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136072/testReport)** for PR 31836 at commit [`3bc3b7e`](https://github.com/apache/spark/commit/3bc3b7ea412b5cd63ff8ba30bc3d80aac4086de0).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800236839


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136114/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan closed pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
cloud-fan closed pull request #31836:
URL: https://github.com/apache/spark/pull/31836


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] MaxGekk commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
MaxGekk commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r594338622



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,52 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)
   extends UnaryExpression with ExpectsInputTypes with NullIntolerant {
 
+  def this(child: Expression) = this(child, SQLConf.get.ansiEnabled)
+
   override def inputTypes: Seq[AbstractDataType] = Seq(NumericType)
 
   override def dataType: DataType = child.dataType
 
-  private lazy val numeric = TypeUtils.getNumeric(dataType)
+  private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
 
   override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = dataType match {
     case _: DecimalType =>
       defineCodeGen(ctx, ev, c => s"$c.abs()")
+
+    case _: ByteType if failOnError =>
+      nullSafeCodeGen(ctx, ev, eval =>
+        s"""
+          |if ($eval == ${Byte.MinValue}) {
+          |  throw new ArithmeticException("byte overflow");
+          |} else if ($eval < 0) {
+          |  ${ev.value} = -$eval;
+          |} else {
+          |  ${ev.value} = $eval;
+          |}
+          |""".stripMargin)
+
+    case _: ShortType if failOnError =>
+      nullSafeCodeGen(ctx, ev, eval =>
+        s"""
+          |if ($eval == ${Short.MinValue}) {
+          |  throw new ArithmeticException("short overflow");
+          |} else if ($eval < 0) {
+          |  ${ev.value} = -$eval;
+          |} else {
+          |  ${ev.value} = $eval;
+          |}
+          |""".stripMargin)
+
+    case _: IntegerType if failOnError =>
+      defineCodeGen(ctx, ev, c => s"$c < 0 ? java.lang.Math.negateExact($c) : $c")
+
+    case _: LongType if failOnError =>
+      defineCodeGen(ctx, ev, c => s"$c < 0 ? java.lang.Math.negateExact($c) : $c")

Review comment:
       ```suggestion
       case IntegerType | LongType if failOnError =>
         defineCodeGen(ctx, ev, c => s"$c < 0 ? java.lang.Math.negateExact($c) : $c")
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799269614


   Kubernetes integration test status failure
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40643/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800776335






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] maropu commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r595716452



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,39 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)

Review comment:
       Does the interpreted code has the same behaviour?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799610254


   **[Test build #136072 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/136072/testReport)** for PR 31836 at commit [`3bc3b7e`](https://github.com/apache/spark/commit/3bc3b7ea412b5cd63ff8ba30bc3d80aac4086de0).
    * This patch **fails Spark unit tests**.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r594964447



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -249,7 +249,7 @@ object AnsiTypeCoercion extends TypeCoercionBase {
       case b @ BinaryOperator(left @ AtomicType(), right @ StringType()) if right.foldable =>
         b.makeCopy(Array(left, castExpr(right, left.dataType)))
 
-      case Abs(e @ StringType()) if e.foldable => Abs(Cast(e, DoubleType))
+      case Abs(e @ StringType(), _) if e.foldable => Abs(Cast(e, DoubleType))

Review comment:
       shall we propagate the `failOnError` flag to the newly created `Abs`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800078610


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136104/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] cloud-fan commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r594964608



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
##########
@@ -1081,7 +1081,7 @@ object TypeCoercion extends TypeCoercionBase {
         val commonType = findCommonTypeForBinaryComparison(left.dataType, right.dataType, conf).get
         p.makeCopy(Array(castExpr(left, commonType), castExpr(right, commonType)))
 
-      case Abs(e @ StringType()) => Abs(Cast(e, DoubleType))
+      case Abs(e @ StringType(), _) => Abs(Cast(e, DoubleType))

Review comment:
       ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800790037


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40718/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r595718397



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,39 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)

Review comment:
       Yes, it happens on `private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)`
   It will use exact version of `negate` eventually. 
   Otherwise, it won't pass unit tests.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] maropu commented on a change in pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
maropu commented on a change in pull request #31836:
URL: https://github.com/apache/spark/pull/31836#discussion_r595622827



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,39 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)
   extends UnaryExpression with ExpectsInputTypes with NullIntolerant {
 
+  def this(child: Expression) = this(child, SQLConf.get.ansiEnabled)
+
   override def inputTypes: Seq[AbstractDataType] = Seq(NumericType)
 
   override def dataType: DataType = child.dataType
 
-  private lazy val numeric = TypeUtils.getNumeric(dataType)
+  private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
 
   override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = dataType match {
     case _: DecimalType =>
       defineCodeGen(ctx, ev, c => s"$c.abs()")
+
+    case ByteType | ShortType if failOnError =>
+      val javaBoxedType = CodeGenerator.boxedType(dataType)
+      val javaType = CodeGenerator.javaType(dataType)
+      nullSafeCodeGen(ctx, ev, eval =>
+        s"""
+          |if ($eval == $javaBoxedType.MIN_VALUE) {
+          |  throw QueryExecutionErrors.unaryMinusCauseOverflowError($eval);
+          |} else if ($eval < 0) {
+          |  ${ev.value} = ($javaType)-$eval;

Review comment:
       No test for this code path?

##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
##########
@@ -145,18 +145,39 @@ case class UnaryPositive(child: Expression)
   """,
   since = "1.2.0",
   group = "math_funcs")
-case class Abs(child: Expression)
+case class Abs(child: Expression, failOnError: Boolean = SQLConf.get.ansiEnabled)
   extends UnaryExpression with ExpectsInputTypes with NullIntolerant {
 
+  def this(child: Expression) = this(child, SQLConf.get.ansiEnabled)
+
   override def inputTypes: Seq[AbstractDataType] = Seq(NumericType)
 
   override def dataType: DataType = child.dataType
 
-  private lazy val numeric = TypeUtils.getNumeric(dataType)
+  private lazy val numeric = TypeUtils.getNumeric(dataType, failOnError)
 
   override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = dataType match {
     case _: DecimalType =>
       defineCodeGen(ctx, ev, c => s"$c.abs()")
+
+    case ByteType | ShortType if failOnError =>
+      val javaBoxedType = CodeGenerator.boxedType(dataType)
+      val javaType = CodeGenerator.javaType(dataType)
+      nullSafeCodeGen(ctx, ev, eval =>
+        s"""
+          |if ($eval == $javaBoxedType.MIN_VALUE) {
+          |  throw QueryExecutionErrors.unaryMinusCauseOverflowError($eval);
+          |} else if ($eval < 0) {
+          |  ${ev.value} = ($javaType)-$eval;
+          |} else {
+          |  ${ev.value} = $eval;

Review comment:
       ditto




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins commented on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799612844


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/136072/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800078610






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] gengliangwang commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
gengliangwang commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-800383906


   The scala 2.13 test failure in https://github.com/apache/spark/pull/31836/checks?check_run_id=2121411366 seems unrelated.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] AmplabJenkins removed a comment on pull request #31836: [WIP][SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799566252


   
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder-K8s/40655/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] SparkQA commented on pull request #31836: [SPARK-34742][SQL] ANSI mode: Abs throws exception if input is out of range

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #31836:
URL: https://github.com/apache/spark/pull/31836#issuecomment-799265357


   Kubernetes integration test starting
   URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/40643/
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org