Skip to content

Commit 9621fc6

Browse files
committed
preserve decimal type info
1 parent f49e6d4 commit 9621fc6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/RowEncoder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ object RowEncoder {
8484
"fromJavaDate",
8585
inputObject :: Nil)
8686

87-
case _: DecimalType =>
87+
case d: DecimalType =>
8888
StaticInvoke(
8989
Decimal.getClass,
90-
DecimalType.SYSTEM_DEFAULT,
90+
d,
9191
"fromDecimal",
9292
inputObject :: Nil)
9393

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ class RowEncoderSuite extends SparkFunSuite {
164164
assert(convertedBack.getDecimal(2).compareTo(catalystDecimal.toJavaBigDecimal) == 0)
165165
}
166166

167+
test("RowEncoder should preserve decimal precision and scale") {
168+
val schema = new StructType().add("decimal", DecimalType(10, 5), false)
169+
val encoder = RowEncoder(schema)
170+
val decimal = Decimal("67123.45")
171+
val input = Row(decimal)
172+
val row = encoder.toRow(input)
173+
174+
assert(row.toSeq(schema).head == decimal)
175+
}
176+
167177
test("RowEncoder should preserve schema nullability") {
168178
val schema = new StructType().add("int", IntegerType, nullable = false)
169179
val encoder = RowEncoder(schema)

0 commit comments

Comments
 (0)