diff options
author | Liang-Chi Hsieh <viirya@appier.com> | 2015-11-16 23:16:17 -0800 |
---|---|---|
committer | Davies Liu <davies.liu@gmail.com> | 2015-11-16 23:16:17 -0800 |
commit | d79d8b08ff69b30b02fe87839e695e29bfea5ace (patch) | |
tree | 93fb33108698ccbdd17f952d5c212df7fec99202 /sql | |
parent | e01865af0d5ebe11033de46c388c5c583876c187 (diff) | |
download | spark-d79d8b08ff69b30b02fe87839e695e29bfea5ace.tar.gz spark-d79d8b08ff69b30b02fe87839e695e29bfea5ace.tar.bz2 spark-d79d8b08ff69b30b02fe87839e695e29bfea5ace.zip |
[MINOR] [SQL] Fix randomly generated ArrayData in RowEncoderSuite
The randomly generated ArrayData used for the UDT `ExamplePoint` in `RowEncoderSuite` sometimes doesn't have enough elements. In this case, this test will fail. This patch is to fix it.
Author: Liang-Chi Hsieh <viirya@appier.com>
Closes #9757 from viirya/fix-randomgenerated-udt.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala index c868ddec1b..46c6e0d98d 100644 --- a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala +++ b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala @@ -17,6 +17,8 @@ package org.apache.spark.sql.catalyst.encoders +import scala.util.Random + import org.apache.spark.SparkFunSuite import org.apache.spark.sql.{RandomDataGenerator, Row} import org.apache.spark.sql.catalyst.util.{GenericArrayData, ArrayData} @@ -59,7 +61,12 @@ class ExamplePointUDT extends UserDefinedType[ExamplePoint] { override def deserialize(datum: Any): ExamplePoint = { datum match { case values: ArrayData => - new ExamplePoint(values.getDouble(0), values.getDouble(1)) + if (values.numElements() > 1) { + new ExamplePoint(values.getDouble(0), values.getDouble(1)) + } else { + val random = new Random() + new ExamplePoint(random.nextDouble(), random.nextDouble()) + } } } |