Spark Scala Streaming CSV

前端 未结 2 1829
耶瑟儿~
耶瑟儿~ 2021-02-10 20:16

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

    sqlContext.read.format(\"csv\")

and how to read text streams and file streams:

相关标签:
2条回答
  • 2021-02-10 20:51

    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.  
    
            }
          }
        })
    
        ssc.start()
        ssc.awaitTermination()
      } 
    
    0 讨论(0)
  • 2021-02-10 20:58

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

    You can refer here

    0 讨论(0)
提交回复
热议问题