Skip to content
Closed
Show file tree
Hide file tree
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 @@ -450,10 +450,15 @@ object SerializerBuildHelper {
private def validateAndSerializeElement(
enc: AgnosticEncoder[_],
nullable: Boolean): Expression => Expression = { input =>
val expected = enc match {
case OptionEncoder(_) => lenientExternalDataTypeFor(enc)
case _ => enc.dataType
}

expressionWithNullSafety(
createSerializer(
enc,
ValidateExternalType(input, enc.dataType, lenientExternalDataTypeFor(enc))),
ValidateExternalType(input, expected, lenientExternalDataTypeFor(enc))),
nullable,
WalkedTypePath())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,18 @@ class ExpressionEncoderSuite extends CodegenInterpretedPlanTest with AnalysisTes
encodeDecodeTest(Option.empty[Int], "empty option of int")
encodeDecodeTest(Option("abc"), "option of string")
encodeDecodeTest(Option.empty[String], "empty option of string")
encodeDecodeTest(Seq(Some(Seq(0))), "SPARK-45896: seq of option of seq")
encodeDecodeTest(Map(0 -> Some(Seq(0))), "SPARK-45896: map of option of seq")
encodeDecodeTest(Seq(Some(Timestamp.valueOf("2023-01-01 00:00:00"))),
"SPARK-45896: seq of option of timestamp")
encodeDecodeTest(Map(0 -> Some(Timestamp.valueOf("2023-01-01 00:00:00"))),
"SPARK-45896: map of option of timestamp")
encodeDecodeTest(Seq(Some(Date.valueOf("2023-01-01"))),
"SPARK-45896: seq of option of date")
encodeDecodeTest(Map(0 -> Some(Date.valueOf("2023-01-01"))),
"SPARK-45896: map of option of date")
encodeDecodeTest(Seq(Some(BigDecimal(200))), "SPARK-45896: seq of option of bigdecimal")
encodeDecodeTest(Map(0 -> Some(BigDecimal(200))), "SPARK-45896: map of option of bigdecimal")

encodeDecodeTest(ScroogeLikeExample(1),
"SPARK-40385 class with only a companion object constructor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ class DatasetSuite extends QueryTest
(ClassData("one", 2), 1L), (ClassData("two", 3), 1L))
}

test("SPARK-45896: seq of option of seq") {
val ds = Seq(DataSeqOptSeq(Seq(Some(Seq(0))))).toDS()
checkDataset(
ds,
DataSeqOptSeq(Seq(Some(List(0)))))
}

test("select") {
val ds = Seq(("a", 1), ("b", 2), ("c", 3)).toDS()
checkDataset(
Expand Down Expand Up @@ -2760,6 +2767,8 @@ case class ClassNullableData(a: String, b: Integer)
case class NestedStruct(f: ClassData)
case class DeepNestedStruct(f: NestedStruct)

case class DataSeqOptSeq(a: Seq[Option[Seq[Int]]])

/**
* A class used to test serialization using encoders. This class throws exceptions when using
* Java serialization -- so the only way it can be "serialized" is through our encoders.
Expand Down