remove NULL columns in Spark SQL

前端 未结 2 711
误落风尘
误落风尘 2020-12-12 02:19

How to remove columns containing only null values from a table? Suppose I have a table -

SnapshotDate    CreationDate    Country Region  CloseDate   Probabi         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 02:51

    You can add custom udf, and it in Spark SQL.

    sqlContext.udf.register("ISNOTNULL", (str: String) => Option(str).getOrElse(""))
    

    And with Spark SQL you can do :

    SELECT ISNOTNULL(Probability) Probability, ISNOTNULL(BookingAmount) BookingAmount, ISNOTNULL(RevenueAmount) RevenueAmount FROM df
    

提交回复
热议问题