While working in a sparkSql UDAF function I find some of my input columns turns from null to 0 unexpectedly.
With some REPL practice, it turns out the behavior is of scala 2.10.5.
code snap as bellow
import scala.collection.mutable
val wa = mutable.WrappedArray.make[Int](Array(null, null))
wa
wa(1)
Would you please someone family with scala help explain why and what is happening behind the hood?
You called method
make[Int]which is declared as follows:In your case
xisArray(null, null)which is instance ofArray[AnyRef], somakecreates and returns instance of classofRef[AnyRef]which is declared as:When you call
wa(1), you call methodapplyof this class and since your second element isnullit will return0, becausenull.asInstanceOf[Int]returns0.