【问题标题】:google dataflow: the type Sum.SumIntegerFn is not visible谷歌数据流:类型 Sum.SumIntegerFn 不可见
【发布时间】:2017-05-03 19:32:24
【问题描述】:

在我的 Eclipse 中,我被标记为错误“类型 Sum.SumIntegerFn 不可见。

import org.apache.beam.sdk.transforms.Sum;
....
something = createAggregator("something", new Sum.SumIntegerFn());

【问题讨论】:

    标签: google-cloud-dataflow apache-beam


    【解决方案1】:

    我从导入中看到您正在使用 Apache Beam。您应该使用Sum.ofIntegers() 而不是new Sum.SumIntegerFn()

    另外请注意,在 Github head 中,聚合器已被删除。相反,计数器指标将提供类似的行为。详情请见Metrics

    【讨论】:

    • 但我从 Beam document Sum.SumIntegerFn() 中发现了这个,它结合了输入 PCollection 中的元素。 PCollection<Integer> pc = ...; PCollection<Integer> sum = pc.apply( Combine.globally(new Sum.SumIntegerFn()));
    • 文档已过期,Sum.SumIntegerFn() 不再公开。 Sum.ofIntegers() 已替换它。对于该用例,您也可以使用Sum.integersGlobally()。最初的问题是关于聚合器,而不是联合。
    • 现在我得到了这个“Sum.ofIntegers 无法解析为类型”
    • 您使用的是Sum.ofIntegers() 还是new Sum.ofIntegers()。请参阅链接 - 它不是您与 new 一起使用的类型,它是一个函数。
    • 您可以使用something = createAggregator("something", Sum.ofIntegers());,也可以使用something = Metrics.counter("counternamespace", "something");,如果您想使用指标计数器。
    【解决方案2】:

    Sum.SumIntegerFn() 不再公开,取而代之的是Sum.ofIntegers()。如果您需要一种解决方法来使用自己的 Iterable 函数而不是内置函数,请尝试下面的代码块。

    something = createAggregator("something", new SumIntegers());
    
    public static class SumIntegers implements SerializableFunction<Iterable<Integer>, Integer> {
            @Override
            public Integer apply(Iterable<Integer> input) {
                Integer sum = 0;
                for (Integer item : input) {
                    sum += item;
                }
                return sum;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 2018-07-20
      • 1970-01-01
      相关资源
      最近更新 更多