Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kiszk committed Dec 1, 2016
1 parent 93d4354 commit 737b21f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,9 @@ object ScalaReflection extends ScalaReflection {
"cannot be used as field name\n" + walkedTypePath.mkString("\n"))
}

// we know primitive type takes only non-null, or
// we can infer correct nullability for struct's fieldValue by a guard
// using If(IsNull()) at the last line of this section
val returnNonNull = fieldType.typeSymbol.asClass.isPrimitive ||
definedByConstructorParams(fieldType)
val fieldValue = Invoke(inputObject, fieldName, dataTypeFor(fieldType),
returnNullable = !returnNonNull)
val fieldValue = Invoke(
AssertNotNull(inputObject, walkedTypePath), fieldName, dataTypeFor(fieldType),
returnNullable = !fieldType.typeSymbol.asClass.isPrimitive)
val clsName = getClassNameFromType(fieldType)
val newPath = s"""- field (class: "$clsName", name: "$fieldName")""" +: walkedTypePath
expressions.Literal(fieldName) :: serializerFor(fieldValue, fieldType, newPath) :: Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class ExpressionEncoderSuite extends PlanTest with AnalysisTest {
encodeDecodeTest(
ReferenceValueClass(ReferenceValueClass.Container(1)), "reference value class")

encodeDecodeTest(Option(31), "option of int")
encodeDecodeTest(Option.empty[Int], "empty option of int")
encodeDecodeTest(Option("abc"), "option of string")
encodeDecodeTest(Option.empty[String], "empty option of string")

productTest(("UDT", new ExamplePoint(0.1, 0.2)))

test("nullable of encoder schema") {
Expand Down Expand Up @@ -340,7 +345,7 @@ class ExpressionEncoderSuite extends PlanTest with AnalysisTest {

test("nullable of encoder serializer") {
def checkNullable[T: Encoder](nullable: Boolean): Unit = {
assert(encoderFor[T].serializer.map(_.nullable) === nullable)
assert(encoderFor[T].serializer.forall(_.nullable === nullable))
}

// test for flat encoders
Expand Down

0 comments on commit 737b21f

Please sign in to comment.