不支持 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 RDDto MYSQL, which RDDcontains java.util.Datetype.
我想写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 RDDthe key of time's value type is also java.util.Dateand 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 Timestampis better than Date.
更新:AndreHolzner 建议使用java.sql.Timestamp. 我还没有尝试过,但总体Timestamp来说比Date.

