4

我对这个大数据真的很陌生,我需要知道 hbase 是否可以嵌入到 java 应用程序中。

由于它是在 java 中开发的,可以将 hbase 作为库添加并进行操作吗?

如果是这样,任何人都可以提供一个简单的教程或示例代码。

4

2 回答 2

4

HBase 不运行嵌入式,它运行在 Hadoop 之上,它针对大数据和大量服务器。

它确实有一个 Java API,您可以使用它,例如 Charles Menguy 的回复

于 2013-01-19T14:02:23.637 回答
3

您绝对可以编写一个 Java 应用程序来使用 Hbase,主 Hbase 发行版中提供了一个 Java API。

您应该从官方网站获取最新版本并获取hbase-0.xx.x.jar可用于构建应用程序的 jar。如果你想查看 hbase 的类路径依赖关系,一旦你安装了 hbase,你就可以这样做hbase classpath,这应该会打印出你需要的 jar 列表。

您可能会在 Google 上找到很多 Java 应用程序执行 Hbase 操作的示例,但这里有一个通常操作的示例:

// get the hbase config
Configuration config = HBaseConfiguration.create();

// specify which table you want to use
HTable table = new HTable(config, "mytable");
// add a row to your table
Put p = new Put(Bytes.toBytes("myrow"));    
// specify the column family, column qualifier and column value
p.add(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"), Bytes.toBytes("myvalue"));
// commit to your table
table.put(p);

// define which row you want to get 
Get g = new Get(Bytes.toBytes("myrow"));
// get your row
Result r = table.get(g);
// choose what you want to extract from your row
byte[] value = r.getValue(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"));
// convert to a string
System.out.println("GET: " + Bytes.toString(value)); 

// do a scan operation
Scan s = new Scan();
s.addColumn(Bytes.toBytes("myfamily"), Bytes.toBytes("myqualifier"));
ResultScanner scanner = table.getScanner(s);
于 2013-01-18T23:07:04.887 回答