I'm using collect_list to group some column like:
val res = hiveContext.sql("SELECT date, time, collect_list(id) AS id_list FROM table1 GROUP BY date, time")
The id_list returns as a WrappedArray:
WrappedArray(1,2,1,2)
WrappedArray(4,3,4)
WrappedArray(6,7,6,7,6)
However I'm passing the id_list into myFunc that takes an Array[Double] as input:
def myFunc(xs: Array[Double]) {...}
My question is how can I call myFunc correctly to parse the id_list. I'm having something like:
res.collect.foreach(x => myFunc(x(2)))
but it's giving me an type mismatch; found : Any required: Array[Double] error.
What is the correct way to implicitly convert the WrappedArray into an Array or how can I call myFunc in an optimized way?
Thanks!
scala.collection.mutable.WrappedArrayhas a defarray: Array[T], so invoke like thisres.collect.foreach(x => myFunc(x(2).array))may solve you problem.x(2)in typeAnybe recognized as an Array first instead of converting it directly.