Lisa
Lisa

Reputation: 3181

Convert DStream[java.util.Date] to DStream[String]

I'm trying to union two 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

But I'm getting an error that there is a mismatch in types:

Found: org.apache.spark.streaming.dstream.DStream[java.util.Date]

Required: org.apache.spark.streaming.dstream.DStream[String]

How can I do the conversion?

Upvotes: 0

Views: 406

Answers (1)

Marek Adamek
Marek Adamek

Reputation: 520

try this

val Dates = tweets.map(status => status.getCreatedAt.toString)

or if you want specific format

val format = new SimpleDateFormat("yyyy-MM-dd")
val Dates = tweets.map(status => format.format(status.getCreatedAt))

Upvotes: 2

Related Questions