Spark DataFrame到MySql时间戳错误

时间:2017-02-16 13:14:59

标签: apache-spark

我有架构

的数据框架
id : long (nullable = false)
DDate: timestamp (nullable = true)
EDate: timestamp (nullable = true)
B1Date: timestamp (nullable = true)
B2Date: timestamp (nullable = true)
B3Date: timestamp (nullable = true)

当我使用df.write.jdbc(url," DF",prop)我收到错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Invalid default  value for 'DDate'
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI    mpl.java:62)
at      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorA    ccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

对于每个时间戳我都遇到同样的问题如何解决问题

1 个答案:

答案 0 :(得分:0)

timestamp type更改为java.sql.Timestamp

ex:case class DfWithTs (ts: sent_at: java.sql.Timestamp, value: Int)

val ds = df.as[DfWithTs]

然后编写它,这将与jdbc

一起使用