title: Convert Spark Row to typed Array of Doubles
body: <p>I am using Spark 1.3.1 with Hive and have a row object that is a long series of doubles to be passed to a Vecors.dense constructor, however when I convert a Row to an array via </p>
  
  <pre><code>SparkDataFrame.map{r =&gt; r.toSeq.toArray} 
  </code></pre>
  
  <p>All type information is lost and I get back an array of [Any] type. I am unable to cast this object to double using </p>
  
  <pre><code>SparkDataFrame.map{r =&gt; 
    val array = r.toSeq.toArray 
    array.map(_.toDouble) 
  } // Fails with value toDouble is not a member of any
  </code></pre>
  
  <p>as does </p>
  
  <pre><code>SparkDataFrame.map{r =&gt; 
        val array = r.toSeq.toArray 
        array.map(_.asInstanceOf[Double]) 
      } // Fails with java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double 
  </code></pre>
  
  <p>I see that the Row object has an API that supports getting specific elements as a type, via: </p>
  
  <pre><code>SparkDataFrame.map{r =&gt; 
    r.getDouble(5)}  
  </code></pre>
  
  <p>However event this fails with java.lang.Integer cannot be cast to java.lang.Double</p>
  
  <p>The only work around I have found is the following: </p>
  
  <pre><code> SparkDataFrame.map{r =&gt; 
    doubleArray = Array(r.getInt(5).toDouble, r.getInt(6).toDouble) 
    Vectors.dense(doubleArray) } 
  </code></pre>
  
  <p>However this is prohibitively tedious when index 5 through 1000 need to be converted to an array of doubles. </p>
  
  <p>Any way around explicitly indexing the row object? </p>