hbase操作

建表

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

数据操作

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

java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public void test() {
logger.info("test");

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master", "172.17.161.5:60000");
conf.set("hbase.zookeeper.property.clientport", "2181");
conf.set("hbase.zookeeper.quorum", "172.17.161.5");
conf.set("zookeeper.znode.parent", "/hbase-rpt");

try {
Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin();

TableName[] names = admin.listTableNames();
for (TableName tableName : names) {
logger.info("Table Name is : " + tableName.getNameAsString());
}
} catch (IOException e) {
e.printStackTrace();
}
}
文章目录
  1. 1. 建表
  2. 2. 数据操作
  3. 3. java