我已经设置了管道。我必须解析数百个 *.gz 文件。因此 glob 效果很好。
但我需要当前处理的文件的原始名称,因为我想将结果文件命名为原始文件。
有人能帮我一下吗?
这是我的代码。
@Default.String(LOGS_PATH + "*.gz")
String getInputFile();
void setInputFile(String value);
TextIO.Read read = TextIO.read().withCompressionType(TextIO.CompressionType.GZIP).from(options.getInputFile());
read.getName();
p.apply("ReadLines", read).apply(new CountWords())
.apply(MapElements.via(new FormatAsTextFn()))
.apply("WriteCounts", TextIO.write().to(WordCountOptions.LOGS_PATH + "_" + options.getOutput()));
p.run().waitUntilFinish();
Run Code Online (Sandbox Code Playgroud)