Apache Beam动态窗口写入用defaultNaming遇NetBeans语法错误求助
Let's break down what's causing that syntax error in your withNaming line and fix it:
The Root Cause
The error is happening because you're trying to call defaultNaming() without properly referencing its containing class. In Apache Beam, defaultNaming is a static method belonging to FileIO.Write, so you need to qualify it with the full class path to resolve it correctly.
Corrected Code
Here's the fixed version of your method:
static void applyWindowedWrite(PCollection<String> stream) { stream.apply( FileIO.<String, String>writeDynamic() .by(Event::getKey) .via(TextIO.sink()) .to("gs://some_bucket/events/") .withNaming(key -> FileIO.Write.defaultNaming(key, ".json"))); }
Additional Checks (Just to Be Safe)
- Make sure you have the correct import for
FileIO:import org.apache.beam.sdk.io.FileIO; - If you're using an older Beam version, double-check the
defaultNamingmethod signature—some earlier releases used slightly different parameter ordering, but your suffix choice of.jsonis perfectly valid for the current standard signature.
Why This Works
By adding FileIO.Write. before defaultNaming, you're telling the compiler exactly where to find that static method. The lambda key -> FileIO.Write.defaultNaming(key, ".json") correctly maps each event key to a unique file naming scheme, which is exactly what writeDynamic() expects for partitioning your output files by key.
内容的提问来源于stack exchange,提问作者ljhenne

