Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MultipleInput class in mapreduce?

I have a one question.

I need two files as an Input to mapreduce program.

@Override
public int run(String[] args) throws Exception {

    (argument skip)
    Job job1 = new Job();           
    job1.setJarByClass(CFRecommenderDriver.class);

    job1.setMapperClass(CFRecommenderMapper.class);     
    //job1.setReducerClass(CFRecommenderReducer.class);    

    job1.setMapOutputKeyClass(Text.class);
    job1.setMapOutputValueClass(TextDoublePairWritableComparable.class);

    //job1.setOutputKeyClass(TextTwoWritableComparable.class);
    //job1.setOutputValueClass(TextDoubleTwoPairsWritableComparable.class);

    MultipleInputs.addInputPath(job1, new Path(args[0]), FileInputFormat.class);
    MultipleInputs.addInputPath(job1, new Path(args[1]), FileInputFormat.class);

job1.setNumReduceTasks(0);

    boolean step1 = job1.waitForCompletion(true);
    if(!(step1)) return -1;

If I'm running program with the following command:

hadoop jar mapreduce-0.1.jar cf /input/cf-re/data1 /input/cf-re/data2 /output/cf-r/data1

I get the following error:

2013-07-01 13:13:44.822 java[45783:1603] Unable to load realm info from SCDynamicStore
13/07/01 13:13:45 WARN mapred.JobClient: Use GenericOptionsParser for parsing the        arguments. Applications should implement Tool for the same.
 13/07/01 13:13:45 INFO mapred.JobClient: Cleaning up the staging area  hdfs://127.0.0.1:9000/tmp/hadoop- suhyunjeon/mapred/staging/suhyunjeon/.staging/job_201306191432_0218
 java.lang.RuntimeException: java.lang.InstantiationException
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
at org.apache.hadoop.mapreduce.lib.input.MultipleInputs.getInputFormatMap(MultipleInputs.java:109)
at org.apache.hadoop.mapreduce.lib.input.DelegatingInputFormat.getSplits(DelegatingInputFormat.java:58)
at org.apache.hadoop.mapred.JobClient.writeNewSplits(JobClient.java:1024)
at org.apache.hadoop.mapred.JobClient.writeSplits(JobClient.java:1041)
at org.apache.hadoop.mapred.JobClient.access$700(JobClient.java:179)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:959)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:912)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1149)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:912)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:500)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:530)
at org.ankus.hadoop.mapreduce.algorithm.cf.recommender.CFRecommenderDriver.run(CFRecommenderDriver.java:86)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79)
at org.ankus.hadoop.mapreduce.algorithm.cf.recommender.CFRecommenderDriver.main(CFRecommenderDriver.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:68)
at org.apache.hadoop.util.ProgramDriver.driver(ProgramDriver.java:139)
at org.ankus.hadoop.mapreduce.MapReduceDriver.main(MapReduceDriver.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.InstantiationException
at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
... 29 more

I don't know what exactly the problem. Please help me.

like image 246
user1976546 Avatar asked Jan 13 '23 00:01

user1976546


2 Answers

You can not use the abstract class FileInputFormat directly. If your inputs are text, you can use org.apache.hadoop.mapreduce.lib.input.TextInputFormat. For example,

MultipleInputs.addInputPath(job1, new Path(args[0]), TextInputFormat.class);
MultipleInputs.addInputPath(job1, new Path(args[1]), TextInputFormat.class);
like image 88
zsxwing Avatar answered Jan 19 '23 11:01

zsxwing


This is how you can use multiple input files in your job:

job1.setInputFormatClass(TextInputFormat.class);

FileInputFormat.setInputPaths(job1, input_1 + ","
                + input_2);
like image 39
Ashish Avatar answered Jan 19 '23 10:01

Ashish