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 ...
随机推荐
- jquery CDN(内容分发网络)使用
jquery CDN 给开发者提供一种捷径,即不下载jquary 就通过CDN能使用各个版本的jquery. 使用方法很简单,就是在HTML 文档中引用相关版本的jquery. 例如:我用百度的CDN ...
- CSS3系列:魔法系列
一.三角形 #wrap div{ margin: 0 auto; } .triangle_three { height:0px; width:0px; border-bottom:50px solid ...
- c++ windows 获取mac地址
c++ windows 获取mac地址 GetAdaptersInfo 用windows api获取mac地址和硬盘id编号 aa
- Ubuntu 14.04 LTS 安装 VNC Viewer
1.修改镜像源: /etc/apt/sources.list将"http://archive.ubuntu.com/ubuntu/"替换为: http://cn.archive.u ...
- 树莓派学Python博客收集
http://www.geekfan.net/8657/ 这个博客是控制LED,虽然不是原创地址不是这,但是我觉得排版比较好. http://my.oschina.net/RagingTyphoon ...
- 纯CSS制作三角(转)
原原文地址:http://www.w3cplus.com/code/303.html 原文地址:http://blog.csdn.net/dyllove98/article/details/89670 ...
- memcached学习笔记2--安装及命令
学习memcached的原理: 用户一 -> 访问浏览器 -> 服务器Apache -> PHP文件(该文件应用了memcached技术) -> [第一次]到数据库DB中查找数 ...
- delphi 高版本可执行程序减小的办法
选菜单里的 Project -> Options.. (Shift+Ctrl+F11)出现Project Options for Project1.exe窗口,在左边选 Packages出现如下 ...
- jq窗口类小问题
if ($(window).height() + $(window).scrollTop() >= $(document.body).height() - options.marginBotto ...
- Java高级之线程同步
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于实现多线程的意义,"从业四年看并发"一文已经讲述,而本篇主要讲一下常用的设计 ...