how to populate select clause of dataframe dynamically? giving AnalysisException

前端 未结 3 895
终归单人心
终归单人心 2020-12-12 06:12

I am Using spark-sql 2.4.1 and java 8.

 val country_df = Seq(
    (\"us\",2001),
    (\"fr\",2002),
    (\"jp\",2002),
    (\"in\",2001),
    (\"fr\",2003),
         


        
3条回答
  •  庸人自扰
    2020-12-12 06:34

    Using pivot you can get the values as column names directly like this:

    val selectCols = col_df.groupBy().pivot($"country").agg(lit(null)).columns
    data_df.select(selectCols.head, selectCols.tail: _*)
    

提交回复
热议问题