【问题标题】:Spark Scala Streaming CSVSpark Scala 流式处理 CSV
【发布时间】:2016-09-28 07:36:11
【问题描述】:

我是 Spark/Scala 的新手。我知道如何加载 CSV 文件:

    sqlContext.read.format("csv")

以及如何读取文本流和文件流:

    scc.textFileStream("""file:///c:\path\filename""");
    scc.fileStream[LongWritable, Text, TextInputFormat](...)

但是如何阅读 CSV 格式的流 文本?谢谢,列维

【问题讨论】:

    标签: scala csv apache-spark spark-streaming


    【解决方案1】:

    给你:

    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()
      } 
    

    【讨论】:

      【解决方案2】:

      您可以使用 spark 2.2 结构化流式传输轻松流式传输您的 Csv 文件。

      您可以参考here

      【讨论】:

        猜你喜欢
        • 2018-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-20
        相关资源
        最近更新 更多