SimpleDao
Hbase操作
2019-05-06, 访问数: 944

建表

  1. create 'table1', {
  2. NAME => 'card',
  3. DATA_BLOCK_ENCODING => 'NONE',
  4. BLOOMFILTER => 'ROWCOL',
  5. REPLICATION_SCOPE => '1',
  6. COMPRESSION => 'SNAPPY',
  7. VERSIONS => '1',
  8. MIN_VERSIONS => '0',
  9. KEEP_DELETED_CELLS => 'false',
  10. BLOCKSIZE => '65536',
  11. IN_MEMORY => 'false',
  12. BLOCKCACHE => 'false'
  13. }

数据操作

  1. put 'table1', 'rowkey1', 'card:col3', 'value3'
  2. get 'table1', 'rowkey1', {COLUMN => ['card:col1', 'card:col2']}
  3. scan 'table1'

java

  1. public void test() {
  2. logger.info("test");
  3. Configuration conf = HBaseConfiguration.create();
  4. conf.set("hbase.master", "172.17.161.5:60000");
  5. conf.set("hbase.zookeeper.property.clientport", "2181");
  6. conf.set("hbase.zookeeper.quorum", "172.17.161.5");
  7. conf.set("zookeeper.znode.parent", "/hbase-rpt");
  8. try {
  9. Connection connection = ConnectionFactory.createConnection(conf);
  10. Admin admin = connection.getAdmin();
  11. TableName[] names = admin.listTableNames();
  12. for (TableName tableName : names) {
  13. logger.info("Table Name is : " + tableName.getNameAsString());
  14. }
  15. } catch (IOException e) {
  16. e.printStackTrace();
  17. }
  18. }