没有 id 的 HBase 扫描值

HBase scan values without their id

我正在尝试在 Java 上使用 HBase 创建一个列表。我可以一起获取值,但我很困惑如何将它们分配给变量。(String bookName = ...,String bookAuthor = ...)

我需要获取贡献 table 中的所有值,并将它们分配给变量。

contributetable中有id,author,name.

HTable hTable = new HTable(hConn.config, "contribute");
            Scan scan = new Scan();
            scan.addColumn(Bytes.toBytes("book"), Bytes.toBytes("author"));
            scan.addColumn(Bytes.toBytes("book"), Bytes.toBytes("name"));
            ResultScanner scanner = hTable.getScanner(scan);
            for (Result result = scanner.next(); result != null; result = scanner.next())
            {
                for(KeyValue keyValue : result.list()) {
                    System.out.println("Qualifier : " + Bytes.toString(keyValue.getKey()) + " : Value : " + Bytes.toString(keyValue.getValue()));
                }
            }

Qualifier : $dba190f6-ff45-4d5b-bf2f-d2ea75bb528fbookauthorT�� : Value : Frans Hoffman

Qualifier : $dba190f6-ff45-4d5b-bf2f-d2ea75bb528fbooknameT�� : Value : h32

当我检查它们时,keyValue.getKey()keyValue.getValue() 显示 table 中的每个值。 有没有可能得到具体的value/qualify?例如,我只需要获取 name.

的值

我的理解: 您只想获得一列 name

        HTable hTable = new HTable(hConn.config, "contribute");
        Scan scan = new Scan();
        scan.addColumn(Bytes.toBytes("book"), Bytes.toBytes("author"));
        scan.addColumn(Bytes.toBytes("book"), Bytes.toBytes("name"));
        ResultScanner scanner = hTable.getScanner(scan);

for (Result rr = scan.next() ; rr != null; rr = scan.next())  { 
NavigableMap familyMap = rr.getFamilyMap(Bytes.toBytes("book")); 
byte[] name = (byte[]) familyMap.get(Bytes.toBytes("name")); 
System.out.println(Bytes.toString(name)); // This you can assign it to variable
}