This is an automated email from the ASF dual-hosted git repository. srowen 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 0087a2a19dd [SPARK-41007][SQL] Add missing serializer for java.math.BigInteger 0087a2a19dd is described below commit 0087a2a19dd081b524e96d6a407d3940cab1f2c0 Author: Daniel Fiterman <fiter...@amazon.com> AuthorDate: Mon Nov 7 19:33:21 2022 -0600 [SPARK-41007][SQL] Add missing serializer for java.math.BigInteger ### What changes were proposed in this pull request? The JavaTypeInference class used by the [Bean Encoder](https://spark.apache.org/docs/3.2.0/api/java/org/apache/spark/sql/Encoders.html#bean-java.lang.Class-) to create serialize/deserialize a Java Bean was missing a case statement to serialize java.math.BigInteger. This adds the missing case statement. ### Why are the changes needed? This fixes the bug mentioned in the description ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - Unit Test - Manually tested creating a new dataset with a Java Bean containing a java.math.BigInteger field Closes #38500 from dfit99/SPARK-41007. Authored-by: Daniel Fiterman <fiter...@amazon.com> Signed-off-by: Sean Owen <sro...@gmail.com> --- .../spark/sql/catalyst/JavaTypeInference.scala | 3 ++ .../sql/catalyst/JavaTypeInferenceSuite.scala | 42 ++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala index 903072ae29d..dccaf1c4835 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/JavaTypeInference.scala @@ -424,6 +424,9 @@ object JavaTypeInference { case c if c == classOf[java.time.Period] => createSerializerForJavaPeriod(inputObject) + case c if c == classOf[java.math.BigInteger] => + createSerializerForJavaBigInteger(inputObject) + case c if c == classOf[java.math.BigDecimal] => createSerializerForJavaBigDecimal(inputObject) diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala new file mode 100644 index 00000000000..9c1d0c17777 --- /dev/null +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/JavaTypeInferenceSuite.scala @@ -0,0 +1,42 @@ +/* + * 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 + +import java.math.BigInteger + +import scala.beans.BeanProperty + +import org.apache.spark.SparkFunSuite +import org.apache.spark.sql.catalyst.expressions.{CheckOverflow, Expression, Literal} +import org.apache.spark.sql.types.DecimalType + +class DummyBean() { + @BeanProperty var bigInteger = null: BigInteger +} + +class JavaTypeInferenceSuite extends SparkFunSuite { + + test("SPARK-41007: JavaTypeInference returns the correct serializer for BigInteger") { + var serializer = JavaTypeInference.serializerFor(classOf[DummyBean]) + var bigIntegerFieldName: Expression = serializer.children(0) + assert(bigIntegerFieldName.asInstanceOf[Literal].value.toString == "bigInteger") + var bigIntegerFieldExpression: Expression = serializer.children(1) + assert(bigIntegerFieldExpression.asInstanceOf[CheckOverflow].dataType == + DecimalType.BigIntDecimal) + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org For additional commands, e-mail: commits-h...@spark.apache.org