【问题标题】:How to convert a PCollection<Long> having a single element to a java in-memory collection?如何将具有单个元素的 PCollection<Long> 转换为 java 内存集合?
【发布时间】:2018-11-28 23:24:24
【问题描述】:

所以我想要做的是我将Count 转换的输出存储在PCollection&lt;Long&gt; 中,现在只有一个元素。如果有任何方法可以将其转换为 Java 内存中的集合,那将非常方便。基本上我正在寻找的是对Create.of() 转换的否定。任何想法?

【问题讨论】:

    标签: java google-cloud-dataflow apache-beam


    【解决方案1】:

    在 Beam 中,没有提供执行此操作的方法。也就是说,您想做的任何后续计算都可以将单个元素用作ParDo 的侧输入。我建议您在执行Count 时直接转换为PCollectionView;对于具有标识元素的组合器来说,这是一个很好的做法。

    PCollectionView<Long> count =
        input.apply(Combine.globally(Count.combineFn()).asSingletonView())
    
    dummyCollection.apply(ParDo.of(new DoFnConsumingTheCount(count)).withSideInputs(count));
    

    【讨论】:

      【解决方案2】:

      看看Scio中的materialize。

      【讨论】:

        猜你喜欢
        • 2022-08-16
        • 2019-03-18
        • 2021-12-14
        • 2017-11-28
        • 1970-01-01
        • 1970-01-01
        • 2022-01-13
        • 2020-05-07
        相关资源
        最近更新 更多