首页 > 解决方案 > 使用 spark 从 hdfs 加载镶木地板后数据被弄乱了

问题描述

我在 hdfs 集群上有一些文本文件。之后,我使用 spark 加载这些文本文件并使用 parquet 格式在 hdfs 上重写它们并删除这些文本文件。

df = spark.read.text(hdfs_url)
df.coalesce(partition_num).write.option("compression","gzip").parquet(new_hdfs_url)

现在,当我使用 spark 加载这些 parquet 文件时,我的数据搞砸了,我不知道它们有什么问题。

df = spark.read.parquet(new_hdfs_url)

我的真实数据是一些 nginx 错误日志,但是当我获取数据时,我会看到如下内容:

'PAR1\x15\x00\x15���\x01\x15��\x0b,\x15�\x1e\x15\x00\x15\x06\x15\x08\x1c6\x00(�\x052019-10-28T20:54:58.369Z "PUBLIC.STH.COM"  2019/10/29 00:24:58 [error] 15643#15643: *111716990 upstream timed out (110: Connection timed out) while reading upstream, client: 5.12.123.4, server: s1.something.com, request: "GET / HTTP/1.1", subrequest: "/", upstream: "http://5.5.5.5:80/", host: "s1.something.com", referrer: "http://something.com/?fbclid=IwAR0Ywsy-U2XFit1u3ITn4RmPfP_WnNmRcG2_70iK_8JXyr1D4" 35825232e44d1da669b7d4:\x18�\x032019-10-28T02:07:23.144Z "PUBLIC.SOMETHING.COM"  2019/10/28 05:37:23 [error] 15546#15546: *107839350 upstream timed out (110: Connection timed out) while connecting to upstream, client: 123.123.123.123, server: something.com, request: "GET / HTTP/1.0", upstream: "http://5.5.5.15:80/", host: "s1.something.com" 825ed3d1dad1481705d4:\x00\x00\x00\x1f�\x08\x00\x00\x00\x00\x00\x00\x00�k�$Yv\x1eFia�\t\t\x12)�\x12E�8�"v�\x1b�����j��U�ݻ��î���Y/�Q�QU9��Q����\u0604a\x014d)�\x06�dže��a\x10�?��Eل�_$`ِa'

我的一个猜测是数据加载不正确,因为在这个数据中,我在一条记录中有两个单独的日志,但在其中一些记录中没有像这样的数据:

�-��\x00A�!

标签: pysparkhdfscorruption

解决方案


推荐阅读