You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ge...@apache.org on 2022/08/02 19:59:28 UTC
[spark] branch master updated: [SPARK-39917][SQL] Use different error classes for numeric/interval arithmetic overflow
This is an automated email from the ASF dual-hosted git repository.
gengliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/master by this push:
new 51e4c2cc55a [SPARK-39917][SQL] Use different error classes for numeric/interval arithmetic overflow
51e4c2cc55a is described below
commit 51e4c2cc55aa01f07b28b1cd807b553f8729075d
Author: Gengliang Wang <ge...@apache.org>
AuthorDate: Tue Aug 2 12:59:05 2022 -0700
[SPARK-39917][SQL] Use different error classes for numeric/interval arithmetic overflow
### What changes were proposed in this pull request?
Similar with https://github.com/apache/spark/pull/37313, currently, when arithmetic overflow errors happen under ANSI mode, the error messages are like
```
[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false"
```
The "(except for ANSI interval type)" part is confusing. We should remove it for the numeric arithmetic operations and have a new error class for the interval division error: `INTERVAL_ARITHMETIC_OVERFLOW`
### Why are the changes needed?
For better error messages
### Does this PR introduce _any_ user-facing change?
Yes, Use different error classes for arithmetic overflows of numeric/interval.. After changes, the error messages are simpler and more clear.
### How was this patch tested?
UT
Closes #37374 from gengliangwang/SPARK-39917.
Authored-by: Gengliang Wang <ge...@apache.org>
Signed-off-by: Gengliang Wang <ge...@apache.org>
---
core/src/main/resources/error/error-classes.json | 8 +++-
.../sql/catalyst/expressions/arithmetic.scala | 20 +++++-----
.../catalyst/expressions/intervalExpressions.scala | 3 +-
.../sql/catalyst/util/IntervalMathUtils.scala | 46 ++++++++++++++++++++++
.../spark/sql/errors/QueryExecutionErrors.scala | 14 +++++++
.../sql-tests/results/ansi/interval.sql.out | 14 +++----
.../resources/sql-tests/results/interval.sql.out | 14 +++----
.../sql-tests/results/postgreSQL/int4.sql.out | 12 +++---
.../sql-tests/results/postgreSQL/int8.sql.out | 8 ++--
.../results/postgreSQL/window_part2.sql.out | 4 +-
.../apache/spark/sql/DataFrameAggregateSuite.scala | 8 ++--
11 files changed, 110 insertions(+), 41 deletions(-)
diff --git a/core/src/main/resources/error/error-classes.json b/core/src/main/resources/error/error-classes.json
index c4b59799f88..ed6dd112e9f 100644
--- a/core/src/main/resources/error/error-classes.json
+++ b/core/src/main/resources/error/error-classes.json
@@ -7,7 +7,7 @@
},
"ARITHMETIC_OVERFLOW" : {
"message" : [
- "<message>.<alternative> If necessary set <config> to \"false\" (except for ANSI interval type) to bypass this error."
+ "<message>.<alternative> If necessary set <config> to \"false\" to bypass this error."
],
"sqlState" : "22003"
},
@@ -210,6 +210,12 @@
"<message>"
]
},
+ "INTERVAL_ARITHMETIC_OVERFLOW" : {
+ "message" : [
+ "<message>.<alternative>"
+ ],
+ "sqlState" : "22003"
+ },
"INTERVAL_DIVIDED_BY_ZERO" : {
"message" : [
"Division by zero. Use `try_divide` to tolerate divisor being 0 and return NULL instead."
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
index 86e6e6d7323..24ac685eace 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala
@@ -25,7 +25,7 @@ import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.trees.SQLQueryContext
import org.apache.spark.sql.catalyst.trees.TreePattern.{BINARY_ARITHMETIC, TreePattern, UNARY_POSITIVE}
-import org.apache.spark.sql.catalyst.util.{IntervalUtils, MathUtils, TypeUtils}
+import org.apache.spark.sql.catalyst.util.{IntervalMathUtils, IntervalUtils, MathUtils, TypeUtils}
import org.apache.spark.sql.errors.QueryExecutionErrors
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
@@ -89,7 +89,7 @@ case class UnaryMinus(
defineCodeGen(ctx, ev, c => s"$iu.$method($c)")
case _: AnsiIntervalType =>
nullSafeCodeGen(ctx, ev, eval => {
- val mathUtils = MathUtils.getClass.getCanonicalName.stripSuffix("$")
+ val mathUtils = IntervalMathUtils.getClass.getCanonicalName.stripSuffix("$")
s"${ev.value} = $mathUtils.negateExact($eval);"
})
}
@@ -98,8 +98,8 @@ case class UnaryMinus(
case CalendarIntervalType if failOnError =>
IntervalUtils.negateExact(input.asInstanceOf[CalendarInterval])
case CalendarIntervalType => IntervalUtils.negate(input.asInstanceOf[CalendarInterval])
- case _: DayTimeIntervalType => MathUtils.negateExact(input.asInstanceOf[Long])
- case _: YearMonthIntervalType => MathUtils.negateExact(input.asInstanceOf[Int])
+ case _: DayTimeIntervalType => IntervalMathUtils.negateExact(input.asInstanceOf[Long])
+ case _: YearMonthIntervalType => IntervalMathUtils.negateExact(input.asInstanceOf[Int])
case _ => numeric.negate(input)
}
@@ -278,6 +278,8 @@ abstract class BinaryArithmetic extends BinaryOperator
throw QueryExecutionErrors.notOverrideExpectedMethodsError("BinaryArithmetics",
"calendarIntervalMethod", "genCode")
+ protected def isAnsiInterval: Boolean = dataType.isInstanceOf[AnsiIntervalType]
+
// Name of the function for the exact version of this expression in [[Math]].
// If the option "spark.sql.ansi.enabled" is enabled and there is corresponding
// function in [[Math]], the exact function will be called instead of evaluation with [[symbol]].
@@ -305,7 +307,7 @@ abstract class BinaryArithmetic extends BinaryOperator
assert(exactMathMethod.isDefined,
s"The expression '$nodeName' must override the exactMathMethod() method " +
"if it is supposed to operate over interval types.")
- val mathUtils = MathUtils.getClass.getCanonicalName.stripSuffix("$")
+ val mathUtils = IntervalMathUtils.getClass.getCanonicalName.stripSuffix("$")
defineCodeGen(ctx, ev, (eval1, eval2) => s"$mathUtils.${exactMathMethod.get}($eval1, $eval2)")
// byte and short are casted into int when add, minus, times or divide
case ByteType | ShortType =>
@@ -406,9 +408,9 @@ case class Add(
IntervalUtils.add(
input1.asInstanceOf[CalendarInterval], input2.asInstanceOf[CalendarInterval])
case _: DayTimeIntervalType =>
- MathUtils.addExact(input1.asInstanceOf[Long], input2.asInstanceOf[Long])
+ IntervalMathUtils.addExact(input1.asInstanceOf[Long], input2.asInstanceOf[Long])
case _: YearMonthIntervalType =>
- MathUtils.addExact(input1.asInstanceOf[Int], input2.asInstanceOf[Int])
+ IntervalMathUtils.addExact(input1.asInstanceOf[Int], input2.asInstanceOf[Int])
case _: IntegerType if failOnError =>
MathUtils.addExact(input1.asInstanceOf[Int], input2.asInstanceOf[Int], getContextOrNull())
case _: LongType if failOnError =>
@@ -475,9 +477,9 @@ case class Subtract(
IntervalUtils.subtract(
input1.asInstanceOf[CalendarInterval], input2.asInstanceOf[CalendarInterval])
case _: DayTimeIntervalType =>
- MathUtils.subtractExact(input1.asInstanceOf[Long], input2.asInstanceOf[Long])
+ IntervalMathUtils.subtractExact(input1.asInstanceOf[Long], input2.asInstanceOf[Long])
case _: YearMonthIntervalType =>
- MathUtils.subtractExact(input1.asInstanceOf[Int], input2.asInstanceOf[Int])
+ IntervalMathUtils.subtractExact(input1.asInstanceOf[Int], input2.asInstanceOf[Int])
case _: IntegerType if failOnError =>
MathUtils.subtractExact(
input1.asInstanceOf[Int],
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
index f7ec82de11b..5378639e683 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/intervalExpressions.scala
@@ -607,7 +607,8 @@ trait IntervalDivide {
context: SQLQueryContext): Unit = {
if (value == minValue && num.dataType.isInstanceOf[IntegralType]) {
if (numValue.asInstanceOf[Number].longValue() == -1) {
- throw QueryExecutionErrors.overflowInIntegralDivideError(context)
+ throw QueryExecutionErrors.intervalArithmeticOverflowError(
+ "Interval value overflows after being divided by -1", "try_divide", context)
}
}
}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalMathUtils.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalMathUtils.scala
new file mode 100644
index 00000000000..c935c605737
--- /dev/null
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/IntervalMathUtils.scala
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.catalyst.util
+
+import org.apache.spark.sql.errors.QueryExecutionErrors
+
+/**
+ * Helper functions for interval arithmetic operations with overflow.
+ */
+object IntervalMathUtils {
+
+ def addExact(a: Int, b: Int): Int = withOverflow(Math.addExact(a, b), "try_add")
+
+ def addExact(a: Long, b: Long): Long = withOverflow(Math.addExact(a, b), "try_add")
+
+ def subtractExact(a: Int, b: Int): Int = withOverflow(Math.subtractExact(a, b), "try_subtract")
+
+ def subtractExact(a: Long, b: Long): Long = withOverflow(Math.subtractExact(a, b), "try_subtract")
+
+ def negateExact(a: Int): Int = withOverflow(Math.negateExact(a))
+
+ def negateExact(a: Long): Long = withOverflow(Math.negateExact(a))
+
+ private def withOverflow[A](f: => A, hint: String = ""): A = {
+ try {
+ f
+ } catch {
+ case e: ArithmeticException =>
+ throw QueryExecutionErrors.intervalArithmeticOverflowError(e.getMessage, hint, null)
+ }
+ }
+}
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
index 3644e7c0df8..71f42cf4d03 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala
@@ -535,6 +535,20 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase {
s"${toSQLValue(eval1, ShortType)} $symbol ${toSQLValue(eval2, ShortType)} caused overflow")
}
+ def intervalArithmeticOverflowError(
+ message: String,
+ hint: String = "",
+ context: SQLQueryContext): ArithmeticException = {
+ val alternative = if (hint.nonEmpty) {
+ s" Use '$hint' to tolerate overflow and return NULL instead."
+ } else ""
+ new SparkArithmeticException(
+ errorClass = "INTERVAL_ARITHMETIC_OVERFLOW",
+ messageParameters = Array(message, alternative),
+ context = getQueryContext(context),
+ summary = getSummary(context))
+ }
+
def failedToCompileMsg(e: Exception): String = {
s"failed to compile: $e"
}
diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out
index e96ab297d2a..19e8fbc8c9f 100644
--- a/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/ansi/interval.sql.out
@@ -1786,7 +1786,7 @@ select -(a) from values (interval '-2147483648 months', interval '2147483647 mon
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow.
-- !query
@@ -1795,7 +1795,7 @@ select a - b from values (interval '-2147483648 months', interval '2147483647 mo
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead.
-- !query
@@ -1804,7 +1804,7 @@ select b + interval '1 month' from values (interval '-2147483648 months', interv
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead.
-- !query
@@ -2033,7 +2033,7 @@ SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2045,7 +2045,7 @@ SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1L
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1L
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2091,7 +2091,7 @@ SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2103,7 +2103,7 @@ SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1L
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1L
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/sql/core/src/test/resources/sql-tests/results/interval.sql.out b/sql/core/src/test/resources/sql-tests/results/interval.sql.out
index 53172283d12..8234031021a 100644
--- a/sql/core/src/test/resources/sql-tests/results/interval.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/interval.sql.out
@@ -1742,7 +1742,7 @@ select -(a) from values (interval '-2147483648 months', interval '2147483647 mon
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow.
-- !query
@@ -1751,7 +1751,7 @@ select a - b from values (interval '-2147483648 months', interval '2147483647 mo
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead.
-- !query
@@ -1760,7 +1760,7 @@ select b + interval '1 month' from values (interval '-2147483648 months', interv
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead.
-- !query
@@ -1989,7 +1989,7 @@ SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2001,7 +2001,7 @@ SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1L
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-178956970-8' YEAR TO MONTH) / -1L
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2047,7 +2047,7 @@ SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -2059,7 +2059,7 @@ SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1L
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] Overflow in integral divide. Use 'try_divide' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[INTERVAL_ARITHMETIC_OVERFLOW] Interval value overflows after being divided by -1. Use 'try_divide' to tolerate overflow and return NULL instead.
== SQL(line 1, position 8) ==
SELECT (INTERVAL '-106751991 04:00:54.775808' DAY TO SECOND) / -1L
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/int4.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/int4.sql.out
index 730607e5c16..745633e157a 100755
--- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/int4.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/int4.sql.out
@@ -197,7 +197,7 @@ SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 * smallint('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^^^^^^
@@ -220,7 +220,7 @@ SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 * int('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^
@@ -243,7 +243,7 @@ SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 + smallint('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^^^^^^
@@ -267,7 +267,7 @@ SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 + int('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^
@@ -291,7 +291,7 @@ SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 - smallint('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^^^^^^
@@ -315,7 +315,7 @@ SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT4_TBL i
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] integer overflow. Use 'try_subtract' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 26) ==
SELECT '' AS five, i.f1, i.f1 - int('2') AS x FROM INT4_TBL i
^^^^^^^^^^^^^^^
diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/int8.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/int8.sql.out
index 664263ee8e7..ab77dbe6a60 100755
--- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/int8.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/int8.sql.out
@@ -389,7 +389,7 @@ SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 29) ==
SELECT '' AS three, q1, q2, q1 * q2 AS multiply FROM INT8_TBL
^^^^^^^
@@ -826,7 +826,7 @@ SELECT bigint((-9223372036854775808)) * bigint((-1))
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 8) ==
SELECT bigint((-9223372036854775808)) * bigint((-1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -854,7 +854,7 @@ SELECT bigint((-9223372036854775808)) * int((-1))
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 8) ==
SELECT bigint((-9223372036854775808)) * int((-1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -882,7 +882,7 @@ SELECT bigint((-9223372036854775808)) * smallint((-1))
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_multiply' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
== SQL(line 1, position 8) ==
SELECT bigint((-9223372036854775808)) * smallint((-1))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part2.sql.out b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part2.sql.out
index cb374eb62bd..127e9809169 100644
--- a/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part2.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/postgreSQL/window_part2.sql.out
@@ -222,7 +222,7 @@ from range(9223372036854775804, 9223372036854775807) x
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
-- !query
@@ -232,7 +232,7 @@ from range(-9223372036854775806, -9223372036854775805) x
struct<>
-- !query output
org.apache.spark.SparkArithmeticException
-[ARITHMETIC_OVERFLOW] long overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" (except for ANSI interval type) to bypass this error.
+[ARITHMETIC_OVERFLOW] long overflow. Use 'try_add' to tolerate overflow and return NULL instead. If necessary set spark.sql.ansi.enabled to "false" to bypass this error.
-- !query
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
index 81a9294df39..958b3e3f53c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
@@ -1266,13 +1266,13 @@ class DataFrameAggregateSuite extends QueryTest
checkAnswer(df2.select(sum($"year-month")), Nil)
}
assert(error.toString contains
- "SparkArithmeticException: [ARITHMETIC_OVERFLOW] integer overflow")
+ "SparkArithmeticException: [INTERVAL_ARITHMETIC_OVERFLOW] integer overflow")
val error2 = intercept[SparkException] {
checkAnswer(df2.select(sum($"day")), Nil)
}
assert(error2.toString contains
- "SparkArithmeticException: [ARITHMETIC_OVERFLOW] long overflow")
+ "SparkArithmeticException: [INTERVAL_ARITHMETIC_OVERFLOW] long overflow")
}
test("SPARK-34837: Support ANSI SQL intervals by the aggregate function `avg`") {
@@ -1402,13 +1402,13 @@ class DataFrameAggregateSuite extends QueryTest
checkAnswer(df2.select(avg($"year-month")), Nil)
}
assert(error.toString contains
- "SparkArithmeticException: [ARITHMETIC_OVERFLOW] integer overflow")
+ "SparkArithmeticException: [INTERVAL_ARITHMETIC_OVERFLOW] integer overflow")
val error2 = intercept[SparkException] {
checkAnswer(df2.select(avg($"day")), Nil)
}
assert(error2.toString contains
- "SparkArithmeticException: [ARITHMETIC_OVERFLOW] long overflow")
+ "SparkArithmeticException: [INTERVAL_ARITHMETIC_OVERFLOW] long overflow")
val df3 = intervalData.filter($"class" > 4)
val avgDF3 = df3.select(avg($"year-month"), avg($"day"))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org