Spark Scala Streaming CSV

Levi Source

I am new in Spark/Scala. I know how to load CSV files:"csv")

and how to read text streams and file streams:

    scc.fileStream[LongWritable, Text, TextInputFormat](...)

but how to read text stream in CSV format? Thanks, Levi



answered 2 years ago Sudheer Palyam #1

Here you go:

val ssc = new StreamingContext(sparkConf, Seconds(5))

    // Create the FileInputDStream on the directory
    val lines = ssc.textFileStream("file:///C:/foo/bar")

    lines.foreachRDD(rdd => {
        if (!rdd.isEmpty()) {
          println("RDD row count: " + rdd.count())
         // Now you can convert this RDD to DataFrame/DataSet and perform business logic.  



answered 1 year ago Naman Agarwal #2

You can stream your Csv file easily by using spark 2.2 structured streaming.

You can refer here

comments powered by Disqus