在scala中验证数据帧中的日期列?

在scala中验证数据帧中的日期列?,scala,apache-spark,dataframe,hbase,Scala,Apache Spark,Dataframe,Hbase,我正在使用spark从hbase读取数据,数据框中有date列,几乎没有数据字段已损坏。如10-20176-7等。在进一步处理之前,我如何检查这些数据并用一些默认值替换它们 谢谢。我跟踪了错误,下面是错误 Exception in thread "main" java.time.format.DateTimeParseException: Text '20140218' could not be parsed: Unable to obtain LocalDateTime from Temp

我正在使用spark从hbase读取数据,数据框中有date列,几乎没有数据字段已损坏。如10-20176-7等。在进一步处理之前,我如何检查这些数据并用一些默认值替换它们


谢谢。

我跟踪了错误,下面是错误

Exception in thread "main" java.time.format.DateTimeParseException: 
Text '20140218' could not be parsed: 
Unable to obtain LocalDateTime from TemporalAccessor: 
{},ISO resolved to 2014-02-18 of type java.time.format.Parsed
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1918)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1853)
at java.time.LocalDateTime.parse(LocalDateTime.java:492)
所以我用LocalDate而不是LocalDateTime来解决这个问题。下面是使用的示例代码

def validateDfsdate(row: Row): Boolean = try {

val a = java.time.LocalDate.parse(row.getString(40), java.time.format.DateTimeFormatter.ofPattern(DATE_TIME_FORMAT))

true

} catch {
case ex: java.time.format.DateTimeParseException => {
  println("Exception : " + ex)
  false
}

}

您能展示一下您迄今为止所做的尝试吗?给我们一些代码开始…你可以检查现有答案,然后用默认值替换无效日期。@RamGhadiyaram,我实现了上述逻辑,在数据帧中得到零记录,尽管我有有效日期的记录。可能是你的逻辑错误。Tzac已经问过代码片段在哪里?请在下面找到我正在使用的代码。val-spdfsdate\u validate=spdf2.filtervalidateDfsdate\val-DATE\u-TIME\u FORMAT=YYYY-MM-DD def-validateDfsdaterow:Row:Boolean=try{val a=java.TIME.LocalDateTime.parserow.getString40,java.TIME.FORMAT.DateTimeFormatter.ofPatternDATE\u-TIME\u-FORMAT true}catch{case ex:java.TIME.FORMAT.DateTimeParseException=>{false}