spark sql select中传入可变参数列,并拆解动态数组列
记录下对某个数组列进行拆解时,如何动态传入可变的参数问题
原来的静态写入形式:
val resultAllDF = resultDF.select(
col("wCycle").getItem("starttime").as("starttime"),
col("wCycle").getItem("endtime").as("endtime"),
col("wCycle").getItem("level").as("level"))
其中的参数可能经常变化,而且需要可配置化,所以改成以下方式传入:
val list = List("starttime",
"endtime",
"level"
).map(x=>col("wCycle").getItem(x).as(x))
resultDF.select(list: _*).show(false)
其中 wCycle列是一个Map列,可以定义个List来动态组织Map列里的内容,这样就可以把这个Map列配置化的拆分成多个单独的列了。