File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed
main/scala/org/apache/spark/sql/catalyst
test/scala/org/apache/spark/sql/catalyst/encoders Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ object RowEncoder {
4848 private def extractorsFor (
4949 inputObject : Expression ,
5050 inputType : DataType ): Expression = inputType match {
51- case BooleanType | ByteType | ShortType | IntegerType | LongType |
51+ case NullType | BooleanType | ByteType | ShortType | IntegerType | LongType |
5252 FloatType | DoubleType | BinaryType => inputObject
5353
5454 case udt : UserDefinedType [_] =>
@@ -143,6 +143,7 @@ object RowEncoder {
143143 case _ : MapType => ObjectType (classOf [scala.collection.Map [_, _]])
144144 case _ : StructType => ObjectType (classOf [Row ])
145145 case udt : UserDefinedType [_] => ObjectType (udt.userClass)
146+ case _ : NullType => ObjectType (classOf [java.lang.Object ])
146147 }
147148
148149 private def constructorFor (schema : StructType ): Expression = {
@@ -158,7 +159,7 @@ object RowEncoder {
158159 }
159160
160161 private def constructorFor (input : Expression ): Expression = input.dataType match {
161- case BooleanType | ByteType | ShortType | IntegerType | LongType |
162+ case NullType | BooleanType | ByteType | ShortType | IntegerType | LongType |
162163 FloatType | DoubleType | BinaryType => input
163164
164165 case udt : UserDefinedType [_] =>
Original file line number Diff line number Diff line change @@ -369,6 +369,9 @@ case class MapObjects(
369369 private lazy val completeFunction = function(loopAttribute)
370370
371371 private def itemAccessorMethod (dataType : DataType ): String => String = dataType match {
372+ case NullType =>
373+ val nullTypeClassName = NullType .getClass.getName + " .MODULE$"
374+ (i : String ) => s " .get( $i, $nullTypeClassName) "
372375 case IntegerType => (i : String ) => s " .getInt( $i) "
373376 case LongType => (i : String ) => s " .getLong( $i) "
374377 case FloatType => (i : String ) => s " .getFloat( $i) "
Original file line number Diff line number Diff line change @@ -80,11 +80,13 @@ class RowEncoderSuite extends SparkFunSuite {
8080 private val structOfString = new StructType ().add(" str" , StringType )
8181 private val structOfUDT = new StructType ().add(" udt" , new ExamplePointUDT , false )
8282 private val arrayOfString = ArrayType (StringType )
83+ private val arrayOfNull = ArrayType (NullType )
8384 private val mapOfString = MapType (StringType , StringType )
8485 private val arrayOfUDT = ArrayType (new ExamplePointUDT , false )
8586
8687 encodeDecodeTest(
8788 new StructType ()
89+ .add(" null" , NullType )
8890 .add(" boolean" , BooleanType )
8991 .add(" byte" , ByteType )
9092 .add(" short" , ShortType )
@@ -101,6 +103,7 @@ class RowEncoderSuite extends SparkFunSuite {
101103
102104 encodeDecodeTest(
103105 new StructType ()
106+ .add(" arrayOfNull" , arrayOfNull)
104107 .add(" arrayOfString" , arrayOfString)
105108 .add(" arrayOfArrayOfString" , ArrayType (arrayOfString))
106109 .add(" arrayOfArrayOfInt" , ArrayType (ArrayType (IntegerType )))
You can’t perform that action at this time.
0 commit comments