Skip to content
Snippets Groups Projects
Commit d79d8b08 authored by Liang-Chi Hsieh's avatar Liang-Chi Hsieh Committed by Davies Liu
Browse files

[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.
parent e01865af
No related branches found
No related tags found
No related merge requests found
......@@ -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())
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment