【问题标题】:spark read contents of zip file in HDFSspark读取HDFS中zip文件的内容
【发布时间】:2018-08-24 12:37:41
【问题描述】:

我正在尝试从 zip 文件中读取数据

可以读取整个文本文件如下

val f = sc.wholeTextFiles("hdfs://")

但不知道如何读取 zip 文件中的文本数据

有没有什么办法,如果有请告诉我。

【问题讨论】:

标签: scala apache-spark spark-submit spark-shell


【解决方案1】:

您可以使用 newAPIHadoopFile 命令从 zipFile 创建 RDD。

import com.cotdp.hadoop.ZipFileInputFormat
import org.apache.hadoop.io.BytesWritable
import org.apache.hadoop.io.Text
import org.apache.hadoop.mapreduce.Job

val zipFileRDD = sc.newAPIHadoopFile(
        "hdfs://tmp/sample_zip/LoanStats3a.csv.zip",
        classOf[ZipFileInputFormat],
        classOf[Text],
        classOf[BytesWritable],
        new Job().getConfiguration())
println("The file contents are: " + zipFileRDD.map(s => new String(s._2.getBytes())).first())

【讨论】:

  • 非常感谢,这正是我正在研究的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-18
  • 1970-01-01
  • 1970-01-01
  • 2021-06-18
  • 2012-02-26
相关资源
最近更新 更多