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 ba79d1ae293 [SPARK-42045][SQL] ANSI SQL mode: Round/Bround should
return an error on tiny/small/big integer overflow
ba79d1ae293 is described below
commit ba79d1ae293f4b956129c65459a5f3e82dbc0f82
Author: Gengliang Wang <[email protected]>
AuthorDate: Fri Jan 13 20:30:46 2023 -0800
[SPARK-42045][SQL] ANSI SQL mode: Round/Bround should return an error on
tiny/small/big integer overflow
### What changes were proposed in this pull request?
Similar to https://github.com/apache/spark/pull/39546, this PR is to change
Round/Bround to return an error on tiny/small/big integer overflow.
### Why are the changes needed?
In ANSI SQL mode, integer overflow should cause error instead of returning
an unreasonable result.
For example, round(127y, -1) should return error instead of returning -126
### Does this PR introduce _any_ user-facing change?
Yes, in ANSI SQL mode, SQL function Round and Bround will return an error
on tiny/small/big integer overflow
### How was this patch tested?
UTs
Closes #39557 from gengliangwang/fixRoundOtherInt.
Authored-by: Gengliang Wang <[email protected]>
Signed-off-by: Gengliang Wang <[email protected]>
---
.../sql/catalyst/expressions/mathExpressions.scala | 74 ++-
.../expressions/MathExpressionsSuite.scala | 23 +-
.../src/test/resources/sql-tests/inputs/math.sql | 58 ++-
.../resources/sql-tests/results/ansi/math.sql.out | 528 +++++++++++++++++++++
.../test/resources/sql-tests/results/math.sql.out | 336 +++++++++++++
5 files changed, 970 insertions(+), 49 deletions(-)
diff --git
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
index 50a1194c2f1..d5bf77968f8 100644
---
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
+++
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/mathExpressions.scala
@@ -1537,8 +1537,16 @@ abstract class RoundBase(child: Expression, scale:
Expression,
} else {
Decimal(decimal.toBigDecimal.setScale(_scale, mode), p, s)
}
+ case ByteType if ansiEnabled =>
+ MathUtils.withOverflow(
+ f = BigDecimal(input1.asInstanceOf[Byte]).setScale(_scale,
mode).toByteExact,
+ context = getContextOrNull)
case ByteType =>
BigDecimal(input1.asInstanceOf[Byte]).setScale(_scale, mode).toByte
+ case ShortType if ansiEnabled =>
+ MathUtils.withOverflow(
+ f = BigDecimal(input1.asInstanceOf[Short]).setScale(_scale,
mode).toShortExact,
+ context = getContextOrNull)
case ShortType =>
BigDecimal(input1.asInstanceOf[Short]).setScale(_scale, mode).toShort
case IntegerType if ansiEnabled =>
@@ -1547,6 +1555,10 @@ abstract class RoundBase(child: Expression, scale:
Expression,
context = getContextOrNull)
case IntegerType =>
BigDecimal(input1.asInstanceOf[Int]).setScale(_scale, mode).toInt
+ case LongType if ansiEnabled =>
+ MathUtils.withOverflow(
+ f = BigDecimal(input1.asInstanceOf[Long]).setScale(_scale,
mode).toLongExact,
+ context = getContextOrNull)
case LongType =>
BigDecimal(input1.asInstanceOf[Long]).setScale(_scale, mode).toLong
case FloatType =>
@@ -1569,6 +1581,26 @@ abstract class RoundBase(child: Expression, scale:
Expression,
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val ce = child.genCode(ctx)
+ def codegenForIntegralType(dt: String): String = {
+ if (_scale < 0) {
+ if (ansiEnabled) {
+ val errorContext = getContextOrNullCode(ctx)
+ val evalCode = s"""
+ |${ev.value} = new java.math.BigDecimal(${ce.value}).
+ |setScale(${_scale},
java.math.BigDecimal.${modeStr}).${dt}ValueExact();
+ |""".stripMargin
+ MathUtils.withOverflowCode(evalCode, errorContext)
+ } else {
+ s"""
+ |${ev.value} = new java.math.BigDecimal(${ce.value}).
+ |setScale(${_scale},
java.math.BigDecimal.${modeStr}).${dt}Value();
+ |""".stripMargin
+ }
+ } else {
+ s"${ev.value} = ${ce.value};"
+ }
+ }
+
val evaluationCode = dataType match {
case DecimalType.Fixed(p, s) =>
if (_scale >= 0) {
@@ -1583,47 +1615,13 @@ abstract class RoundBase(child: Expression, scale:
Expression,
${ev.isNull} = ${ev.value} == null;"""
}
case ByteType =>
- if (_scale < 0) {
- s"""
- ${ev.value} = new java.math.BigDecimal(${ce.value}).
- setScale(${_scale},
java.math.BigDecimal.${modeStr}).byteValue();"""
- } else {
- s"${ev.value} = ${ce.value};"
- }
+ codegenForIntegralType("byte")
case ShortType =>
- if (_scale < 0) {
- s"""
- ${ev.value} = new java.math.BigDecimal(${ce.value}).
- setScale(${_scale},
java.math.BigDecimal.${modeStr}).shortValue();"""
- } else {
- s"${ev.value} = ${ce.value};"
- }
+ codegenForIntegralType("short")
case IntegerType =>
- if (_scale < 0) {
- if (ansiEnabled) {
- val errorContext = getContextOrNullCode(ctx)
- val evalCode = s"""
- |${ev.value} = new java.math.BigDecimal(${ce.value}).
- |setScale(${_scale},
java.math.BigDecimal.${modeStr}).intValueExact();
- |""".stripMargin
- MathUtils.withOverflowCode(evalCode, errorContext)
- } else {
- s"""
- |${ev.value} = new java.math.BigDecimal(${ce.value}).
- |setScale(${_scale},
java.math.BigDecimal.${modeStr}).intValue();
- |""".stripMargin
- }
- } else {
- s"${ev.value} = ${ce.value};"
- }
+ codegenForIntegralType("int")
case LongType =>
- if (_scale < 0) {
- s"""
- ${ev.value} = new java.math.BigDecimal(${ce.value}).
- setScale(${_scale},
java.math.BigDecimal.${modeStr}).longValue();"""
- } else {
- s"${ev.value} = ${ce.value};"
- }
+ codegenForIntegralType("long")
case FloatType => // if child eval to NaN or Infinity, just return it.
s"""
if (Float.isNaN(${ce.value}) || Float.isInfinite(${ce.value})) {
diff --git
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
index 92b683a7106..be0375af094 100644
---
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
+++
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MathExpressionsSuite.scala
@@ -839,15 +839,20 @@ class MathExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
}
test("SPARK-42045: integer overflow in round/bround") {
- val input = 2147483647
- val scale = -1
- Seq(Round(input, scale, ansiEnabled = true),
- BRound(input, scale, ansiEnabled = true)).foreach { expr =>
- checkExceptionInExpression[SparkArithmeticException](expr, "Overflow")
- }
- Seq(Round(input, scale, ansiEnabled = false),
- BRound(input, scale, ansiEnabled = false)).foreach { expr =>
- checkEvaluation(expr, -2147483646)
+ Seq(
+ (Byte.MaxValue, ByteType, -1, -126.toByte),
+ (Short.MaxValue, ShortType, -1, -32766.toShort),
+ (Int.MaxValue, IntegerType, -1, -2147483646),
+ (Long.MaxValue, LongType, -1, -9223372036854775806L)
+ ).foreach { case (input, dt, scale, expected) =>
+ Seq(Round(Literal(input, dt), scale, ansiEnabled = true),
+ BRound(Literal(input, dt), scale, ansiEnabled = true)).foreach { expr
=>
+ checkExceptionInExpression[SparkArithmeticException](expr, "Overflow")
+ }
+ Seq(Round(Literal(input, dt), scale, ansiEnabled = false),
+ BRound(Literal(input, dt), scale, ansiEnabled = false)).foreach { expr
=>
+ checkEvaluation(expr, expected)
+ }
}
}
diff --git a/sql/core/src/test/resources/sql-tests/inputs/math.sql
b/sql/core/src/test/resources/sql-tests/inputs/math.sql
index df7210c4595..46ee9fdb2d5 100644
--- a/sql/core/src/test/resources/sql-tests/inputs/math.sql
+++ b/sql/core/src/test/resources/sql-tests/inputs/math.sql
@@ -1,3 +1,21 @@
+-- Round with Byte input
+SELECT round(25y, 1);
+SELECT round(25y, 0);
+SELECT round(25y, -1);
+SELECT round(25y, -2);
+SELECT round(25y, -3);
+SELECT round(127y, -1);
+SELECT round(-128y, -1);
+
+-- Round with short integer input
+SELECT round(525s, 1);
+SELECT round(525s, 0);
+SELECT round(525s, -1);
+SELECT round(525s, -2);
+SELECT round(525s, -3);
+SELECT round(32767s, -1);
+SELECT round(-32768s, -1);
+
-- Round with integer input
SELECT round(525, 1);
SELECT round(525, 0);
@@ -7,11 +25,47 @@ SELECT round(525, -3);
SELECT round(2147483647, -1);
SELECT round(-2147483647, -1);
--- BRound with integer input
+-- Round with big integer input
+SELECT round(525L, 1);
+SELECT round(525L, 0);
+SELECT round(525L, -1);
+SELECT round(525L, -2);
+SELECT round(525L, -3);
+SELECT round(9223372036854775807L, -1);
+SELECT round(-9223372036854775808L, -1);
+
+-- Bround with byte input
+SELECT bround(25y, 1);
+SELECT bround(25y, 0);
+SELECT bround(25y, -1);
+SELECT bround(25y, -2);
+SELECT bround(25y, -3);
+SELECT bround(127y, -1);
+SELECT bround(-128y, -1);
+
+-- Bround with Short input
+SELECT bround(525s, 1);
+SELECT bround(525s, 0);
+SELECT bround(525s, -1);
+SELECT bround(525s, -2);
+SELECT bround(525s, -3);
+SELECT bround(32767s, -1);
+SELECT bround(-32768s, -1);
+
+-- Bround with integer input
SELECT bround(525, 1);
SELECT bround(525, 0);
SELECT bround(525, -1);
SELECT bround(525, -2);
SELECT bround(525, -3);
SELECT bround(2147483647, -1);
-SELECT bround(-2147483647, -1);
\ No newline at end of file
+SELECT bround(-2147483647, -1);
+
+-- Bround with big integer input
+SELECT bround(525L, 1);
+SELECT bround(525L, 0);
+SELECT bround(525L, -1);
+SELECT bround(525L, -2);
+SELECT bround(525L, -3);
+SELECT bround(9223372036854775807L, -1);
+SELECT bround(-9223372036854775808L, -1);
\ No newline at end of file
diff --git a/sql/core/src/test/resources/sql-tests/results/ansi/math.sql.out
b/sql/core/src/test/resources/sql-tests/results/ansi/math.sql.out
index e7866b59047..e24b23bbacd 100644
--- a/sql/core/src/test/resources/sql-tests/results/ansi/math.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/ansi/math.sql.out
@@ -1,4 +1,180 @@
-- Automatically generated by SQLQueryTestSuite
+-- !query
+SELECT round(25y, 1)
+-- !query schema
+struct<round(25, 1):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT round(25y, 0)
+-- !query schema
+struct<round(25, 0):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT round(25y, -1)
+-- !query schema
+struct<round(25, -1):tinyint>
+-- !query output
+30
+
+
+-- !query
+SELECT round(25y, -2)
+-- !query schema
+struct<round(25, -2):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT round(25y, -3)
+-- !query schema
+struct<round(25, -3):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT round(127y, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 22,
+ "fragment" : "round(127y, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT round(-128y, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 23,
+ "fragment" : "round(-128y, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT round(525s, 1)
+-- !query schema
+struct<round(525, 1):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525s, 0)
+-- !query schema
+struct<round(525, 0):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525s, -1)
+-- !query schema
+struct<round(525, -1):smallint>
+-- !query output
+530
+
+
+-- !query
+SELECT round(525s, -2)
+-- !query schema
+struct<round(525, -2):smallint>
+-- !query output
+500
+
+
+-- !query
+SELECT round(525s, -3)
+-- !query schema
+struct<round(525, -3):smallint>
+-- !query output
+1000
+
+
+-- !query
+SELECT round(32767s, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 24,
+ "fragment" : "round(32767s, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT round(-32768s, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 25,
+ "fragment" : "round(-32768s, -1)"
+ } ]
+}
+
+
-- !query
SELECT round(525, 1)
-- !query schema
@@ -87,6 +263,270 @@ org.apache.spark.SparkArithmeticException
}
+-- !query
+SELECT round(525L, 1)
+-- !query schema
+struct<round(525, 1):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525L, 0)
+-- !query schema
+struct<round(525, 0):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525L, -1)
+-- !query schema
+struct<round(525, -1):bigint>
+-- !query output
+530
+
+
+-- !query
+SELECT round(525L, -2)
+-- !query schema
+struct<round(525, -2):bigint>
+-- !query output
+500
+
+
+-- !query
+SELECT round(525L, -3)
+-- !query schema
+struct<round(525, -3):bigint>
+-- !query output
+1000
+
+
+-- !query
+SELECT round(9223372036854775807L, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 38,
+ "fragment" : "round(9223372036854775807L, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT round(-9223372036854775808L, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 39,
+ "fragment" : "round(-9223372036854775808L, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT bround(25y, 1)
+-- !query schema
+struct<bround(25, 1):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT bround(25y, 0)
+-- !query schema
+struct<bround(25, 0):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT bround(25y, -1)
+-- !query schema
+struct<bround(25, -1):tinyint>
+-- !query output
+20
+
+
+-- !query
+SELECT bround(25y, -2)
+-- !query schema
+struct<bround(25, -2):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT bround(25y, -3)
+-- !query schema
+struct<bround(25, -3):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT bround(127y, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 23,
+ "fragment" : "bround(127y, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT bround(-128y, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 24,
+ "fragment" : "bround(-128y, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT bround(525s, 1)
+-- !query schema
+struct<bround(525, 1):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525s, 0)
+-- !query schema
+struct<bround(525, 0):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525s, -1)
+-- !query schema
+struct<bround(525, -1):smallint>
+-- !query output
+520
+
+
+-- !query
+SELECT bround(525s, -2)
+-- !query schema
+struct<bround(525, -2):smallint>
+-- !query output
+500
+
+
+-- !query
+SELECT bround(525s, -3)
+-- !query schema
+struct<bround(525, -3):smallint>
+-- !query output
+1000
+
+
+-- !query
+SELECT bround(32767s, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 25,
+ "fragment" : "bround(32767s, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT bround(-32768s, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 26,
+ "fragment" : "bround(-32768s, -1)"
+ } ]
+}
+
+
-- !query
SELECT bround(525, 1)
-- !query schema
@@ -173,3 +613,91 @@ org.apache.spark.SparkArithmeticException
"fragment" : "bround(-2147483647, -1)"
} ]
}
+
+
+-- !query
+SELECT bround(525L, 1)
+-- !query schema
+struct<bround(525, 1):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525L, 0)
+-- !query schema
+struct<bround(525, 0):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525L, -1)
+-- !query schema
+struct<bround(525, -1):bigint>
+-- !query output
+520
+
+
+-- !query
+SELECT bround(525L, -2)
+-- !query schema
+struct<bround(525, -2):bigint>
+-- !query output
+500
+
+
+-- !query
+SELECT bround(525L, -3)
+-- !query schema
+struct<bround(525, -3):bigint>
+-- !query output
+1000
+
+
+-- !query
+SELECT bround(9223372036854775807L, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 39,
+ "fragment" : "bround(9223372036854775807L, -1)"
+ } ]
+}
+
+
+-- !query
+SELECT bround(-9223372036854775808L, -1)
+-- !query schema
+struct<>
+-- !query output
+org.apache.spark.SparkArithmeticException
+{
+ "errorClass" : "ARITHMETIC_OVERFLOW",
+ "sqlState" : "22003",
+ "messageParameters" : {
+ "alternative" : "",
+ "config" : "\"spark.sql.ansi.enabled\"",
+ "message" : "Overflow"
+ },
+ "queryContext" : [ {
+ "objectType" : "",
+ "objectName" : "",
+ "startIndex" : 8,
+ "stopIndex" : 40,
+ "fragment" : "bround(-9223372036854775808L, -1)"
+ } ]
+}
diff --git a/sql/core/src/test/resources/sql-tests/results/math.sql.out
b/sql/core/src/test/resources/sql-tests/results/math.sql.out
index 693ce3e8cbf..4721d66b6fc 100644
--- a/sql/core/src/test/resources/sql-tests/results/math.sql.out
+++ b/sql/core/src/test/resources/sql-tests/results/math.sql.out
@@ -1,4 +1,116 @@
-- Automatically generated by SQLQueryTestSuite
+-- !query
+SELECT round(25y, 1)
+-- !query schema
+struct<round(25, 1):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT round(25y, 0)
+-- !query schema
+struct<round(25, 0):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT round(25y, -1)
+-- !query schema
+struct<round(25, -1):tinyint>
+-- !query output
+30
+
+
+-- !query
+SELECT round(25y, -2)
+-- !query schema
+struct<round(25, -2):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT round(25y, -3)
+-- !query schema
+struct<round(25, -3):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT round(127y, -1)
+-- !query schema
+struct<round(127, -1):tinyint>
+-- !query output
+-126
+
+
+-- !query
+SELECT round(-128y, -1)
+-- !query schema
+struct<round(-128, -1):tinyint>
+-- !query output
+126
+
+
+-- !query
+SELECT round(525s, 1)
+-- !query schema
+struct<round(525, 1):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525s, 0)
+-- !query schema
+struct<round(525, 0):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525s, -1)
+-- !query schema
+struct<round(525, -1):smallint>
+-- !query output
+530
+
+
+-- !query
+SELECT round(525s, -2)
+-- !query schema
+struct<round(525, -2):smallint>
+-- !query output
+500
+
+
+-- !query
+SELECT round(525s, -3)
+-- !query schema
+struct<round(525, -3):smallint>
+-- !query output
+1000
+
+
+-- !query
+SELECT round(32767s, -1)
+-- !query schema
+struct<round(32767, -1):smallint>
+-- !query output
+-32766
+
+
+-- !query
+SELECT round(-32768s, -1)
+-- !query schema
+struct<round(-32768, -1):smallint>
+-- !query output
+32766
+
+
-- !query
SELECT round(525, 1)
-- !query schema
@@ -55,6 +167,174 @@ struct<round(-2147483647, -1):int>
2147483646
+-- !query
+SELECT round(525L, 1)
+-- !query schema
+struct<round(525, 1):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525L, 0)
+-- !query schema
+struct<round(525, 0):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT round(525L, -1)
+-- !query schema
+struct<round(525, -1):bigint>
+-- !query output
+530
+
+
+-- !query
+SELECT round(525L, -2)
+-- !query schema
+struct<round(525, -2):bigint>
+-- !query output
+500
+
+
+-- !query
+SELECT round(525L, -3)
+-- !query schema
+struct<round(525, -3):bigint>
+-- !query output
+1000
+
+
+-- !query
+SELECT round(9223372036854775807L, -1)
+-- !query schema
+struct<round(9223372036854775807, -1):bigint>
+-- !query output
+-9223372036854775806
+
+
+-- !query
+SELECT round(-9223372036854775808L, -1)
+-- !query schema
+struct<round(-9223372036854775808, -1):bigint>
+-- !query output
+9223372036854775806
+
+
+-- !query
+SELECT bround(25y, 1)
+-- !query schema
+struct<bround(25, 1):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT bround(25y, 0)
+-- !query schema
+struct<bround(25, 0):tinyint>
+-- !query output
+25
+
+
+-- !query
+SELECT bround(25y, -1)
+-- !query schema
+struct<bround(25, -1):tinyint>
+-- !query output
+20
+
+
+-- !query
+SELECT bround(25y, -2)
+-- !query schema
+struct<bround(25, -2):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT bround(25y, -3)
+-- !query schema
+struct<bround(25, -3):tinyint>
+-- !query output
+0
+
+
+-- !query
+SELECT bround(127y, -1)
+-- !query schema
+struct<bround(127, -1):tinyint>
+-- !query output
+-126
+
+
+-- !query
+SELECT bround(-128y, -1)
+-- !query schema
+struct<bround(-128, -1):tinyint>
+-- !query output
+126
+
+
+-- !query
+SELECT bround(525s, 1)
+-- !query schema
+struct<bround(525, 1):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525s, 0)
+-- !query schema
+struct<bround(525, 0):smallint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525s, -1)
+-- !query schema
+struct<bround(525, -1):smallint>
+-- !query output
+520
+
+
+-- !query
+SELECT bround(525s, -2)
+-- !query schema
+struct<bround(525, -2):smallint>
+-- !query output
+500
+
+
+-- !query
+SELECT bround(525s, -3)
+-- !query schema
+struct<bround(525, -3):smallint>
+-- !query output
+1000
+
+
+-- !query
+SELECT bround(32767s, -1)
+-- !query schema
+struct<bround(32767, -1):smallint>
+-- !query output
+-32766
+
+
+-- !query
+SELECT bround(-32768s, -1)
+-- !query schema
+struct<bround(-32768, -1):smallint>
+-- !query output
+32766
+
+
-- !query
SELECT bround(525, 1)
-- !query schema
@@ -109,3 +389,59 @@ SELECT bround(-2147483647, -1)
struct<bround(-2147483647, -1):int>
-- !query output
2147483646
+
+
+-- !query
+SELECT bround(525L, 1)
+-- !query schema
+struct<bround(525, 1):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525L, 0)
+-- !query schema
+struct<bround(525, 0):bigint>
+-- !query output
+525
+
+
+-- !query
+SELECT bround(525L, -1)
+-- !query schema
+struct<bround(525, -1):bigint>
+-- !query output
+520
+
+
+-- !query
+SELECT bround(525L, -2)
+-- !query schema
+struct<bround(525, -2):bigint>
+-- !query output
+500
+
+
+-- !query
+SELECT bround(525L, -3)
+-- !query schema
+struct<bround(525, -3):bigint>
+-- !query output
+1000
+
+
+-- !query
+SELECT bround(9223372036854775807L, -1)
+-- !query schema
+struct<bround(9223372036854775807, -1):bigint>
+-- !query output
+-9223372036854775806
+
+
+-- !query
+SELECT bround(-9223372036854775808L, -1)
+-- !query schema
+struct<bround(-9223372036854775808, -1):bigint>
+-- !query output
+9223372036854775806
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]