scala - value saveAsTextFile is not a member of org.apache.spark.streaming.dstream.DStream[(String, Long)] -
i try save wordcount result in file.
val wordcounts = words.map(x => (x, 1l)).reducebykey(_ + _) wordcounts.saveastextfile("/home/hadoop/datafile1") but showing
value saveastextfile not member of org.apache.spark.streaming.dstream.dstream[(string, long)] [error] wordcounts.saveastextfile("/home/hadoop/datafile1") i using spark 2.1. show 1 answer suggesting old spark version.but want in spark 2.1. thanks.
you using method defined rdd on dstream.
this method on rdd:
def saveastextfile(path: string): unit ...with description "save rdd text file, using string representations of elements."
this method on dstream:
saveastextfiles(prefix: string, suffix: string = ""): unit ...with description "save each rdd in dstream @ text file, using string representation of elements. file name @ each batch interval generated based on prefix , suffix: "prefix-time_in_ms.suffix."
so method signatures different--both in name , parameters.
in code, wordcounts apparently dstream, not have saveastextfile method.
however, feeling confusing abstractions , want write individual rdds contained in dstream microbatch. that:
counts.foreachrdd { rdd => ... rdd.saveastextfiles(s"/home/hadoop/datafile-$timestamp") }
Comments
Post a Comment