5
我在Scala中使用了Spark類庫。我創建使用Scala DataFrame:分解數組
val searchArr = Array(
StructField("log",IntegerType,true),
StructField("user", StructType(Array(
StructField("date",StringType,true),
StructField("ua",StringType,true),
StructField("ui",LongType,true))),true),
StructField("what",StructType(Array(
StructField("q1",ArrayType(IntegerType, true),true),
StructField("q2",ArrayType(IntegerType, true),true),
StructField("sid",StringType,true),
StructField("url",StringType,true))),true),
StructField("where",StructType(Array(
StructField("o1",IntegerType,true),
StructField("o2",IntegerType,true))),true)
)
val searchSt = new StructType(searchArr)
val searchData = sqlContext.jsonFile(searchPath, searchSt)
我現在是一個數據幀什麼爆炸現場what.q1,它應該包含整數數組,但文檔是有限的: http://spark.apache.org/docs/1.4.0/api/java/org/apache/spark/sql/DataFrame.html#explode(java.lang.String,%20java.lang.String,%20scala.Function1,%20scala.reflect.api.TypeTags.TypeTag)
到目前爲止,我嘗試了幾件沒有太多運氣的東西
val searchSplit = searchData.explode("q1", "rb")(q1 => q1.getList[Int](0).toArray())
任何想法/如何使用數組爆炸的例子?