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()
}
}
标签:函数,val,炸裂,explode,ss,ls,70,90,zs 来源: https://www.cnblogs.com/jsqup/p/16659552.html