Access multi-dimensional WrappedArray elements in Java using Spark SQL Row -
i have following schema:
geometry: struct (nullable = true) -- coordinates: array (nullable = true) -- element: array (containsnull = true) -- element: array (containsnull = true) -- element: double (containsnull = true) in java, how can access double element spark sql row?
the furthest can seem is: row.getstruct(0).getlist(0).
thanks!
in scala works, leave translate java:
import org.apache.spark.sql.{row, sqlcontext} import org.apache.spark.{sparkconf, sparkcontext} import scala.collection.mutable.wrappedarray object demo { case class mystruct(coordinates:array[array[array[double]]]) case class myrow(struct:mystruct) def main(args: array[string]): unit = { val sc = new sparkcontext(new sparkconf().setappname("demo").setmaster("local[*]")) val sqlcontext = new sqlcontext(sc) import sqlcontext.implicits._ val data = myrow(mystruct(array(array(array(1.0))))) val df= sc.parallelize(seq(data)).todf() // first entry (row) val row = df.collect()(0) val arr = row.getas[row](0).getas[wrappedarray[wrappedarray[wrappedarray[double]]]](0) //access element val res = arr(0)(0)(0) println(res) // 1.0 } }
Comments
Post a Comment