我试图用 Java 代码编写一个简单的 HBase 数据操作
代码如下
public static void main(String[] args) {
Configuration hBconfig = HBaseConfiguration.create();
hBconfig.addResource(new Path("/home/circar/hbase/conf/hbase-site.xml"));
try {
HTable hTable = new HTable(hBconfig, "exampleHbTable");
Result result = hTable.get(new Get(Bytes.toBytes("ExampleRow1")));
List<KeyValue> keyValList = result.list();
for(KeyValue keyValue : keyValList){
System.out.println("a. Key:"+keyValue.getKeyString());
System.out.println("a. KeyType:"+keyValue.getType());
System.out.println("a. Row:"+keyValue.getRow().toString());
System.out.println("a. Family:"+keyValue.getFamily().toString());
System.out.println("a. Qualifier:"+keyValue.getQualifier().toString());
System.out.println("a. Value:"+keyValue.getValue().toString());
System.out.println("a. TotalColLength:"+keyValue.getTotalColumnLength());
System.out.println("a. TimeStamp:"+keyValue.getTimestamp());
SplitKeyValue splitKeyValue = keyValue.split();
System.out.println("b. KeyType:"+splitKeyValue.getType());
System.out.println("b. Row:"+splitKeyValue.getRow().toString());
System.out.println("b. Family:"+splitKeyValue.getFamily().toString());
System.out.println("b. Qualifier:"+splitKeyValue.getQualifier().toString());
System.out.println("b. Value:"+splitKeyValue.getValue().toString());
System.out.println("b. TimeStamp:"+splitKeyValue.getTimestamp());
}
} catch (IOException e) {
e.printStackTrace();
}
}
结果显示为
13/06/21 18:15:29 INFO zookeeper.ClientCnxn: Socket connection established to localhost/127.0.0.1:2181, initiating session
13/06/21 18:15:29 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13f66c41fc90003, negotiated timeout = 40000
a. Key:\x00\x0BExampleRow1\x10CircarConsultingMapReduce\x00\x00\x01?f\x16m\x0D\x04
a. KeyType:4
a. Row:[B@15718f2
a. Family:[B@126f827
a. Qualifier:[B@16dfa45
a. Value:[B@149eb9f
a. TotalColLength:25
a. TimeStamp:1371807313165
b. KeyType:[B@289d2e
b. Row:[B@6754d6
b. Family:[B@1f2cea2
b. Qualifier:[B@1dc0e7a
b. Value:[B@3a9bba
b. TimeStamp:[B@1c5ddc9
a. Key:\x00\x0BExampleRow1\x08ProjectsMapReduce\x00\x00\x01?f\x16m\x0D\x04
a. KeyType:4
a. Row:[B@163f7a1
a. Family:[B@1690ab
a. Qualifier:[B@173ec72
a. Value:[B@1a85d38
a. TotalColLength:17
a. TimeStamp:1371807313165
b. KeyType:[B@8046f4
b. Row:[B@1b273cc
b. Family:[B@d05c13
b. Qualifier:[B@14d1d41
b. Value:[B@1bbd7b2
b. TimeStamp:[B@14df764
但它具有 HBase Shell 中显示的值如下:
~-desktop:~$ sudo hbase/bin/hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.8, r1485407, Wed May 22 20:53:13 UTC 2013
hbase(main):001:0>
hbase(main):002:0* list
TABLE
exampleHbTable
1 row(s) in 0.7540 seconds
hbase(main):003:0> scan 'exampleHbTable'
ROW COLUMN+CELL
ExampleRow1 column=CircarConsulting:MapReduce, timestamp=1371807313165, value=Hadoop
ExampleRow1 column=Projects:MapReduce, timestamp=1371807313165, value=MyProject
1 row(s) in 0.1170 seconds
hbase(main):004:0>
有人可以提供任何想法来使用 Java 代码获得实际的可读值吗?