不支持 java.util.Date
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31312108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.util.Date is not supported
提问by yeyimilk
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
回答by Saqib Rezwan
At first convert java.util.Dateto java.sql.Date. Then run your sql with the data of java.sql.Date. Sample code :
首先将java.util.Date转换为java.sql.Date。然后使用java.sql.Date的数据运行您的 sql 。示例代码:
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
. I did not try it yet, but generally Timestamp
is better than Date
.
更新:AndreHolzner 建议使用java.sql.Timestamp
. 我还没有尝试过,但总体Timestamp
来说比Date
.