在我的oozie coordinator.xml文件中,我将以下内容定义为输入目录:
<property>
<name>countingHourlyInputDir</name>
<value>${coord:dataIn('hourly-input')}/*Pattern1*,${coord:dataIn('hourly-input')}/*Pattern2*</value>
</property>
这匹配文件名与“Pattern1”或“Pattern2”匹配的目录中的文件。如果目录包含文件Pattern1文件和Pattern2文件,我的作业运行没有问题。但是,如果目录只包含Pattern1文件或Pattern2文件,我的作业将失败,并且出现如下错误:
Oozie Launcher失败,主要课程 [org.apache.oozie.action.hadoop.MapReduceMain],main()扔了 异常,输入模式 hdfs:// hdfsPath / logs / 2012/07/09/02 / Pattern1 匹配0个文件 org.apache.hadoop.mapreduce.lib.input.InvalidInputException:输入 图案 hdfs:// hdfsPath / logs / 2012/07/09 / 02 / Pattern1 匹配0个文件
有没有办法告诉Oozie忽略此错误,以便仍然对匹配Pattern2的文件执行MapReduce作业,而不是使整个作业失败?
更新
我自己想出了解决方案,我会记录我做了什么,以防其他人以后遇到这个问题。
我创建了一个名为RegexPathFilter的类,它实现了PathFilter和Configurable。我通过在oozie workflow.xml中指定 mapred.input.pathFilter.class 属性将此过滤器传递给hadoop作业。这是我的课程和我的配置片段:
public class RegexPathFilter implements PathFilter, Configurable {
public static final String CONF_REGEX_PROPERTY = "regexPathFilter.regex";
private static final Log LOG = LogFactory.getLog(RegexPathFilter.class);
private String _regex;
private Configuration _conf;
public RegexPathFilter() {
}
@Override
public void setConf(Configuration conf) {
_conf = conf;
//get regex from Configuration
_regex = _conf.get(CONF_REGEX_PROPERTY);
}
@Override
public Configuration getConf() {
return _conf;
}
public boolean accept(Path path) {
if(_regex == null) {
throw new IllegalStateException("RegexPathFilter must be given a regex to filter with.");
}
boolean matches = path.toString().matches(_regex);
LOG.info(path + (matches ? " matches " : " does NOT match ") + _regex);
return matches;
}
}
workflow.xml:
<property>
<name>mapred.input.pathFilter.class</name>
<value>com.company.project.hadoop.util.RegexPathFilter</value>
</property>
<property>
<name>regexPathFilter.regex</name>
<value>.*(Pattern1|Pattern2).*</value>
</property>
答案 0 :(得分:0)
此问题背后的原因是https://issues.apache.org/jira/browse/HADOOP-8870
我也遇到了同样的问题,并通过对模式和零代码进行细微更改来解决它。
替换
<property>
<name>countingHourlyInputDir</name>
<value>${coord:dataIn('hourly-input')}/*Pattern1*,${coord:dataIn('hourly-input')}/*Pattern2*</value>
</property>
带
<property>
<name>countingHourlyInputDir</name>
<value>{${coord:dataIn('hourly-input')}}/{*Pattern1*,*Pattern2*}</value>
</property>
在替换之后,只有当目录包含既不匹配pattern1也不匹配pattern2的文件时,hadoop将抛出错误。