java - 如何在hadoop级联中获取输入文件名

标签 java hadoop mapreduce cascading

在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/

相关文章:

hadoop - Spring Cloud Dataflow-http |卡夫卡和卡夫卡| hdfs-在HDFS中获取原始消息

java - Hadoop MapReduce : Strange Result when Storing Previous Value in Memory in a Reduce Class (Java)

javascript - 使用 groupBy 对数组进行分组

java - BufferedWriter 性能缓慢

java - 静态工厂方法如何返回一个新实例?

java - 发送网格 v3 : "Substitutions may not be used with dynamic templating"

hadoop - 在 Mesos 上运行 Impala

java - 将程序转换为使用对象而不是数字

hadoop - 如何配置hadoop使用非默认端口: "0.0.0.0: ssh: connect to host 0.0.0.0 port 22: Connection refused"

hadoop - cloudera hadoop mapreduce 作业 GC 开销限制超出错误