Accessing MapR DB without installing MapR Client

Document created by snayeem Employee on Feb 27, 2016
Version 1Show Document
  • View in full screen mode

Author: Sanjamala Nayeem

Original Publication Date: April 15, 2015



  • MapR v3.1.1+ latest EBF patch (mapr-patch- onwards)
  • MapR v4.0.2


To access MapR DB from application without installing MapR client for un-secure cluster.


To achieve this MapR has provided following configuration parameter to set cluster details at run time which allows to connect to that cluster.

conf.set("dfs.nameservices", clusterName); 
conf.set("dfs.ha.namenodes." + clusterName, "cldb1,cldb2,cldb3");
conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb1",cldb1node + ":7222");
  • In above snippet, we need to provide cluster name against dfs.nameservices.
  • Need to specify how many CLDB do we have, if we have HA implemented for CLDB and in this example we are having three cldbs, configured as cldb1,cldb2.cldb3. and against dfs.namenodes.<clustername>
  • Hostname of CLDB or IP addresses of CLDB with port  7222 need to be set against dfs.namenode.rpc-address.<clustername>.<cldbno>


import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HColumnDescriptor;

import org.apache.hadoop.hbase.HTableDescriptor;

import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Put;


public class SampleAccessMDB {


public static void main(String[] args) {

Configuration conf = new Configuration();

String clusterName = "gauth";

String cldb1node = "";

String cldb2node = "";

String cldb3node = "";


conf.setBoolean("fs.mapr.impl.clustername.unique", true);


conf.set("dfs.nameservices", clusterName);

conf.set("dfs.ha.namenodes." + clusterName, "cldb1,cldb2,cldb3");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb1",cldb1node + ":7222");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb2",cldb2node + ":7222");

conf.set("dfs.namenode.rpc-address." + clusterName + ".cldb3",cldb3node + ":7222");


  System.out.println("Check for Tables");

  String tableName = "/mapr/gauth/myTable"+System.currentTimeMillis();

  System.out.println("Table name: " + tableName);


HBaseAdmin admin = new HBaseAdmin(conf);

HTableDescriptor des = new HTableDescriptor(tableName.getBytes());


des.addFamily(new HColumnDescriptor("cf1".getBytes()));



Put put = new Put("r1".getBytes());


HTable table = new HTable(conf,tableName);


  }catch(Exception ex){





  • In the above sample we are trying to create table /mapr/gauth/myTable"+ Current timestamp in this path is /mapr/gauth and table name is myTable+time-in-millis.
3 people found this helpful