title: Combining entire column of Arrays into one Array
body: <p>I have this dataframe and I'd like to combine all the arrays,
  in the data column, into one big array, separate from the DataFrame.</p>
  
  <p>Scala and DataFrame API are still pretty new to me, but I gave it a shot:</p>
  
  <pre><code>case class Tile(data: Array[Int])
  
  val ta = Tile(Array(1,2))
  val tb = Tile(Array(3,4))
  val tc = Tile(Array(5,6))
  
  df =  ListBuffer(ta,tb,tc).toDF()
  
  // Combine contents of DF into one array
  val result = new Array[Int](6)
  var offset = 0
  val combine = (t: WrappedArray[Int]) =&gt; {
      Array.copy(t, 0, result, offset, t.length)
      offset += t.length
  }
  
  df.foreach(r =&gt; combine(r(0).asInstanceOf[WrappedArray[Int]]))
  
  df.show()
  +------+
  |  data|
  +------+
  |[1, 1]|
  |[2, 2]|
  |[3, 3]|
  +------+
  </code></pre>
  
  <p>When I run this, I get the following error:</p>
  
  <pre><code>16/08/23 11:21:32 ERROR executor.Executor: Exception in task 0.0 in stage 17.0 (TID 17)
  scala.MatchError: WrappedArray(1, 1) (of class scala.collection.mutable.WrappedArray$ofRef)
  at scala.runtime.ScalaRunTime$.array_apply(ScalaRunTime.scala:71)
  at scala.Array$.slowcopy(Array.scala:81)
  at scala.Array$.copy(Array.scala:107)
  at $line150.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:32)
  at $line150.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:31)
  at $line190.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:46)
  at $line190.$read$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$1.apply(&lt;console&gt;:46)
  at scala.collection.Iterator$class.foreach(Iterator.scala:727)
  at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
  at org.apache.spark.rdd.RDD$$anonfun$foreach$1$$anonfun$apply$32.apply(RDD.scala:912)
  at org.apache.spark.rdd.RDD$$anonfun$foreach$1$$anonfun$apply$32.apply(RDD.scala:912)
  at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1869)
  at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1869)
  at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
  at org.apache.spark.scheduler.Task.run(Task.scala:89)
  at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:74
  </code></pre>
  
  <p>Can anyone point me in the right direction? Thanks!</p>