Apache Beam Dataflow SDK 错误示例

Apache beam Dataflow SDK error with example

我正在尝试 beam google 数据流管道示例之一,但我遇到了有关 MapElements 和方法 SingleFunction / SerializableFunction 调用的异常。代码片段如下:

static class ParseTableRowJson extends SimpleFunction<String, TableRow> {
    @Override
    public TableRow apply(String input) {
        try {
            return Transport.getJsonFactory().fromString(input, TableRow.class);
        } catch (IOException e) {
            throw new RuntimeException("Failed parsing table row json", e);
        }
    }
}
......
p.apply(TextIO.read().from(options.getInput()))
                .apply(MapElements.via(new ParseTableRowJson()))
                .apply(new ComputeTopSessions(samplingThreshold))
                .apply("Write", 
TextIO.write().withoutSharding().to(options.getOutput()));

异常是对方法的调用不明确:

Ambiguous method call. Both
via (SimpleFunction<String, TableRow>) in MapElements and
via (SerializableFunction)             in MapElements match

有没有其他人遇到同样的异常并找到解决办法?

完整示例在 github (https://github.com/apache/beam/blob/master/examples/java/src/main/java/org/apache/beam/examples/complete/TopWikipediaSessions.java).

谢谢,

费尔南多

这似乎已在 HEAD 的代码中修复。具体来说,MapElements 不再有 via 的两个静态版本。短期内,您可以从 HEAD 安装 Beam 或通过将 ParseTableRowJson 设为 DoFn 而不是 SimpleFunction.[=16= 来更新示例以直接使用 ParDo ]