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 ...
随机推荐
- Laravel Eloquent 判断取出的结果集是否为空
在使用Laravel Eloquent模型时,我们可能要判断取出的结果集是否为空,但我们发现直接使用is_null或empty是无法判段它结果集是否为空的. var_dump之后我们很容易发现,即使取 ...
- 【翻译】Kinect v1和Kinect v2的彻底比较
本连载主要是比较Kinect for Windows的现行版(v1)和次世代型的开发者预览版(v2),以C++开发者为背景介绍进化的硬件和软件.本文主要是对传感的配置和运行条件进行彻底的比较. ...
- mysqli_multi_query($link, $wsql)
if (mysqli_multi_query($link, $wsql)) { do { if ($result = mysqli_store_result($link)) { mysqli_free ...
- 页面瀑布流布局的实现 javascript+css
先看所谓的瀑布流布局 在不使用瀑布流布局的情况下,当页面要显示不同高度的图片时,会如下面显示 下面的元素总是和最靠近它的元素对齐. 为了使元素能够在我们想要的位置上显示,我们使用绝对定位. 说一下大体 ...
- correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. { var arVersion = ...
- 在XE5中 VCL空窗体的3个线程
中午看到技术群里有人讨论, XE5一个空窗体程序就包含了3个线程, 赶忙打开XE5开了个空窗体一看, 果然如此 再打开D7和2010看了一下, 都是一个线程 这时看到有人说一个是输入法, 一个是GDI ...
- php判断爬虫
function checkrobot($useragent = ''){ static $kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos ...
- Unix网络编程(迭代服务器)
#include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/soc ...
- Java 进程(转)
转自http://jiangshuiy.iteye.com/blog/1674235 PS:今天做android助手项目的时候,发现adb push命令执行会卡死,最后发现不能用waitfor阻塞等待 ...
- T450的Fn lock
新到手一台T450,有一点让我比较恼火,就是F1~F12不能直接按必须先按Fn. 使用一阵突然发现,按住Fn+Esc能锁定/解锁Fn,锁定后F1~F12就可以直接按了. 设计者想得还是比较周到的. 2 ...