wordcount 示例很棒——但有限。
想象一下,我们要对 shakespeare
文件夹中的每个文件进行转换,并且处理过程比计算单词要激烈得多。
是否可以在同一管道中进行类似的操作,而无需手动指定不同的分支?
# This processes all the files in the same "branch" in Dataflow.
p | beam.Create([/shakespeare/*.txt]) | MatchAll() | ...
┌───────────────────────────┐
│ Start: /shakespeare/*.txt │
└────────────┬──────────────┘
│
│
┌────────────▼──────────────┐
│ Expand glob (MatchAll) │
└────────────┬──────────────┘
│
┌─────────┬──────────────┼────────┬──────────────┐
│ │ │ │ │
┌─────▼─┐ ┌──▼────┐ ┌──────▼┐ ┌───▼───┐ ┌───▼─────┐
│ File1 │ │ File2 │ │ File3 │ │ File4 │ ... │ File123 │
└───┬───┘ └──┬────┘ └───┬───┘ └───┬───┘ └───┬─────┘
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
┌───▼───┐ ┌──▼────┐ ┌───▼───┐ ┌───▼───┐ ┌───▼───┐
│ done │ │ done │ │ done │ │ done │ │ done │
└───┬───┘ └───┬───┘ └───┬───┘ └───┬───┘ └───┬───┘
│ │ │ │ │
│ │ │ │ │
└────────────┴──────────┴──┬────────┴──────────────┘
│
┌──────▼──────┐
│Merge Results│
└─────────────┘
答案 0 :(得分:0)
我想到的一个解决方案是将您的收藏分成多个收藏。
Partition 将集合中的元素分成多个输出集合。分区函数包含确定如何将输入集合的元素分离到每个结果分区输出集合中的逻辑。
有关更多信息和示例,请参阅 Apache Beam 文档: https://beam.apache.org/documentation/transforms/python/elementwise/partition/