【发布时间】:2020-03-20 06:29:12
【问题描述】:
我从位于同一文件夹中的多个 Parquet 文件创建了一个 Parquet 文件。每个文件对应一个分区。
Parquet 文件是在不同的进程中创建的(使用 Python concurrent.futures)。这是我在一个进程中运行的代码示例:
# `df` is a standard Pandas DataFrame with
# 22 columns of different types and at most 100e3 rows.
# Set the index
df.set_index("cid", inplace=True)
# Write to single file
fastparquet.write(fpath, df, compression='snappy, file_scheme='simple)
df 最多包含 100e3 行(和 22 列),并在整数索引(称为 cid)上编制索引。
然后我使用以下方法创建了两个元数据文件:
# `data_paths` contains the list of all the Parquet data files
# created in multiple processes.
fastparquet.writer.merge(data_paths, verify_schema=True)
确实,_metadata 和 _common_metadata 在包含所有 Parquet 文件的文件夹中正确创建。
我天真地认为,由于数据已编入索引和/或具有元数据文件,因此获取数据大小等基本信息应该很快。例如,以下内容需要永远:
import dask.dataframe as ds
# `dataset_path` is the path to the folder
# containing all the Parquet files created above
# and the metadata files.
# It contains ~100-200 individual Parquet files
# for a total of ~60,000,000 rows
data = df.read_parquet(dataset_path)
data.shape[0].compute()
那是例外吗?
另请注意,大多数列是int64、float64,少数是object(string,大小不一。
【问题讨论】:
-
什么是
data?你能解释更多关于df是如何创建的吗?如果数据是从多个期货对象创建的,那么您对data.shape的调用可能需要从原始concurrent.futures对象进行计算,或者最坏的情况是从磁盘计算。也许打电话给df = df.persist()? -
我已经编辑了我的问题。我希望现在更清楚了。
标签: dask parquet fastparquet