如何从Google Dataflow的PCollection中获取元素列表并在管道中使用它来循环执行Write Transforms?

发布于 2021-01-29 15:04:52

我将Google Cloud Dataflow与Python SDK结合使用。

我想要 :

  • 从主PCollection中获取唯一日期列表
  • 遍历该列表中的日期以创建过滤的PCollection(每个过滤器都有一个唯一的日期),并将每个过滤的PCollection写入BigQuery中按时间划分的表中的分区。

如何获得该清单?在执行以下合并转换之后,我创建了一个ListPCollectionView对象,但是无法迭代该对象:

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()))

我做错了吗?最好的方法是什么?

谢谢。

关注者
0
被浏览
52
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    无法直接获取内容PCollection-Apache
    Beam或Dataflow管道更像是一个查询计划,该查询计划应进行哪些处理,并且PCollection是计划中的逻辑中间节点,而不是包含数据。主程序组装计划(管道)并将其启动。

    但是,最终您尝试将数据写入按日期分片的BigQuery表中。当前仅在Java
    SDK中
    支持此用例并且仅对流管道支持。

    有关根据数据将数据写入多个目标的更一般处理,请遵循BEAM-92

    另请参阅通过Google Cloud Dataflow创建/写入Parititoned
    BigQuery表



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看