[英]java.util.Date is not supported
I want to write RDD
to MYSQL
, which RDD
contains java.util.Date
type.我想将RDD
写入MYSQL
,其中RDD
包含java.util.Date
类型。
rdd.map(f=> FeatureData(
f.get("name").toString,
f.get("value").toString.toDouble,
f.get("time").asInstanceOf[Date],
f.get("period").toString))
.toDF()
In this RDD
the key of time
's value type is also java.util.Date
and it just get the error of [See nested exception: java.lang.UnsupportedOperationException: Schema for type java.util.Date is not supported
在这个RDD
中, time
的值类型的键也是java.util.Date
,它只是得到错误[See nested exception: java.lang.UnsupportedOperationException: Schema for type java.util.Date is not supported
At first convert java.util.Date to java.sql.Date .首先将java.util.Date转换为java.sql.Date 。 Then run your sql with the data of java.sql.Date .然后使用java.sql.Date的数据运行您的 sql。 Sample code :示例代码:
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
Update: AndreHolzner suggested to use java.sql.Timestamp
.更新: AndreHolzner 建议使用java.sql.Timestamp
。 I did not try it yet, but generally Timestamp
is better than Date
.我还没有尝试过,但通常Timestamp
比Date
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.