У меня есть Java-класс Filter2, и я хочу запустить его с помощью сценария оболочки run2.sh.Проблема в том, что я не знаю, как я могу ввести 2 параметра ($ 1 и $ 2) в сценарии оболочки.
public class Filter2 {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
conf.set("limit", otherArgs[0]);
conf.set("limit2", otherArgs[1]);//added here
Job job = new Job(conf, "Distributed Filter");
job.setJarByClass(Filter2.class);
job.setMapperClass(FilterMapper.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setNumReduceTasks(0); // Set number of reducers to zero
FileInputFormat.addInputPath(job, new Path(args[1]));
FileOutputFormat.setOutputPath(job, new Path(args[2]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
public static class FilterMapper
extends Mapper<Object, Text, Text, IntWritable>{
private final static IntWritable counter = new IntWritable(0);
private Text word = new Text();
private Integer total;
private Integer limit;
private Integer limit2;//added here
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
limit = Integer.parseInt( context.getConfiguration().get("limit") );
limit2 = Integer.parseInt( context.getConfiguration().get("limit2") );
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
total = Integer.parseInt(itr.nextToken());//added here
if ((total > limit)&&(total<limit2))//added here
{ counter.set( total );
context.write(word, counter); }
}
}
}
}
run2.sh
$HADOOP_HOME/bin/hadoop jar Filter2.jar Filter2 $1 sales.txt /user/solution2/
Я хочу запустить свойJava с помощью сценария оболочки в терминале "./run.sh 45 50", но я не могу поставить 2 входных параметра.Как я могу изменить свой сценарий оболочки, чтобы включить этот результат?