首页 文章

Apache Beam字段分区

提问于
浏览
0

我想在特定字段中使用Python在Apache Beam中对PCollection进行分区 .

我在Python SDK文档中找到了以下代码,用于对PCollection进行分区

students = ...
def partition_fn(student, num_partitions):
  return int(get_percentile(student) * num_partitions / 100)

by_decile = students | beam.Partition(partition_fn, 10)

但这不是我想要做的 . 有没有办法做到这一点?

1 回答

  • 0

    “分区”不是你需要的正确变换 .

    你需要使用GroupByKey

    请注意,为了正常工作,您必须确保要处理的元素必须是一对 . 在这样的一对中,第一个元素始终被认为是用于GroupByKey变换的密钥 .

    没有你需要的其他参数 .

    在我的情况下,我有像元组

    (key, < list of dictionaries >)
    

相关问题