0
A
回答
1
没有办法检查PCollection的大小而不应用PTransform(例如Count.globally()或Combine.combineFn()),因为PCollection不像Java SDK中的典型集合等等。
这是一个有界或无界的数据集合的抽象,其中数据被送入集合中以应用于其上的操作(例如PTransform)。它也是并行的(正如课程开始时的P所示)。
因此,您需要一种机制来获取每个工作人员/节点的元素数量并将它们合并以获取值。直到变换结束,才能知道它是0还是n。
1
您没有指定您使用的是哪个SDK,因此我假设了Python。该代码很容易移植到Java。
您可以应用全局元素计数,然后通过应用简单比较将数值映射到布尔值。您将可以一边输入使用pvalue.AsSingleton
功能这个值,像这样:
import apache_beam as beam
from apache_beam import pvalue
is_empty_check = (your_pcollection
| "Count" >> beam.combiners.Count.Globally()
| "Is empty?" >> beam.Map(lambda n: n == 0)
)
another_pipeline_branch = (
p
| beam.Map(do_something, is_empty=pvalue.AsSingleton(is_empty_check))
)
用法如下:
def do_something(element, is_empty):
if is_empty:
# yes
else:
# no
相关问题
- 1. 确定pcollection是否为空
- 2. Apache Beam - 无界PCollection集成测试
- 3. Beam/Dataflow中的批处理PCollection
- 4. Apache-Beam将序列号添加到PCollection中
- 5. 什么是Apache Beam?
- 6. 检查dataGridView是否为空
- 7. 检查JValue是否为空
- 8. 检查imageView是否为空
- 9. 检查tabControl1是否为空?
- 10. 检查CSV是否为空
- 11. 检查double是否为空
- 12. 检查列是否为空
- 13. 检查ALAssetsLibrary是否为空
- 14. 检查ArrayCollection是否为空
- 15. laravel检查是否为空
- 16. 检查textarea是否为空
- 17. 检查NumericUpDown是否为空
- 18. 检查ImageSource是否为空
- 19. 检查是否为空JasperReports
- 20. 检查是否为空JFormattedTextField
- 21. 检查editText是否为空
- 22. 检查JTextField是否为空
- 23. 检查是否为空VB.NET
- 24. 检查StringBuffer是否为空
- 25. 检查OnAction是否为空
- 26. 检查NSDictionary是否为空
- 27. 检查JTextFields是否为空
- 28. 检查managedobjectcontext是否为空?
- 29. 检查它是否为空
- 30. 检查stderr是否为空
Count.globally()如何? – jkff