我正在尝试使用 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
不知道这里有什么问题?任何猜测,任何人?
提前致谢。