2017-02-08 5 views
0

私はsparkを使用してhbaseからデータを読み込んでいますが、データフレームに日付の列があり、データフィールドのほとんどが破損しています.10-20176-7など。どのようにそれらをチェックし、いくつかのデフォルト値私はさらに処理する前に。スカラーのデータフレームの日付列の検証?

ありがとうございました。

+2

あなたがこれまでに試したかを示すことができますか? ... –

+0

で始まるコードを入力して、[verify date](http://stackoverflow.com/a/40510441/647053)の既存の回答を確認し、無効な日付をデフォルト値に置き換えることができます。 –

+0

@RamGhadiyaram、私は上記のロジックを実装し、有効な日付のレコードを持っていますが、データフレームにゼロレコードを取得します。 – GSR

答えて

0

スタックをトレースするとエラーが発生します。

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) 

LocalDateTimeの代わりにLocalDateを使用して問題を解決しました。以下は、使用されたサンプルコードです。

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 
} 

}