hbase基本操作
public class Demo {
private Configuration conf;
private Connection conn;
@Before
public void prepare() throws Exception {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "m6,m7,m8");
conn = ConnectionFactory.createConnection(conf);
}
/**
* 创建表
*/
@Test
public void createTable() throws Exception {
Admin admin = conn.getAdmin();
TableName tableName = TableName.valueOf("t_person");
HTableDescriptor hTableDescriptor = new HTableDescriptor(tableName);
// 添加列簇
HColumnDescriptor baseInfo = new HColumnDescriptor("base_info");
hTableDescriptor.addFamily(baseInfo);
admin.createTable(hTableDescriptor);
admin.close();
conn.close();
}
/**
* 删除表
* @throws Exception
*/
@Test
public void dropTable() throws Exception {
Admin admin = conn.getAdmin();
admin.disableTable(TableName.valueOf("t_person"));
admin.deleteTable(TableName.valueOf("t_person"));
admin.close();
}
/**
* 插入数据
* @throws Exception
*/
@Test
public void put() throws Exception {
TableName tableName = TableName.valueOf("t_person");
// HTablePool pool = new HTablePool(conf, 10);
// HTable table = (HTable) pool.getTable("t_person");
Table table = conn.getTable(tableName);
// rowkey 行健
Put put = new Put(Bytes.toBytes("p_0001"));
put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("name"), Bytes.toBytes("zhangsan"));
put.addColumn(Bytes.toBytes("base_info"), Bytes.toBytes("age"), Bytes.toBytes(18));
table.put(put);
table.close();
}
/**
* 获取数据
* @throws IOException
*/
@Test
public void get() throws IOException {
TableName tableName = TableName.valueOf("t_person");
Table table = conn.getTable(tableName);
Get get = new Get(Bytes.toBytes("p_0001"));
Result result = table.get(get);
for (Cell cell : result.listCells()) {
System.out.println(Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println(Bytes.toString(CellUtil.cloneQualifier(cell)));
System.out.println(Bytes.toInt(CellUtil.cloneValue(cell)));
}
}
@Test
public void scan() throws IOException {
TableName tableName = TableName.valueOf("t_person");
Table table = conn.getTable(tableName);
Scan scan = new Scan();
// 根据Qualifier的开头字符进行过滤
ColumnPrefixFilter filter = new ColumnPrefixFilter(Bytes.toBytes("z"));
scan.setFilter(filter);
ResultScanner scanner = table.getScanner(scan);
for (Result result : scanner) {
for (Cell cell : result.listCells()) {
System.out.println(Bytes.toString(CellUtil.cloneFamily(cell)));
System.out.println(Bytes.toString(CellUtil.cloneQualifier(cell)));
}
}
}
}
hbase基本操作的更多相关文章
- 熟悉HBase基本操作
1. ssh localhost start-dfs.sh start-hbase.sh hbase shell create 'Student', 'S_No', 'S_Name', 'S_Sex' ...
- Hbase记录-HBase基本操作(二)
HBase Exists 可以使用exists命令验证表的存在.下面的示例演示了如何使用这个命令. hbase(main):024:0> exists 'emp' Table emp doe ...
- Hbase记录-HBase基本操作(一)
HBase创建表 可以使用命令创建一个表,在这里必须指定表名和列族名.在HBase shell中创建表的语法如下所示. create ‘<table name>’,’<column ...
- HBase 基本操作
如何添加列族 很简单,跟rdbms一样 直接用alter,但是alter之前必须先disable这个表 ---->disable 'test' ...
- hadoop之hbase基本操作
hbase shell 进入hbase命令行 list 显示HBASE表 status 系统上运行的服务器的细节和系统的状态 version 返回HBase系统使用的版本 table_help 引导如 ...
- HBase基本操作-Java实现
创建Table public static void createTable(String tableName){ try { HBaseAdmin hbaseAdmin = new HBaseAdm ...
- HBase笔记--编程实战
HBase总结:http://blog.csdn.net/lifuxiangcaohui/article/details/39997205 (very good) Spark使用Java读取hbas ...
- 第四章:大数据 の HBase 基础
本课主题 NoSQL 数据库介绍 HBase 基本操作 HBase 集群架构与设计介紹 HBase 与HDFS的关系 HBase 数据拆分和紧缩 引言 介绍什么是 NoSQL,NoSQL 和 RDBM ...
- Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)
声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...
随机推荐
- SDUT 2610 Boring Counting(离散化+主席树区间内的区间求和)
Boring Counting Time Limit: 3000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Descriptio ...
- NBUT 1457 Sona(莫队算法+离散化)
[1457] Sona 时间限制: 5000 ms 内存限制: 65535 K 问题描述 Sona, Maven of the Strings. Of cause, she can play the ...
- 【IOS笔记】About Events in iOS
About Events in iOS Users manipulate their iOS devices in a number of ways, such as touching the scr ...
- Oracle数据库--SQL函数
Oracle SQL函数 1.ASCII返回与指定的字符对应的十进制数;SQL> select ascii('A') A,ascii('a') a,ascii('0') zero,ascii( ...
- Linux下监控磁盘使用量并在超过阀值后自动发送报警邮件
最近Linux服务器磁盘使用量经常到100%,直到影响到正常服务出现故障才会去注意,做不到防患于未然,今天在网上搜集了资料,加上自己修改,写了一个shell脚本用于实时监控磁盘使用量并在超过阀值后自动 ...
- ubuntu lnmp
apt-get update apt-get upgrade apt-get install libxml2 libxml2-dev apt-get install make apt-get inst ...
- laravel 视图组件
假设有一个文件被多个视图需要,比如导航条: 1.在路由文件添加 View::composer('stats', function($view){ $view->with('stats', app ...
- Java高级之虚拟机垃圾回收机制
博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 区别于C语言手动回收,Java自动执行垃圾回收,但为了执行高效 ...
- C++ 简单中文敏感词检测工具类
具体思路: 1->敏感词库,可从数据库读取,也可以从文件加载. 2->将敏感词转化为gbk编码,因为gbk严格按照字符一个字节,汉字两个字节的格式编码,便于容易切分文字段. 3->将 ...
- PE文件格式图示