我正在尝试使用ExecuteScript处理器执行一段java代码来过滤csv文件并输出一个新的csv文件。
将出现错误:未指定调拨关系。我怎么才能修复它呢?
我的代码:
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
FlowFile newflowFile = session.create();
try {
Reader reader = Files.newBufferedReader(Paths.get(flowFile), StandardCharsets.UTF-8);
Writer writer = Files.newBufferedWriter(Paths.get(newflowFile), StandardCharsets.UTF-8, StandardOpenOption.CREATE);
CSVPrinter printer = CSVFormat.DEFAULT.print(writer);
...
//using printer write a new content
session.transfer(newflowFile, REL_SUCCESS);
} catch (Exception e) {
session.transfer(flowFile, REL_FAILURE);
}发布于 2021-05-08 01:52:53
我建议你使用ExecuteGroovyScript而不是ExecuteScript -它有更多的功能,而且它只需在处理器初始化时编译一次。所以,它的速度要快一点。
如果您计划从同一个流文件中读取数据或将数据写入同一个流文件,这里是该脚本的基础。
def ff=session.get()
if(!ff)return
ff.write{InputStream rawIn, OutputStream rawOut->
//rawIn - current flowfile content
//rawOut - stream for a new flowfile content
rawIn.withReader("UTF-8"){reader->
rawOut.withWriter("UTF-8"){writer->
CSVPrinter printer = CSVFormat.DEFAULT.print(writer)
...
}
}
}
REL_SUCCESS << ff //the same as session.transferhttps://stackoverflow.com/questions/67421794
复制相似问题