Can I tell spark.read.json that my files are gzipped?

杀马特。学长 韩版系。学妹 提交于 2020-07-20 17:25:58

问题


I have an s3 bucket with nearly 100k gzipped JSON files.

These files are called [timestamp].json instead of the more sensible [timestamp].json.gz.

I have other processes that use them so renaming is not an option and copying them is even less ideal.

I am using spark.read.json([pattern]) to read these files. If I rename the filename to contain the .gz this works fine, but whilst the extension is just .json they cannot be read.

Is there any way I can tell spark that these files are gzipped?


回答1:


SparkSession can read compressed json file directly, just like this:

val json=spark.read.json("/user/the_file_path/the_json_file.log.gz") json.printSchema()



来源:https://stackoverflow.com/questions/52253022/can-i-tell-spark-read-json-that-my-files-are-gzipped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!