Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for date validity in spark sql

Tags:

apache-spark

Is it possible to check if a date(yyymmdd) is valid in spark SQL? I have tried the following:

TO_DATE(CAST(UNIX_TIMESTAMP(CAST(UNIX_TIMESTAMP(colname, 'yyyymmdd') AS  TIMESTAMP))) IS NOT NULL

Thanks, Bharath

like image 444
Bharath Avatar asked Jan 25 '26 05:01

Bharath


1 Answers

You could try

set spark.sql.legacy.timeParserPolicy=CORRECTED;

before the select. This policy allows invalid dates to be casted as null.

Hope it helps.

like image 109
Miquel Avatar answered Jan 28 '26 06:01

Miquel