【问题标题】:Sample java spark program to read and load json file as a RDD示例 java spark 程序以读取和加载 json 文件作为 RDD
【发布时间】:2015-09-12 18:26:48
【问题描述】:

我正在寻找可以在 spark 中读取本地 json 文件的示例 java 程序。

【问题讨论】:

标签: json apache-spark


【解决方案1】:

您必须创建自己的特定 jsonFormat 类,在 spark sc.textFile 中,您必须创建该类的对象并返回这些对象的 rdd,否则您将需要实现 json 记录读取器,它将实现此接口 RecordReader [键,值]。

【讨论】:

    【解决方案2】:

    该示例是http://spark.apache.org/docs/latest/sql-programming-guide.html#json-datasets 文档的一部分:

    // sc is an existing JavaSparkContext.
    SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
    
    // A JSON dataset is pointed to by path.
    // The path can be either a single text file or a directory storing text files.
    DataFrame people = sqlContext.read.json("examples/src/main/resources/people.json");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-13
      • 2015-06-22
      • 2022-08-19
      • 2021-05-26
      • 2020-08-18
      • 1970-01-01
      • 2021-08-25
      • 1970-01-01
      相关资源
      最近更新 更多