AnsweredAssumed Answered

Error occurred while instantiating com.mapr.fs.hbase.MapRTableMappingRules. Simple Java MapReduce on MapR-DB Table

Question asked by AnandMSA on Jul 12, 2016
Latest reply on Jul 14, 2016 by snayeem


I am trying to create a simple Java Map Reduce Job accessing Mapr-DB table. I have hbase-0.98.12. I issued this command.

hadoop jar ./hbase-mr-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.test.FreqCounter1 -libjars /opt/mapr/hbase/hbase-0.98.12/lib/hbase-*.jar:${HBASE_CLASSPATH}

Here is the program:

 

public class FreqCounter1 {

    static class Mapper1 extends TableMapper<ImmutableBytesWritable, IntWritable> {

        private int numRecords = 0;
        private static final IntWritable one = new IntWritable(1);

        @Override
        public void map(ImmutableBytesWritable row, Result values, Context context) throws IOException {
            // extract userKey from the compositeKey (userId + counter)
            ImmutableBytesWritable userKey = new ImmutableBytesWritable(row.get(), 0, Bytes.SIZEOF_INT);
            try {
                context.write(userKey, one);
            } catch (InterruptedException e) {
                throw new IOException(e);
            }
            numRecords++;
            if ((numRecords % 10000) == 0) {
                context.setStatus("mapper processed " + numRecords + " records so far");
            }
        }
    }

    public static class Reducer1 extends TableReducer<ImmutableBytesWritable, IntWritable, ImmutableBytesWritable> {
        public void reduce(ImmutableBytesWritable key, Iterable<IntWritable> values, Context context)
                throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {
                sum += val.get();
            }

            Put put = new Put(key.get());
            put.add(Bytes.toBytes("details"), Bytes.toBytes("total"), Bytes.toBytes(sum));
            System.out.println(String.format("stats :   key : %d,  count : %d", Bytes.toInt(key.get()), sum));
            context.write(key, put);
        }
    }
   
    public static void main(String[] args) throws Exception {
              
        Configuration conf = HBaseConfiguration.create();
       
        @SuppressWarnings("deprecation")
  Job job = new Job(conf, "Hbase_FreqCounter1");
        job.setJarByClass(FreqCounter1.class);
        Scan scan = new Scan();
        //String columns = "details"; // comma seperated
        //scan.addColumns(columns);
        scan.addColumn(Bytes.toBytes("f"), Bytes.toBytes("upcDescription"));
        scan.setFilter(new FirstKeyOnlyFilter());
        TableMapReduceUtil.initTableMapperJob("access_logs", scan, Mapper1.class, ImmutableBytesWritable.class,
                IntWritable.class, job);
        TableMapReduceUtil.initTableReducerJob("summary_user", Reducer1.class, job);
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

 

Here is pom.xml

 

<repository>
  <id>mapr-maven</id>
  <url>http://repository.mapr.com/maven</url>
  <releases>
  <enabled>true</enabled>
  </releases>
  <snapshots>
  <enabled>false</enabled>
  </snapshots>


</repository>

</repositories>

  <dependencies>




<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-client</artifactId>
  <version>0.98.12-mapr-1506-m7-5.0.0</version>
</dependency>


<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-common</artifactId>
    <version>0.98.12-mapr-1602-m7-5.0.0</version>
</dependency>


<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-examples</artifactId>
    <version>0.98.12-mapr-1602-m7-5.0.0</version>
</dependency>

 

I am  getting this exception :

 

16/07/12 14:35:11 ERROR mapreduce.TableOutputFormat: java.io.IOException: java.lang.RuntimeException: Error occurred while instantiating com.mapr.fs.hbase.MapRTableMappingRules.
==> org/apache/hadoop/hbase/client/mapr/BaseTableMappingRules.
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: java.lang.RuntimeException: Error occurred while instantiating com.mapr.fs.hbase.MapRTableMappingRules.
==> org/apache/hadoop/hbase/client/mapr/BaseTableMappingRules.
        at org.apache.hadoop.hbase.mapreduce.TableOutputFormat.setConf(TableOutputFormat.java:211)
        at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:76)
        at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:136)
        at org.apache.hadoop.mapreduce.JobSubmitter.checkSpecs(JobSubmitter.java:266)
        at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:142)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1290)
        at org.apache.hadoop.mapreduce.Job$10.run(Job.java:1287)
        at java.security.AccessController.doPrivileged(Native Method)
        at javax.security.auth.Subject.doAs(Subject.java:422)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1595)
        at org.apache.hadoop.mapreduce.Job.submit(Job.java:1287)
        at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:1308)
        at com.msais.ims.pos.FreqCounter1.main(FreqCounter1.java:80)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: java.lang.RuntimeException: Error occurred while instantiating com.mapr.fs.hbase.MapRTableMappingRules.
==> org/apache/hadoop/hbase/client/mapr/BaseTableMappingRules.
        at org.apache.hadoop.hbase.client.mapr.TableMappingRulesFactory.create(TableMappingRulesFactory.java:65)
        at org.apache.hadoop.hbase.client.HTable.initIfMapRTable(HTable.java:440)
        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:204)
        at org.apache.hadoop.hbase.client.HTable.<init>(HTable.java:172)
        at org.apache.hadoop.hbase.mapreduce.TableOutputFormat.setConf(TableOutputFormat.java:206)
        ... 18 more
Caused by: java.lang.RuntimeException: Error occurred while instantiating com.mapr.fs.hbase.MapRTableMappingRules.
==> org/apache/hadoop/hbase/client/mapr/BaseTableMappingRules.
        at org.apache.hadoop.hbase.client.mapr.GenericHFactory.getImplementorInstance(GenericHFactory.java:40)
        at org.apache.hadoop.hbase.client.mapr.TableMappingRulesFactory.create(TableMappingRulesFactory.java:47)
        ... 22 more
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/client/mapr/BaseTableMappingRules
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at org.apache.hadoop.hbase.client.mapr.GenericHFactory.getImplementorInstance(GenericHFactory.java:30)
        ... 23 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.client.mapr.BaseTableMappingRules
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 39 more

 

Note: If I run the logic as a simple Java program, it is working I am able to access the table, read/write in the table. I am facing this issue, only when I try to run this as MapReduce program. Can somebody help me to fix this please?

 

$ rpm -qa | grep -i mapr

mapr-hadoop-core-2.7.0.32987.GA-1.x86_64

mapr-zookeeper-5.0.0.32987.GA-1.x86_64

mapr-patch-5.0.0.32987.GA-38165.x86_64

mapr-asynchbase-1.6.0.201504271624-1.noarch

mapr-core-internal-5.0.0.32987.GA-1.x86_64

mapr-mapreduce2-2.7.0.32987.GA-1.x86_64

mapr-mapreduce1-0.20.2.32987.GA-1.x86_64

mapr-nfs-5.0.0.32987.GA-1.x86_64

mapr-hbase-0.98.12.201507081709-1.noarch

mapr-hive-1.2.201604040723-1.noarch

mapr-drill-1.6.0.201603302146-1.noarch

mapr-core-5.0.0.32987.GA-1.x86_64

mapr-zk-internal-5.0.0.32987.GA.v3.4.5-1.x86_64

mapr-nodemanager-2.7.0.32987.GA-1.x86_64

mapr-fileserver-5.0.0.32987.GA-1.x86_64

mapr-spark-1.5.2.201604040801-1.noarch

Outcomes