gpt4 book ai didi

java - 如何从Hbase读取数据?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:45:15 31 4
gpt4 key购买 nike

您好,我习惯使用 SQL,但我需要从 HBase 表中读取数据。在这方面的任何帮助都会很棒。一本书或者只是一些示例代码可以从表中读取。有人说用扫描仪就可以了,但我不知道怎么用。

最佳答案

来自 the website :

// Sometimes, you won't know the row you're looking for. In this case, you
// use a Scanner. This will give you cursor-like interface to the contents
// of the table. To set up a Scanner, do like you did above making a Put
// and a Get, create a Scan. Adorn it with column names, etc.
Scan s = new Scan();
s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"));
ResultScanner scanner = table.getScanner(s);
try {
// Scanners return Result instances.
// Now, for the actual iteration. One way is to use a while loop like so:
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
// print out the row we found and the columns we were looking for
System.out.println("Found row: " + rr);
}

// The other approach is to use a foreach loop. Scanners are iterable!
// for (Result rr : scanner) {
// System.out.println("Found row: " + rr);
// }
} finally {
// Make sure you close your scanners when you are done!
// Thats why we have it inside a try/finally clause
scanner.close();
}

关于java - 如何从Hbase读取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2431387/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com