Code:
val duration_dates = udf( (ci: Date, co: Date) => {
val miliseconds_per_day = 24*60*60*1000
val nDays = ( co.getTime() - ci.getTime() ) / miliseconds_per_day
(0L until nDays).map(i => new Date(ci.getTime() + i * miliseconds_per_day) )
}
)
我是一名Spark Scala編程的入門者,現在遇到一個問題,有一段prototype是udf的,現在執行報錯
App > Exception in thread "main" java.lang.UnsupportedOperationException: Schema for type java.util.Date is not supported
請幫忙看看哪里有問題,謝謝
uj5u.com熱心網友回復:
你好,針對你這個問題,我使用spark-shell試了下,確實如此。然后找了官方資料查了查,并且給出解決方案,如下。
解決方法:

原因:
Spark SQL and DataFrames support the following data types:
Datetime type
TimestampType: Represents values comprising values of fields year, month, day, hour, minute, and second.
DateType: Represents values comprising values of fields year, month, day.
TimestampType java.sql.Timestamp TimestampType
DateType java.sql.Date DateType
uj5u.com熱心網友回復:
補充一下,如果你要用到時分秒,請使用 java.sql.Timestamp轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/49088.html
標籤:Spark
