将 DStream[java.util.Date] 转换为 DStream[String]
Convert DStream[java.util.Date] to DStream[String]
我正在尝试合并两个 Dstreams:
val statuses = tweets.map(status => status.getText())
val users = tweets.map(status => status.getUser())
val Dates = tweets.map(status => status.getCreatedAt())
(statuses. union(Dates)).print
但我收到类型不匹配的错误消息:
Found: org.apache.spark.streaming.dstream.DStream[java.util.Date]
Required: org.apache.spark.streaming.dstream.DStream[String]
如何进行转换?
试试这个
val Dates = tweets.map(status => status.getCreatedAt.toString)
或者如果您需要特定格式
val format = new SimpleDateFormat("yyyy-MM-dd")
val Dates = tweets.map(status => format.format(status.getCreatedAt))
我正在尝试合并两个 Dstreams:
val statuses = tweets.map(status => status.getText())
val users = tweets.map(status => status.getUser())
val Dates = tweets.map(status => status.getCreatedAt())
(statuses. union(Dates)).print
但我收到类型不匹配的错误消息:
Found: org.apache.spark.streaming.dstream.DStream[java.util.Date]
Required: org.apache.spark.streaming.dstream.DStream[String]
如何进行转换?
试试这个
val Dates = tweets.map(status => status.getCreatedAt.toString)
或者如果您需要特定格式
val format = new SimpleDateFormat("yyyy-MM-dd")
val Dates = tweets.map(status => format.format(status.getCreatedAt))