将DStream [java.util.Date]转换为DStream [String]

时间:2015-04-03 03:17:38

标签: scala apache-spark twitter4j spark-streaming

我试图联合两个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]

我该如何进行转换?

1 个答案:

答案 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))