【问题标题】:How to read Gzipped file on Azure without (.gz) extension in Spark/Scala如何在 Azure 上读取 Gzipped 文件,无需 Spark/Scala 中的 (.gz) 扩展名
【发布时间】:2019-07-15 15:55:32
【问题描述】:

我有一个 Gzip 文件,在 Azure 上没有 .gz 扩展名。 路径:https://xxxx.blob.core.windows.net/xx/xx/0_2017/xxx/0/100103900

我想阅读 spark/scala 中的 gzip 压缩文件。我浏览了一些建议我使用 sc.binaryFiles() 但得到未解决的错误的帖子。

尝试过但没有成功

spark.read.option("header","true").option("inferSchema","true").textFile(newFollowersStartDatePath).show()

Sample output I am getting

我相信 spark 通过自动解压缩以 .gz 终止的文件来读取 gzip 文件。寻求帮助以读取未指定扩展名的 gzip 压缩文件。

预期输出将是一个 id 列表(一列)

1343423
2342342
2343232
2342343

【问题讨论】:

  • 您能否将您的输出作为文本发布在您的帖子中?
  • 添加了预期的输出。如果您需要更多详细信息,请告诉我。

标签: scala apache-spark


【解决方案1】:

使用binaryFiles 成功了

sparkSession.sparkContext.binaryFiles(filePath)
      .flatMap({ case (_, portableDataStream) =>
        val dataInputStream = new java.io.DataInputStream(
          new GZIPInputStream(portableDataStream.open))
        Iterator.continually( Try(dataInputStream.readLong())).takeWhile(result => {
          result match {
            case Success(_) => true
            case Failure(_) =>  dataInputStream.close()
              false
          }
        })
      }).flatMap(_.toOption).toDS
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    • 2019-01-31
    • 2021-01-20
    • 1970-01-01
    • 2022-01-14
    相关资源
    最近更新 更多