我们如何使用Map Reduce算法来检查数据文件中列的值是否符合给定条件?如何使用map reduce程序检查列的值是否与条件匹配?
例如:对于列C1
我们要检查该列的值是否与条件C1 in ("A", "B", "C")
匹配。
我希望的输出是将符合我的标准的行的所有标识符保存在表中,其他表中的其他表不匹配其他表。我当前的代码是:
public class SmallDataMap extends Mapper<Object, Text, Text, Text> {`
@Override
protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String[] tokens = value.toString().split(",");
if (tokens.length != 8) {
return;
}
String gds = tokens[6];
if (gds.equals("AMA") || (gds.equals("ABA"))) {
context.write(new Text(gds), new Text(tokens[0]));
}
}
}
主类的代码是:
public class SmallData {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] ourArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
Job job = Job.getInstance(conf, "Structuration par code gds");
job.setJarByClass(SmallData.class);
job.setMapperClass(SmallDataMap.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(ourArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(ourArgs[1]));
job.waitForCompletion(true);
}
}
我生成jar文件,当我试图在Cloudera的执行我的工作,我有这样的错误:
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class smalldata.SmallDataMap not found
你的输入是如何存储在HDFS中的?当前的代码是什么,它不起作用?为什么它不起作用?什么是期望的输出?可能是降价是由于缺乏这种信息 – vefthym