我试图从一个在M3 MapR集群的节点内运行的简单Java应用程序与MapR-DB表进行交互。似乎我能够连接到群集,但显然我无法正确连接到表。这是代码片段:
Configuration configuration = new Configuration();
configuration.set("hbase.zookeeper.quorum", "192.168.2.1,192.168.2.2,192.168.2.3");
configuration.set("hbase.zookeeper.property.clientPort", "5181");
configuration.set("mapr.htable.impl", "com.mapr.fs.MapRHTable");
configuration.set("hbase.table.namespace.mappings", "*:/user/mapr/");
configuration = HBaseConfiguration.create(configuration);
HConnection connection = HConnectionManager.createConnection(configuration);
System.out.println("Is Master running? " + connection.isMasterRunning());
String tableName = args[0];
HTable table = (HTable) connection.getTable(tableName.getBytes());
for (HColumnDescriptor columnFamily : table.getTableDescriptor().getColumnFamilies()) {
System.out.println("Column family: " + columnFamily.getNameAsString());
}
我有一个名为" / user / mapr / test_table" (我在MapR Web控制台中看到它,我可以通过hbase shell
访问它)。使用表名的任何合理参数运行代码只会返回以下异常:
org.apache.hadoop.hbase.TableNotFoundException: /user/mapr/test_table
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getHTableDescriptor(HConnectionManager.java:2750)
at org.apache.hadoop.hbase.client.HTable.getTableDescriptor(HTable.java:701)
at it.noovle.bigdata.hadoop.MaprDBLocalTest.main(MaprDBLocalTest.java:49)
hbase shell
我只需使用' / user / mapr / test_table'。答案 0 :(得分:1)
要连接到MapR-DB,您不需要连接到Zookeeper。要打开表,您必须提供绝对路径。对于例如/ user / mapr / test_table。 附上一个简单的例子:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
public class HBaseExample {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
HTable table = new HTable(config, "/user/mapr/test_table");
Put p = new Put(Bytes.toBytes("row1"));
p.add(Bytes.toBytes("cf1"), Bytes.toBytes("col2"),
Bytes.toBytes("ABC"));
table.put(p);
Get g = new Get(Bytes.toBytes("row1"));
Result r = table.get(g);
byte[] value = r.getValue(Bytes.toBytes("cf1"),
Bytes.toBytes("col2"));
String valueStr = Bytes.toString(value);
System.out.println("GET: " + valueStr);
Scan s = new Scan();
s.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col2"));
ResultScanner scanner = table.getScanner(s);
try {
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
System.out.println("Found row: " + rr);
}
} finally {
scanner.close();
}
}
}
这是hbase-site.xml,它取自MapR沙箱。
-bash-4.1$ cat ./hbase/hbase-0.98.7/conf/hbase-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>maprfs:///hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>maprdemo</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>5181</value>
</property>
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
<property>
<name>hbase.fsutil.maprfs.impl</name>
<value>org.apache.hadoop.hbase.util.FSMapRUtils</value>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>30</value>
<!-- default is 25 -->
</property>
<!-- uncomment this to enable fileclient logging
<property>
<name>fs.mapr.trace</name>
<value>debug</value>
</property>
-->
<!-- Allows file/db client to use 64 threads -->
<property>
<name>fs.mapr.threads</name>
<value>64</value>
</property>
</configuration>
-bash-4.1$
答案 1 :(得分:0)
MapR允许您根据您的安装使用:
&#34;名称&#34;该表的定义是否是&#34; MapR-DB&#34;或者&#34; Hbase&#34;表:
123
/apps/my_tables/users
然后,根据表的名称,客户端到达群集的方式各不相同:
客户端代码在MapR-DB或Hbase之间不会改变,只有表名和&#34;配置&#34;改变,我对配置的意思是:
我有一个小项目here