我试图联合两个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]
我该如何进行转换?
答案 0 :(得分:2)
试试这个
val Dates = tweets.map(status => status.getCreatedAt.toString)
或者如果你想要特定的格式
val format = new SimpleDateFormat("yyyy-MM-dd")
val Dates = tweets.map(status => format.format(status.getCreatedAt))