1

我正在尝试使用 Hbase REST API 查询 Mapr 表。我开始使用 hbase 休息服务./hbase-daemon.sh并编写了一个小程序来查询我的表,但它似乎不起作用。但是当我使用 curl 工具从 MapR 表中获取数据时,它会给我正确的输出。

这是我正在使用的 java 代码:

 import java.io.IOException;
 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.HTableInterface;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.rest.client.Client;
 import org.apache.hadoop.hbase.rest.client.Cluster;
 import org.apache.hadoop.hbase.rest.client.RemoteHTable;

 public class GetRequest
 {
 public static void main(String[] args) throws IOException
 {


         Cluster cluster = new Cluster();
         cluster.add(hostname, 8081);
         Client client = new Client(cluster);
         RemoteHTable table = new RemoteHTable(client, "/mytesttable");   //Remove forward slash to query in hbase table

         Get request = new Get(Bytes.toBytes("metric"));
         request.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("c"));
         Result result = table.get(request);
         System.out.println("Output Returned from Table--->  "+ Bytes.toString( result.getValue(Bytes.toBytes("cf"), Bytes.toBytes("c"))));
     }
 }

这是返回正确输出的 curl 命令。

curl -H "Accept: text/xml" http://hostname:8081/%2Fmytesttable/metric/cf:c

不知道这里有什么问题?任何猜测,任何人?

提前致谢。

4

2 回答 2

1

MapR 将使用warden 启动自己的hbase rest 服务器,您不需要手动启动它。它将在8080 端口(默认端口)上运行。确保您的 hbase rest 服务;您可以检查 mapr 集群管理 UI。

于 2015-07-21T07:14:20.917 回答
0

我使用的命令是,

userDetails=用户名+":"+密码

"curl -k -u" + userDetails + " https://" + ip + ":" + port + "/rest/table/create?path=" + path + tableName

于 2015-12-26T11:15:03.257 回答