可以从Dask读取实木复合地板元数据吗?

时间:2019-10-03 13:01:45

标签: dask parquet dask-distributed dask-delayed fastparquet

我有数千个需要处理的镶木地板文件。在处理文件之前,我试图使用镶木地板元数据获取有关文件的各种信息,例如每个分区中的行数,最小值,最大值等。

我尝试使用dask.delayed读取元数据,希望在整个群集中分配元数据收集任务,但这似乎导致Dask不稳定。请参见下面的示例代码片段和节点超时错误。

是否可以从Dask读取实木复合地板元数据?我知道Dask的“ read_parquet”函数具有“ gather_statistics”选项,您可以将其设置为false来加快文件读取速度。但是,如果设置为true,我看不到一种方法来访问所有实木复合地板元数据/统计信息。

示例代码:


@dask.delayed
def get_pf(item_to_read):
     pf = fastparquet.ParquetFile(item_to_read)
     row_groups = pf.row_groups.copy()
     all_stats = pf.statistics.copy()
     col = pf.info['columns'].copy()
     return [row_groups, all_stats, col]

stats_arr = get_pf(item_to_read)

示例错误:

2019-10-03 01:43:51,202 - INFO - 192.168.0.167 - distributed.worker - ERROR - Worker stream died during communication: tcp://192.168.0.223:34623

2019-10-03 01:43:51,203 - INFO - 192.168.0.167 - Traceback (most recent call last):

2019-10-03 01:43:51,204 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/comm/core.py", line 218, in connect

2019-10-03 01:43:51,206 - INFO - 192.168.0.167 -     quiet_exceptions=EnvironmentError,

2019-10-03 01:43:51,207 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 729, in run

2019-10-03 01:43:51,210 - INFO - 192.168.0.167 -     value = future.result()

2019-10-03 01:43:51,211 - INFO - 192.168.0.167 - tornado.util.TimeoutError: Timeout

2019-10-03 01:43:51,212 - INFO - 192.168.0.167 -

2019-10-03 01:43:51,213 - INFO - 192.168.0.167 - During handling of the above exception, another exception occurred:

2019-10-03 01:43:51,214 - INFO - 192.168.0.167 -

2019-10-03 01:43:51,215 - INFO - 192.168.0.167 - Traceback (most recent call last):

2019-10-03 01:43:51,217 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/worker.py", line 1841, in gather_dep

2019-10-03 01:43:51,218 - INFO - 192.168.0.167 -     self.rpc, deps, worker, who=self.address

2019-10-03 01:43:51,219 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 729, in run

2019-10-03 01:43:51,220 - INFO - 192.168.0.167 -     value = future.result()

2019-10-03 01:43:51,222 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 736, in run

2019-10-03 01:43:51,223 - INFO - 192.168.0.167 -     yielded = self.gen.throw(*exc_info)  # type: ignore

2019-10-03 01:43:51,224 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/worker.py", line 3029, in get_data_from_worker

2019-10-03 01:43:51,225 - INFO - 192.168.0.167 -     comm = yield rpc.connect(worker)

2019-10-03 01:43:51,640 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 729, in run

2019-10-03 01:43:51,641 - INFO - 192.168.0.167 -     value = future.result()

2019-10-03 01:43:51,643 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 736, in run

2019-10-03 01:43:51,644 - INFO - 192.168.0.167 -     yielded = self.gen.throw(*exc_info)  # type: ignore

2019-10-03 01:43:51,645 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/core.py", line 866, in connect

2019-10-03 01:43:51,646 - INFO - 192.168.0.167 -     connection_args=self.connection_args,

2019-10-03 01:43:51,647 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 729, in run

2019-10-03 01:43:51,649 - INFO - 192.168.0.167 -     value = future.result()

2019-10-03 01:43:51,650 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/tornado/gen.py", line 736, in run

2019-10-03 01:43:51,651 - INFO - 192.168.0.167 -     yielded = self.gen.throw(*exc_info)  # type: ignore

2019-10-03 01:43:51,652 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/comm/core.py", line 230, in connect

2019-10-03 01:43:51,653 - INFO - 192.168.0.167 -     _raise(error)

2019-10-03 01:43:51,654 - INFO - 192.168.0.167 -   File "/usr/local/lib/python3.7/dist-packages/distributed/comm/core.py", line 207, in _raise

2019-10-03 01:43:51,656 - INFO - 192.168.0.167 -     raise IOError(msg)

2019-10-03 01:43:51,657 - INFO - 192.168.0.167 - OSError: Timed out trying to connect to 'tcp://192.168.0.223:34623' after 10 s: connect() didn't finish in time

1 个答案:

答案 0 :(得分:1)

dd.read_parquet需要很长时间吗?如果没有,那么您可以按照其中的任何策略在客户端中进行阅读。

如果数据在根目录中只有一个_metadata文件,那么您可以简单地使用fastparquet打开它,这正是Dask会做的。它包含所有数据片段的所有详细信息。

没有特别的理由来分发元数据读取应该是一个问题,但是您应该意识到,在某些情况下,元数据项的总数可能总计很大。