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基本操作的更多相关文章

  1. 熟悉HBase基本操作

    1. ssh localhost start-dfs.sh start-hbase.sh hbase shell create 'Student', 'S_No', 'S_Name', 'S_Sex' ...

  2. Hbase记录-HBase基本操作(二)

    HBase Exists   可以使用exists命令验证表的存在.下面的示例演示了如何使用这个命令. hbase(main):024:0> exists 'emp' Table emp doe ...

  3. Hbase记录-HBase基本操作(一)

    HBase创建表 可以使用命令创建一个表,在这里必须指定表名和列族名.在HBase shell中创建表的语法如下所示. create ‘<table name>’,’<column ...

  4. HBase 基本操作

    如何添加列族 很简单,跟rdbms一样 直接用alter,但是alter之前必须先disable这个表 ---->disable 'test'                          ...

  5. hadoop之hbase基本操作

    hbase shell 进入hbase命令行 list 显示HBASE表 status 系统上运行的服务器的细节和系统的状态 version 返回HBase系统使用的版本 table_help 引导如 ...

  6. HBase基本操作-Java实现

    创建Table public static void createTable(String tableName){ try { HBaseAdmin hbaseAdmin = new HBaseAdm ...

  7. HBase笔记--编程实战

    HBase总结:http://blog.csdn.net/lifuxiangcaohui/article/details/39997205  (very good) Spark使用Java读取hbas ...

  8. 第四章:大数据 の HBase 基础

    本课主题 NoSQL 数据库介绍 HBase 基本操作 HBase 集群架构与设计介紹 HBase 与HDFS的关系 HBase 数据拆分和紧缩 引言 介绍什么是 NoSQL,NoSQL 和 RDBM ...

  9. Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)

    声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...

随机推荐

  1. NSQ:分布式消息队列学习记录

    参考资料: NSQ:分布式的实时消息平台 初识NSQ分布式实时消息架构 深入NSQ之旅 nsq topic和channel的区别

  2. Windows编译安装OpenSSL

    windows下使用vs2008中的nmake编译安装openssl的脚本build.bat: echo off & color 0A :: 项目名称 set PROJECT=openssl ...

  3. 自动更新开奖数据的excel文件,供大家下载

    自动更新开奖数据的excel文件,供大家下载 2010-03-14 20:22 228492人阅读打印来源:乐彩网 作者:eren 很多人拥有自制excel电子表格,常要更新最基本的开奖信息.如有多期 ...

  4. [转]常用 Git 命令清单

    作者: 阮一峰 我每天使用 Git ,但是很多命令记不住. 一般来说,日常使用只要记住下图6个命令,就可以了.但是熟练使用,恐怕要记住60-100个命令. 下面是我整理的常用 Git 命令清单.几个专 ...

  5. Natural Language Processing Computational Linguistics

    http://www.nltk.org/book/ch00.html After this, the pace picks up, and we move on to a series of chap ...

  6. Machine Learning in Action -- Support Vector Machines

    虽然SVM本身算法理论,水比较深,很难懂 但是基本原理却非常直观易懂,就是找到与训练集中支持向量有最大间隔的超平面 形式化的描述: 其中需要满足m个约束条件,m为数据集大小,即数据集中的每个数据点fu ...

  7. Android progressbar 详解

    [原文Android学习笔记(十六)进度条] ProgressBar XML属性 属性名 描述 android:animationResolution 超时的动画帧之间的毫秒 :必须是一个整数值,如“ ...

  8. (转)投票系统,更改ip刷票

    前言 相信大家平时肯定会收到朋友发来的链接,打开一看,哦,需要投票.投完票后弹出一个页面(恭喜您,您已经投票成功),再次点击的时候发现,啊哈,您的IP(***.***.***.***)已经投过票了,不 ...

  9. nrf51822裸机教程-RTC

    RTC0被协议栈使用了.所以在跑蓝牙程序的情况下.RTC0不能使用. RTC相关寄存器如下: EVTEN,EVTENSET,EVTENCLR. 这三个寄存器用来设置是否使能某个事件.(TICK,OVR ...

  10. HBase的二级索引,以及phoenix的安装(需再做一次)

    一:HBase的二级索引 1.讲解 uid+ts 11111_20161126111111:查询某一uid的某一个时间段内的数据 查询某一时间段内所有用户的数据:按照时间 索引表 rowkey:ts+ ...