How to validate date format in a dataframe column in spark scala

前端 未结 3 1309
栀梦
栀梦 2021-01-20 05:56

I have a dataframe with one DateTime column and many other columns.

All I wanted to do is parse this DateTime column value and check if the format is \"yyyy-MM

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 06:33

    Use option("dateFormat", "MM/dd/yyyy") to validate date field in dataframe.It will discard the invalid rows.

     val df=spark.read.format("csv").option("header", "false").
                option("dateFormat", "MM/dd/yyyy").
                schema(schema).load("D:/cca175/data/emp.csv")
    

提交回复
热议问题