From 37ad74b01347fc8c8d881e1fd91b6e297f9f927a Mon Sep 17 00:00:00 2001 From: Gengliang Wang Date: Mon, 17 Aug 2020 14:32:25 +0800 Subject: [PATCH] Revert "[SPARK-32018][SQL][3.0] UnsafeRow.setDecimal should set null with overflowed value" This reverts commit 9b6bea5d5ab4bd3a69ca6eaf7811eb54f9562ee6. --- .../spark/sql/catalyst/expressions/UnsafeRow.java | 2 +- .../scala/org/apache/spark/sql/UnsafeRowSuite.scala | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java index 4dc5ce1de047b..034894bd86085 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java @@ -288,7 +288,7 @@ public void setDecimal(int ordinal, Decimal value, int precision) { Platform.putLong(baseObject, baseOffset + cursor, 0L); Platform.putLong(baseObject, baseOffset + cursor + 8, 0L); - if (value == null || !value.changePrecision(precision, value.scale())) { + if (value == null) { setNullAt(ordinal); // keep the offset for future update Platform.putLong(baseObject, getFieldOffset(ordinal), cursor << 32); diff --git a/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala index 9daa69ce9f155..a5f904c621e6e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala @@ -178,14 +178,4 @@ class UnsafeRowSuite extends SparkFunSuite { // Makes sure hashCode on unsafe array won't crash unsafeRow.getArray(0).hashCode() } - - test("SPARK-32018: setDecimal with overflowed value") { - val d1 = new Decimal().set(BigDecimal("10000000000000000000")).toPrecision(38, 18) - val row = InternalRow.apply(d1) - val unsafeRow = UnsafeProjection.create(Array[DataType](DecimalType(38, 18))).apply(row) - assert(unsafeRow.getDecimal(0, 38, 18) === d1) - val d2 = (d1 * Decimal(10)).toPrecision(39, 18) - unsafeRow.setDecimal(0, d2, 38) - assert(unsafeRow.getDecimal(0, 38, 18) === null) - } }