[英]How can I force spark/hadoop to ignore the .gz extension on a file and read it as uncompressed plain text?
[英]How to read Gzipped file on Azure without (.gz) extension in Spark/Scala
我有一个在Azure上没有.gz扩展名的Gzip压缩文件。 路径: 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()
我相信spark通过自动解压缩以.gz终止的文件来读取gzip压缩文件。 寻找一些帮助来阅读未指定扩展名的压缩文件。
预期输出将是ID列表(一列)
1343423
2342342
2343232
2342343
使用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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.