hbaseアクセス方式のjava appi
Hbaseのアクセス方式
1、Native Java API:最も一般的で効率的なアクセス方式。
2、HBase Shell:HBaseのコマンドラインツールは、最も簡単なインターフェースで、HBaseの管理に適しています。
3、Thrift Gateway:Thriftプログレッシブ技術を利用して、C++、PHP、Pythonなど多くの言語をサポートしています。他の異性システムに適合しています。オンラインでHBase表データを訪問します。
4、REST Gateway:RESTスタイルをサポートするHttp APIがHBaseにアクセスし、言語制限を解除しました。
5、MapReduce:直接MapReduce作業でHbaseデータを処理する;
6、PIg/hiveを使ってHbaseデータを処理します。
常用Java APIの使い方:
1、ロードプロファイル
以上は小编が皆さんに绍介したhbase访问方式のjava apiです。皆さんに助けてほしいです。もし何か疑问があれば、メッセージをください。小编はすぐに皆さんに返事します。ここでも私たちのサイトを応援してくれてありがとうございます。
1、Native Java API:最も一般的で効率的なアクセス方式。
2、HBase Shell:HBaseのコマンドラインツールは、最も簡単なインターフェースで、HBaseの管理に適しています。
3、Thrift Gateway:Thriftプログレッシブ技術を利用して、C++、PHP、Pythonなど多くの言語をサポートしています。他の異性システムに適合しています。オンラインでHBase表データを訪問します。
4、REST Gateway:RESTスタイルをサポートするHttp APIがHBaseにアクセスし、言語制限を解除しました。
5、MapReduce:直接MapReduce作業でHbaseデータを処理する;
6、PIg/hiveを使ってHbaseデータを処理します。
常用Java APIの使い方:
1、ロードプロファイル
Configuration config = HBaseConfiguration.create();
// ,
/*config.set("hbase.zookeeper.property.clientPort", "4181");
config.set("hbase.zookeeper.quorum", "hadoop.datanode5.com,hadoop.datanode2.com,hadoop.datanode3.com");
config.set("hbase.master", "hadoop.datanode3.com\\:600000");*/
2、表の作成、表情報の修正、表の削除
HBaseAdmin admin = new HBaseAdmin(config);
//
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor("cf1"));
htd.addFamily(new HColumnDescriptor("cf2"));
admin.createTable(htd);
//
admin.disableTable(tableName);
// modifying existing ColumnFamily
admin.modifyColumn(tableName, new HColumnDescriptor("cf1"));
admin.enableTable(tableName);
//
admin.disableTable(Bytes.toBytes(tableName));
admin.deleteTable(Bytes.toBytes(tableName));
3、記録を追加する
/** , HTablePool
HTable table = new HTable(config, tableName);
=>
HTablePool pool = new HTablePool(config, 1000);
HTableInterface table = pool.getTable(tableName);*/
HTable table = new HTable(config, tableName);
/**
* ,
* ,
* flushCommits();
*/
/*table.setAutoFlush(false);
table.setWriteBufferSize(1024);*/
Put put1 = new Put(Bytes.toBytes(rowKey));
if (ts == 0) {
put1.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
} else {
// , , long
put1.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), ts,Bytes.toBytes(value));
}
table.put(put1);
//table.flushCommits();
4、照会し、Rowkeyによって照会する。
Get get1 = new Get(Bytes.toBytes(rowKey));
Result result = table.get(get1);
System.out.println("get result:" + Bytes.toString(result.getValue(Bytes.toBytes(family), Bytes.toBytes(qualifier))));
Result[] result = table.get(List<Get>);// Rowkey
5、照会、指定条件とrowkey区間クエリ
Scan scan = new Scan();
// 1, , scan next() ,
scan.setCaching(500);
scan.setCacheBlocks(false);
// startRowKey、endRowKey
//Scan scan = new Scan(Bytes.toBytes("startRowKey"), Bytes.toBytes("endRowKey"));
//rowKey , List add;
/**List<Filter> filters = new ArrayList<Filter>();
Filter filter = new SingleColumnValueFilter("familyName".getBytes(),
"qualifierName".getBytes(),
CompareOp.EQUAL,
Bytes.toBytes("value"));
filters.add(filter);
scan.setFilter(new FilterList(filters));*/
ResultScanner scanner = table.getScanner(scan);
System.out.println("scan result list:");
for (Result result : scanner) {
System.out.println(Bytes.toString(result.getRow()));
System.out.println(Bytes.toString(result.getValue(Bytes.toBytes("data"), Bytes.toBytes("data1"))));
System.out.println(Bytes.toString(result.getValue(Bytes.toBytes("data"), Bytes.toBytes("data2"))));
}
scanner.close();
締め括りをつける以上は小编が皆さんに绍介したhbase访问方式のjava apiです。皆さんに助けてほしいです。もし何か疑问があれば、メッセージをください。小编はすぐに皆さんに返事します。ここでも私たちのサイトを応援してくれてありがとうございます。