Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use the first element at least? Did we check the result in tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did check the results as we check input row and the row converted back.
Because this UDT ExamplePoint needs at least two double values. If the array generated by the random generator at the first contains only 1 or 0 elements. values.getDouble will throw out of range exception.

}
}
}

Expand Down