Repository: spark
Updated Branches:
  refs/heads/branch-1.6 113410c12 -> 2ae1fa074


[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 <vii...@appier.com>

Closes #9757 from viirya/fix-randomgenerated-udt.

(cherry picked from commit d79d8b08ff69b30b02fe87839e695e29bfea5ace)
Signed-off-by: Davies Liu <davies....@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/2ae1fa07
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/2ae1fa07
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/2ae1fa07

Branch: refs/heads/branch-1.6
Commit: 2ae1fa074c2dedc67bdde0ac48e2af9476d4cba1
Parents: 113410c
Author: Liang-Chi Hsieh <vii...@appier.com>
Authored: Mon Nov 16 23:16:17 2015 -0800
Committer: Davies Liu <davies....@gmail.com>
Committed: Mon Nov 16 23:16:33 2015 -0800

----------------------------------------------------------------------
 .../spark/sql/catalyst/encoders/RowEncoderSuite.scala       | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/2ae1fa07/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/RowEncoderSuite.scala
----------------------------------------------------------------------
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 c868dde..46c6e0d 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())
+        }
     }
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to