【问题标题】:Can python fastparquet module read in compressed parquet file?python fastparquet模块可以读取压缩的parquet文件吗?
【发布时间】:2017-07-03 06:17:02
【问题描述】:

我们的 parquet 文件存储在 aws S3 存储桶中,并由 SNAPPY 压缩。 我能够使用 python fastparquet 模块读取未压缩版本的 parquet 文件,但不能读取压缩版本。

这是我用于未压缩的代码

s3 = s3fs.S3FileSystem(key='XESF',    secret='dsfkljsf')
myopen = s3.open
pf = ParquetFile('sample/py_test_snappy/part-r-12423423942834.parquet', open_with=myopen)
df=pf.to_pandas()

这不会返回错误,但是当我尝试读取文件的快速压缩版本时:

pf = ParquetFile('sample/py_test_snappy/part-r-12423423942834.snappy.parquet', open_with=myopen)

to_pandas() 出现错误

df=pf.to_pandas()

错误信息

KeyErrorTraceback(最近一次调用最后一次) 在 () ----> 1 df=pf.to_pandas()

/opt/conda/lib/python3.5/site-packages/fastparquet/api.py 在 to_pandas(自我,列,类别,过滤器,索引) 293 for (name, v) in views.items()} 第294章 --> 295 索引=索引,分配=部分) 296 开始 += rg.num_rows 297 其他:

/opt/conda/lib/python3.5/site-packages/fastparquet/api.py 在 read_row_group(self, rg, columns, categories, infile, index, assign) 151 core.read_row_group( 152 infile,rg,列,类别,self.helper,self.cats, --> 153 self.selfmade, index=index,assign=assign) 154 如果返回: 第155章

/opt/conda/lib/python3.5/site-packages/fastparquet/core.py 在 read_row_group(文件,rg,列,类别,schema_helper,猫, 自制,索引,分配) 300 raise RuntimeError('进行预分配!') 301 read_row_group_arrays(文件,rg,列,类别,schema_helper, --> 302 只猫,自制,assign=assign) 303 猫中猫的 304:

/opt/conda/lib/python3.5/site-packages/fastparquet/core.py 在 read_row_group_arrays(文件,rg,列,类别,schema_helper, 猫,自制,分配) 第289章 第290章 --> 291 catdef=out[name+'-catdef'] if use else None) 292 293

/opt/conda/lib/python3.5/site-packages/fastparquet/core.py 在 read_col(column, schema_helper, infile, use_cat, grab_dict, selfmade, 分配,catdef) 196 迪克 = 无 197 如果 ph.type == parquet_thrift.PageType.DICTIONARY_PAGE: --> 198 dic = np.array(read_dictionary_page(infile, schema_helper, ph, cmd)) 199 ph = read_thrift(infile,parquet_thrift.PageHeader) 200 dic = 转换(dic,se)

/opt/conda/lib/python3.5/site-packages/fastparquet/core.py 在 read_dictionary_page(file_obj, schema_helper, page_header, 列元数据) 152 使用纯编码消耗数据并返回一个值数组。 第153章 --> 154 raw_bytes = _read_page(file_obj, page_header, column_metadata) 155 如果 column_metadata.type == parquet_thrift.Type.BYTE_ARRAY: 156 # 没有更快的读取可变长度字符串的方法?

/opt/conda/lib/python3.5/site-packages/fastparquet/core.py 在 _read_page(file_obj, page_header, column_metadata) 28 """从给定的文件对象中读取数据页并将其转换为原始的、未压缩的字节(如果需要)。""" 29 raw_bytes = file_obj.read(page_header.compressed_pa​​ge_size) ---> 30 raw_bytes = decompress_data(raw_bytes, column_metadata.codec) 31 32 断言 len(raw_bytes) == page_header.uncompressed_pa​​ge_size, \

/opt/conda/lib/python3.5/site-packages/fastparquet/compression.py 在 decompress_data(数据,算法) 48 def decompress_data(数据,算法='gzip'): 49 如果是实例(算法,整数): ---> 50 算法 = rev_map[算法] 51 如果 algorithm.upper() 不在解压缩中: 52 raise RuntimeError("解压 '%s' 不可用。选项: %s" %

密钥错误:1

【问题讨论】:

  • 能否请您说明您遇到了什么错误,以及有关文件是如何生成的一些详细信息?
  • 是的。对不起! ^ 请参阅帖子中的编辑

标签: python pandas parquet


【解决方案1】:

该错误可能表明在您的系统上未找到用于解压 SNAPPY 的库 - 尽管显然错误消息可能更清晰!

根据您的系统,以下几行可能会为您解决此问题:

conda install python-snappy

pip install python-snappy

如果你在windows上,构建链可能不起作用,也许你需要从here安装。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-09
  • 2015-01-12
  • 2021-01-22
  • 1970-01-01
相关资源
最近更新 更多