title: Scala convert WrappedArray or Array[Any] to Array[String]
body: <p>I've been trying to convert an RDD to a dataframe. For that, the types need to be defined and not Any. I'm using spark MLLib PrefixSpan, that's where freqSequence.sequence is from. I start with a dataframe that contains Session_IDs, views and purchases as String-Arrays:</p>
  
  <pre><code>viewsPurchasesGrouped: org.apache.spark.sql.DataFrame =
    [session_id: decimal(29,0), view_product_ids: array[string], purchase_product_ids: array[string]]
  </code></pre>
  
  <p>I then calculate frequent patterns and need them in a dataframe so I can write them to a Hive table.</p>
  
  <pre><code>val viewsPurchasesRddString = viewsPurchasesGrouped.map( row =&gt; Array(Array(row(1)), Array(row(2)) ))
  
  val prefixSpan = new PrefixSpan()
    .setMinSupport(0.001)
    .setMaxPatternLength(2)
  
  val model = prefixSpan.run(viewsPurchasesRddString)
  
  val freqSequencesRdd = sc.parallelize(model.freqSequences.collect())
  
  case class FreqSequences(views: Array[String], purchases: Array[String], support: Long)
  
  val viewsPurchasesDf = freqSequencesRdd.map( fs =&gt;
    {   
    val views = fs.sequence(0)(0)
    val purchases = fs.sequence(1)(0)
    val freq = fs.freq
    FreqSequences(views, purchases, freq)
    }
  )
  viewsPurchasesDf.toDF() // optional
  </code></pre>
  
  <p>When I try to run this, views and purchases are "Any" instead of "Array[String]". I've desperately tried to convert them around, but the best I get is Array[Any]. I think I need to map the contents to a String, I've tried e.g. this: <a href="https://stackoverflow.com/questions/40627610/how-to-get-an-element-in-wrappedarray-result-of-dataset-selectx-collect?rq=1">How to get an element in WrappedArray: result of Dataset.select(&quot;x&quot;).collect()?</a> and this: <a href="https://stackoverflow.com/questions/41904744/how-to-cast-a-wrappedarraywrappedarrayfloat-to-arrayarrayfloat-in-spark">How to cast a WrappedArray[WrappedArray[Float]] to Array[Array[Float]] in spark (scala)</a> and thousands of other Stackoverflow questions...</p>
  
  <p>I really don't know how to solve this. I guess I'm already converting the initial dataframe/RDD to much, but can't understand where.</p>