在map-reduce中,我将提取输入文件名如下
public void map(WritableComparable<Text> key, Text value, OutputCollector<Text,Text> output, Reporter reporter)
throws IOException {
FileSplit fileSplit = (FileSplit)reporter.getInputSplit();
String filename = fileSplit.getPath().getName();
System.out.println("File name "+filename);
System.out.println("Directory and File name"+fileSplit.getPath().toString());
process(key,value);
}
我怎样才能用级联来做类似的事情
Pipe assembly = new Pipe(SomeFlowFactory.class.getSimpleName());
Function<Object> parseFunc = new SomeParseFunction();
assembly = new Each(assembly, new Fields(LINE), parseFunc);
...
public class SomeParseFunction extends BaseOperation<Object> implements Function<Object> {
...
@Override
public void operate(FlowProcess flowProcess, FunctionCall<Object> functionCall) {
how can I get the input file name here ???
}
谢谢
最佳答案
我不使用级联,但我认为使用 functionCall.getContext() 访问上下文实例应该足够了,以获得可以使用的文件名:
String filename= ((FileSplit)context.getInputSplit()).getPath().getName();
但是,级联似乎使用旧的 API,如果上述方法不起作用,您必须尝试使用:
Object name = flowProcess.getProperty( "map.input.file" );
关于java - 如何在hadoop级联中获取输入文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13791524/