@@ -74,12 +74,20 @@ class UnsafeRowConverterSuite extends FunSuite with Matchers {
7474 }
7575
7676 test(" null handling" ) {
77- val fieldTypes : Array [DataType ] = Array (IntegerType , LongType , FloatType , DoubleType )
77+ val fieldTypes : Array [DataType ] = Array (
78+ NullType ,
79+ BooleanType ,
80+ ByteType ,
81+ ShortType ,
82+ IntegerType ,
83+ LongType ,
84+ FloatType ,
85+ DoubleType )
7886 val converter = new UnsafeRowConverter (fieldTypes)
7987
8088 val rowWithAllNullColumns : Row = {
8189 val r = new SpecificMutableRow (fieldTypes)
82- for (i <- 0 to 3 ) {
90+ for (i <- 0 to fieldTypes.length - 1 ) {
8391 r.setNullAt(i)
8492 }
8593 r
@@ -94,23 +102,30 @@ class UnsafeRowConverterSuite extends FunSuite with Matchers {
94102 val createdFromNull = new UnsafeRow ()
95103 createdFromNull.pointTo(
96104 createdFromNullBuffer, PlatformDependent .LONG_ARRAY_OFFSET , fieldTypes.length, null )
97- for (i <- 0 to 3 ) {
105+ for (i <- 0 to fieldTypes.length - 1 ) {
98106 assert(createdFromNull.isNullAt(i))
99107 }
100- createdFromNull.getInt(0 ) should be (0 )
101- createdFromNull.getLong(1 ) should be (0 )
102- assert(java.lang.Float .isNaN(createdFromNull.getFloat(2 )))
103- assert(java.lang.Double .isNaN(createdFromNull.getFloat(3 )))
108+ createdFromNull.getBoolean(1 ) should be (false )
109+ createdFromNull.getByte(2 ) should be (0 )
110+ createdFromNull.getShort(3 ) should be (0 )
111+ createdFromNull.getInt(4 ) should be (0 )
112+ createdFromNull.getLong(5 ) should be (0 )
113+ assert(java.lang.Float .isNaN(createdFromNull.getFloat(6 )))
114+ assert(java.lang.Double .isNaN(createdFromNull.getFloat(7 )))
104115
105116 // If we have an UnsafeRow with columns that are initially non-null and we null out those
106117 // columns, then the serialized row representation should be identical to what we would get by
107118 // creating an entirely null row via the converter
108119 val rowWithNoNullColumns : Row = {
109120 val r = new SpecificMutableRow (fieldTypes)
110- r.setInt(0 , 100 )
111- r.setLong(1 , 200 )
112- r.setFloat(2 , 300 )
113- r.setDouble(3 , 400 )
121+ r.setNullAt(0 )
122+ r.setBoolean(1 , false )
123+ r.setByte(2 , 20 )
124+ r.setShort(3 , 30 )
125+ r.setInt(4 , 400 )
126+ r.setLong(5 , 500 )
127+ r.setFloat(6 , 600 )
128+ r.setDouble(7 , 700 )
114129 r
115130 }
116131 val setToNullAfterCreationBuffer : Array [Long ] = new Array [Long ](sizeRequired / 8 )
@@ -119,12 +134,17 @@ class UnsafeRowConverterSuite extends FunSuite with Matchers {
119134 val setToNullAfterCreation = new UnsafeRow ()
120135 setToNullAfterCreation.pointTo(
121136 setToNullAfterCreationBuffer, PlatformDependent .LONG_ARRAY_OFFSET , fieldTypes.length, null )
122- setToNullAfterCreation.getInt(0 ) should be (rowWithNoNullColumns.getInt(0 ))
123- setToNullAfterCreation.getLong(1 ) should be (rowWithNoNullColumns.getLong(1 ))
124- setToNullAfterCreation.getFloat(2 ) should be (rowWithNoNullColumns.getFloat(2 ))
125- setToNullAfterCreation.getDouble(3 ) should be (rowWithNoNullColumns.getDouble(3 ))
126137
127- for (i <- 0 to 3 ) {
138+ setToNullAfterCreation.isNullAt(0 ) should be (rowWithNoNullColumns.isNullAt(0 ))
139+ setToNullAfterCreation.getBoolean(1 ) should be (rowWithNoNullColumns.getBoolean(1 ))
140+ setToNullAfterCreation.getByte(2 ) should be (rowWithNoNullColumns.getByte(2 ))
141+ setToNullAfterCreation.getShort(3 ) should be (rowWithNoNullColumns.getShort(3 ))
142+ setToNullAfterCreation.getInt(4 ) should be (rowWithNoNullColumns.getInt(4 ))
143+ setToNullAfterCreation.getLong(5 ) should be (rowWithNoNullColumns.getLong(5 ))
144+ setToNullAfterCreation.getFloat(6 ) should be (rowWithNoNullColumns.getFloat(6 ))
145+ setToNullAfterCreation.getDouble(7 ) should be (rowWithNoNullColumns.getDouble(7 ))
146+
147+ for (i <- 0 to fieldTypes.length - 1 ) {
128148 setToNullAfterCreation.setNullAt(i)
129149 }
130150 assert(Arrays .equals(createdFromNullBuffer, setToNullAfterCreationBuffer))
0 commit comments