@@ -191,39 +191,39 @@ trait Row extends Serializable {
191191 * @throws ClassCastException when data type does not match.
192192 * @throws NullPointerException when value is null.
193193 */
194- def getBoolean (i : Int ): Boolean = getAs [Boolean ](i)
194+ def getBoolean (i : Int ): Boolean = getAnyValAs [Boolean ](i)
195195
196196 /**
197197 * Returns the value at position i as a primitive byte.
198198 *
199199 * @throws ClassCastException when data type does not match.
200200 * @throws NullPointerException when value is null.
201201 */
202- def getByte (i : Int ): Byte = getAs [Byte ](i)
202+ def getByte (i : Int ): Byte = getAnyValAs [Byte ](i)
203203
204204 /**
205205 * Returns the value at position i as a primitive short.
206206 *
207207 * @throws ClassCastException when data type does not match.
208208 * @throws NullPointerException when value is null.
209209 */
210- def getShort (i : Int ): Short = getAs [Short ](i)
210+ def getShort (i : Int ): Short = getAnyValAs [Short ](i)
211211
212212 /**
213213 * Returns the value at position i as a primitive int.
214214 *
215215 * @throws ClassCastException when data type does not match.
216216 * @throws NullPointerException when value is null.
217217 */
218- def getInt (i : Int ): Int = getAs [Int ](i)
218+ def getInt (i : Int ): Int = getAnyValAs [Int ](i)
219219
220220 /**
221221 * Returns the value at position i as a primitive long.
222222 *
223223 * @throws ClassCastException when data type does not match.
224224 * @throws NullPointerException when value is null.
225225 */
226- def getLong (i : Int ): Long = getAs [Long ](i)
226+ def getLong (i : Int ): Long = getAnyValAs [Long ](i)
227227
228228 /**
229229 * Returns the value at position i as a primitive float.
@@ -232,21 +232,20 @@ trait Row extends Serializable {
232232 * @throws ClassCastException when data type does not match.
233233 * @throws NullPointerException when value is null.
234234 */
235- def getFloat (i : Int ): Float = getAs [Float ](i)
235+ def getFloat (i : Int ): Float = getAnyValAs [Float ](i)
236236
237237 /**
238238 * Returns the value at position i as a primitive double.
239239 *
240240 * @throws ClassCastException when data type does not match.
241241 * @throws NullPointerException when value is null.
242242 */
243- def getDouble (i : Int ): Double = getAs [Double ](i)
243+ def getDouble (i : Int ): Double = getAnyValAs [Double ](i)
244244
245245 /**
246246 * Returns the value at position i as a String object.
247247 *
248248 * @throws ClassCastException when data type does not match.
249- * @throws NullPointerException when value is null.
250249 */
251250 def getString (i : Int ): String = getAs[String ](i)
252251
@@ -310,13 +309,17 @@ trait Row extends Serializable {
310309
311310 /**
312311 * Returns the value at position i.
312+ * For primitive types if value is null it returns 'zero value' specific for primitive
313+ * ie. 0 for Int - use isNullAt to ensure that value is not null
313314 *
314315 * @throws ClassCastException when data type does not match.
315316 */
316317 def getAs [T ](i : Int ): T = get(i).asInstanceOf [T ]
317318
318319 /**
319320 * Returns the value of a given fieldName.
321+ * For primitive types if value is null it returns 'zero value' specific for primitive
322+ * ie. 0 for Int - use isNullAt to ensure that value is not null
320323 *
321324 * @throws UnsupportedOperationException when schema is not defined.
322325 * @throws IllegalArgumentException when fieldName do not exist.
@@ -336,6 +339,8 @@ trait Row extends Serializable {
336339
337340 /**
338341 * Returns a Map(name -> value) for the requested fieldNames
342+ * For primitive types if value is null it returns 'zero value' specific for primitive
343+ * ie. 0 for Int - use isNullAt to ensure that value is not null
339344 *
340345 * @throws UnsupportedOperationException when schema is not defined.
341346 * @throws IllegalArgumentException when fieldName do not exist.
@@ -450,4 +455,15 @@ trait Row extends Serializable {
450455 * start, end, and separator strings.
451456 */
452457 def mkString (start : String , sep : String , end : String ): String = toSeq.mkString(start, sep, end)
458+
459+ /**
460+ * Returns the value of a given fieldName.
461+ *
462+ * @throws UnsupportedOperationException when schema is not defined.
463+ * @throws ClassCastException when data type does not match.
464+ * @throws NullPointerException when value is null.
465+ */
466+ private def getAnyValAs [T <: AnyVal ](i : Int ): T =
467+ if (isNullAt(i)) throw new NullPointerException (s " Value at index $i in null " )
468+ else getAs[T ](i)
453469}
0 commit comments