Spark Scala Streaming CSV

前端 未结 2 1830
耶瑟儿~
耶瑟儿~ 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()
      } 
    

提交回复
热议问题