我正在使用Dataflow处理一个包含大约400万个功能(约2GB )的Shapefile,并将几何图形加载到BigQuery中,因此在管道启动之前,我将shapefile特性提取到一个列表中,并使用beam.Create(features)
初始化管道。有两种方法可以创建初始功能列表:
DoFn
将需要将其解析为dict:features = [f.ExportToJson() for f in layer]
预解析的python
features = [json.loads(f.ExportToJson()) for f in layer]
当使用选项1时,beam.Create(features)
只需一分钟左右,管道就会继续。使用选项2,beam.Create(features)
在6核i7上花费了类似于3+的时间,并且似乎花了很多时间在这里:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in <listcomp>
typehints.Union[[instance_to_type(v) for k, v in o.items()]],
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in instance_to_type
typehints.Union[[instance_to_type(v) for k, v in o.items()]],
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in <listcomp>
这是trivial_inference
吗?当传入一个dicts列表时,会减慢beam.Create
的速度吗?我是否可以将beam.Create
配置为不执行它在那里试图做的任何事情,或者以其他方式加快它的速度,这样一个字典列表就不会比字符串列表慢100倍吗?
发布于 2021-03-23 16:41:28
非常有趣的结果!
我的猜测是,之所以会出现这种情况,是因为Create
需要对接收到的所有数据进行筛选。字典的腌制大小可能很大,因为它们是作为Python对象被腌制的,而字符串则是作为Python字符串被腌制的。
你可以这样做:
p
| beam.Create([f.ExportToJson() for f in layer])
| beam.Map(json.loads)
以避免额外的腌制。这有用吗?
https://stackoverflow.com/questions/65503012
复制