explode炸裂函数
package SparkSQL.fun
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
/**
* _1 _2
* zs 60-70-90
* ls 70-80-90
* 求zs和ls的总成绩 平均成绩
* _1 _2
* zs 60
* zs 70
* zs 90
* ls 70
* ls 80
* ls 90
*/
object ExplodeCode {
def main(args: Array[String]): Unit = {
val sparkConf = new SparkConf().setAppName("func").setMaster("local[*]")
val ss = SparkSession.builder().config(sparkConf).getOrCreate()
val frame = ss.createDataFrame(Array(
("zs", "60-70-90"),
("ls", "70-80-90")
))
frame.createTempView("score")
frame.printSchema()
val frame1 = ss.sql("select score._1, ss.tt from score lateral view explode(split(_2, '-')) ss as tt")
frame1.show()
ss.stop()
}
}
本文来自博客园,作者:jsqup,转载请注明原文链接:https://www.cnblogs.com/jsqup/p/16659552.html