gpt4 book ai didi

java - Apache Beam 代码中插入语法错误

转载 作者:行者123 更新时间:2023-12-02 11:12:52 25 4
gpt4 key购买 nike

我正在编写 Apache Beam 代码进行测试。请引用下面的代码。我创建了示例 SimpleFunction 并应用代码并尝试编译。

    public static void main(String[] args) throws IOException {
System.out.println("Test Log");

PipelineOptions options = PipelineOptionsFactory.create();
//options.setRunner(SparkRunner.class);
options.setRunner(SparkRunner.class);

Pipeline p = Pipeline.create(options);

p.apply(FileIO.match().filepattern("hdfs://path/to/*.gz"))
// withCompression can be omitted - by default compression is detected from the filename.
.apply(FileIO.readMatches())
.apply(MapElements
// uses imports from TypeDescriptors
.via(
new SimpleFunction <ReadableFile, KV<String,String>>() {

private static final long serialVersionUID = -7867677L;

@SuppressWarnings("unused")
public KV<String,String> createKV(ReadableFile f) {
String temp = null;
try{
temp = f.readFullyAsUTF8String();
}catch(IOException e){

}
return KV.of(f.getMetadata().resourceId().toString(), temp);
}

@Override
public String apply(ReadableFile element, KV<String, String> input) {
StringBuilder str = new StringBuilder();
return str.toString();
}
}

))
.apply(FileIO.write());
p.run();
}

但是编译器抛出 syntax error at public String apply(ReadableFile

我尝试但没有成功解决这个问题,有人可以指导我吗?

最佳答案

SimpleFunction<InputT, OutputT>取值为 InputT并返回 OutputT 的值。 apply的签名在这种情况下是 OutputT apply(InputT input); ,参见here .

根据您的类型,SimpleFunction必须看起来像这样:

new SimpleFunction <ReadableFile, KV<String,String>>() {
...
@Override
public KV<String,String> apply(ReadableFile input) {
...
}
}

例如看看它是如何使用的here .

在你的情况下,你需要更多关于 readMatches() 的逻辑,参见here例如如何应用它来解析 Avros,以及 thisPTransform的实现细节从该代码。

关于java - Apache Beam 代码中插入语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50493512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com