Python 如何从Google数据流中的PCollection中获取元素列表,并在管道中使用它来循环写入转换?
我正在使用带有Python SDK的Google云数据流 我想:Python 如何从Google数据流中的PCollection中获取元素列表,并在管道中使用它来循环写入转换?,python,google-bigquery,google-cloud-dataflow,apache-beam,Python,Google Bigquery,Google Cloud Dataflow,Apache Beam,我正在使用带有Python SDK的Google云数据流 我想: 从主PCollection中获取唯一日期的列表 循环该列表中的日期以创建筛选的PCollection(每个都有唯一的日期),并将每个筛选的PCollection写入BigQuery中时间分区表中的分区 我怎样才能得到那个名单?在以下合并转换之后,我创建了ListPCollectionView对象,但无法迭代该对象: class ToUniqueList(beam.CombineFn): def create_accu
- 从主PCollection中获取唯一日期的列表
- 循环该列表中的日期以创建筛选的PCollection(每个都有唯一的日期),并将每个筛选的PCollection写入BigQuery中时间分区表中的分区
class ToUniqueList(beam.CombineFn):
def create_accumulator(self):
return []
def add_input(self, accumulator, element):
if element not in accumulator:
accumulator.append(element)
return accumulator
def merge_accumulators(self, accumulators):
return list(set(accumulators))
def extract_output(self, accumulator):
return accumulator
def get_list_of_dates(pcoll):
return (pcoll
| 'get the list of dates' >> beam.CombineGlobally(ToUniqueList()))
我做错了吗?最好的方法是什么
谢谢。直接获取
PCollection
的内容是不可能的-Apache Beam或数据流管道更像是一个查询计划,说明应该做什么处理,其中PCollection
是计划中的一个逻辑中间节点,而不是包含数据。主程序组装计划(管道)并启动它
然而,最终您将尝试将数据写入按日期分割的BigQuery表。此用例当前仅受支持,并且仅适用于流式管道
有关根据数据将数据写入多个目标的更一般的处理方法,请遵循
另见