`

HBase Shell And JavaAPI使用

 
阅读更多

 

HBase shell操作

表创建

#进入hbase shell
[root@centos bin]# hbase shell
#创建一张user表,有三个列族
hbase(main):001:0> create 'user','uid','address','info44'
#查看表
hbase(main):002:0> list
TABLE
user

查看表结构

hbase(main):001:0> describe 'user'
DESCRIPTION                                                                                           ENABLED
 'user', {NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE  true
 => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELET
 ED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACH
 E => 'true'}, {NAME => 'info44', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_S
 COPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_
 DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOC
 KCACHE => 'true'}, {NAME => 'uid', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION
 _SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEE
 P_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BL
 OCKCACHE => 'true'}

 删除表

#不能直接删除
hbase(main):005:0* drop 'user'
ERROR: Table user is enabled. Disable it first.'
Here is some help for this command:
Drop the named table. Table must first be disabled: e.g. "hbase> drop 't1'"
#先disable一张表
hbase(main):006:0> disable 'user'
0 row(s) in 2.1410 seconds
#才能删除
hbase(main):007:0> drop 'user'
0 row(s) in 1.1180 seconds
hbase(main):008:0> list
TABLE
0 row(s) in 0.0400 seconds

 插入一条记录

#表明,行健,列族,值
hbase(main):004:0> put 'user','lisi','address:city','beijing'
hbase(main):005:0> get 'user','lisi'
COLUMN                                   CELL
 address:city                            timestamp=1439284919358, value=beijing
#查询address列族信息
hbase(main):005:0> get 'user','lisi','address'
#查询address列族中city修饰符
hbase(main):005:0> get 'user','lisi','address:city'

查看记录版本信息,默认最多显示3条例是版本

#查看wangwu info列族的age标识符版本信息
hbase(main):016:0> get 'user','wangwu',{COLUMN=>'info:age',VERSIONS=>3}
COLUMN                                   CELL
 info:age                                timestamp=1439285717405, value=28
 info:age                                timestamp=1439285714541, value=27
 info:age                                timestamp=1439285711351, value=26

 查询整长表

hbase(main):001:0> scan 'user'

删除一行记录

hbase(main):001:0> deleteall 'user','wangwu'

 

删除一列记录

#删除行健为wangwu的info列族中age标识符列
hbase(main):001:0>delete 'user','wangwu','info:age'

清空表数据

hbase(main):001:0> truncate 'user'

 

 

HBase JavaAPI

创建表

@Test
	public void createTableTest() throws Exception {
		Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://192.168.56.101:/hbase");
		configuration.set("hbase.zookeeper.quorum", "centos");
		
		HBaseAdmin hBaseAdmin = new HBaseAdmin(configuration);
		// exist table name
		if (!hBaseAdmin.tableExists("tablee")) {
			// create table
			HTableDescriptor tableDescriptor = new HTableDescriptor("tablee");
			// create colum family
			HColumnDescriptor columnDescriptor = new HColumnDescriptor("familyy");
			// set column family in table
			tableDescriptor.addFamily(columnDescriptor);
			// create
			hBaseAdmin.createTable(tableDescriptor);
		}
		hBaseAdmin.close();
	}

 删除表

@Test
	public void deleteTableTest() throws Exception {
		Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://192.168.56.101:/hbase");
		configuration.set("hbase.zookeeper.quorum", "centos");
		
		HBaseAdmin hBaseAdmin = new HBaseAdmin(configuration);
		hBaseAdmin.disableTable("tablee");
		hBaseAdmin.deleteTable("tablee");
		hBaseAdmin.close();
	}

 插入一条记录

@Test
	public void insertDataTest() throws Exception {
		Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://192.168.56.101:/hbase");
		configuration.set("hbase.zookeeper.quorum", "centos");

		HTable hTable = new HTable(configuration, "tablee");
		// set rowkey
		Put put = new Put("rowkey3".getBytes());
		// set column family (列族名,列族标识符,值)
		put.add("familyy".getBytes(), "age".getBytes(), "25".getBytes());
		hTable.put(put);
		hTable.close();
	}

 查询一条记录

@Test
	public void getRecordDataTest() throws Exception {
		Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://192.168.56.101:/hbase");
		configuration.set("hbase.zookeeper.quorum", "centos");

		HTable hTable = new HTable(configuration, "tablee");
		Get get = new Get("rowkey1".getBytes());
		Result result = hTable.get(get);
		System.out.println(result);
		// get column family
		byte[] ageValue = result.getValue("familyy".getBytes(), "age".getBytes());
		System.out.println(new String(ageValue));
		hTable.close();
	}

 查询全表数据

@Test
	public void findAllDataTest() throws Exception {
		Configuration configuration = HBaseConfiguration.create();
		configuration.set("hbase.rootdir", "hdfs://192.168.56.101:/hbase");
		configuration.set("hbase.zookeeper.quorum", "centos");

		HTable hTable = new HTable(configuration, "tablee");
		ResultScanner resultScanner = hTable.getScanner(new Scan());
		for (Result result : resultScanner) {
			byte[] row = result.getRow();
			byte[] ageValue = result.getValue("familyy".getBytes(), "age".getBytes());
			System.out.println(new String(row) + "\t" + new String(ageValue));
		}
		hTable.close();
	}

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Hbase实验报告.pdf

    掌握Hbase shell操作。 1.2实验要求: 用Hbase shell操作创建一个student表,其结构如下表所示 Row Key address score province city street Java Hadoop Math zhangsan guangdong guangzhou yinglonglu 85 80 90 ...

    实验三:熟悉常用的HBase操作

    (2)熟练使用HBase操作常用的 Shell命令。(3)熟悉HBase操作常用的 Java API。 A.3.2 实验平台 (1)操作系统:Linux。 (2)Hadoop 版本:2.7.1或以上版本。(3)HBase版本:1.1.2或以上版本。(4) JDK 版本:1.7或以上...

    Hello HBase

    简介HBase,单机的安装配置,hbase shell和Java api的使用

    【免费下载】HBase分布式数据库实验

    HBase分布式NoSQL数据库实验 1.HBase基础 HBase伪分布式部署 ...创建和使用自动化脚本Shell HBase用户权限管理 4.HBase编程开发 Java API命名空间操作 Java API表操作 编程实现数据操作功能 编程应用过滤器

    大数据技术原理及应用课实验3 熟悉常用的HBase操作 林子雨实验

    在本次实验中,我更加进一步理解了HDFS在Hadoop体系结构中的角色并能使用HDFS操作常用的Shell命令以及HDFS操作常用的Java API。 在本次实验的第一题是用编程Java API实现指定功能,并用Hadoop提供的HBase Shell命令...

    大数据实验三-HBase编程实践

    一.实验内容 HBase编程实践: 1)在Hadoop基础上安装HBase;...3、熟悉HBase操作常用的JavaAPI。 三.实验过程截图及说明 1、安装HBase (1)解压HBase文件到/usr/local目录下,并将目录改名为hbase:

    Apache HBase Primer

    Part V: Apache HBase Java API Chapter 16: The HBaseAdmin Class Chapter 17: Using the Get Class Chapter 18: Using the HTable Class Part VI: Administration Chapter 19: Using the HBase Shell ...

    hbase应用架构指南

    Hbase全称为Hadoop Database,即Hbase是Hadoop的数据库,是一个分布式的存储系统。...本篇文章将重点介绍Hbase三个方面的内容:Hbase体系结构(架构)的介绍、Hbase shell的操作、Hbase的Java api的客户端操作

    HBase Succinctly

    Hbase and the HBase Shell HBase Table Design Connecting with the Java API Connecting with Python and Thrift Connecting with .NET and Stargate The Architecture of HBase Inside the Region Server ...

    Hbase+Spring boot实战分布式文件存储

    3-1 HBase写流程 3-2 HBase读流程 3-3 HBase模块协作 3-4 HBase实战:Shell命令实战 3-5 HBase实 战:Java Api实现HBase连接类 3-6 HBase实战:Java Api实现HBase操作类 3-7 HBase实战:用过滤器筛选数据 3-8 HBase...

    Hbase.xmind

    整理后的Hbase集群搭建,shell命令、高级shell命令,javaAPI入门程序编写,提供详细的Hbase入门手册

    Hadoop+Hive+Spark+Kafka+Zookeeper+Flume+Sqoop+Azkaban+Scala

    Java API 的使用 基于 Zookeeper 搭建 Hadoop 高可用集群 二、Hive 简介及核心概念 Linux 环境下 Hive 的安装部署 CLI 和 Beeline 命令行的基本使用 常用 DDL 操作 分区表和分桶表 视图和索引 常用 DML 操作 数据...

    大数据技术开发环境搭建.docx

    HBase JAVA API编程实践 64 安装MySQL 68 Hive安装 70 Redis安装和使用 74 MongoDB安装和使用 83 Neo4j安装和使用 96 安装Spark 103 使用 Spark Shell 编写代码 104 Scala独立应用编程 106 Java独立应用...

    HBase完整学习笔记

    - HBase介绍 - HBase内部组成 - 安装运行HBase (单击、伪分布、完全分布式) - Shell 命令操作 - HBase 客户端 API - HBase 客户端API:管理功能 - 日期操作

    hadoop使用

    Linux使用;Hadoop安装;HDFS常用操作;HDFS常用操作java api;MapReduce计数操作,排序操作;HBase操作shell命令,HBase操作java api

    Hbase是Apache的NoSQL分布式可扩展Hadoop数据库,可以很好地横向扩展.rar

    易于使用的基于Java的API用于客户端访问。 低延迟访问数十亿条记录中的单行。 快速查找较大的表。 Thrift网关和支持XML,Protobuf和二进制数据编码选项的REST-ful Web服务 可扩展的基于Jruby的(JIRB)Shell 支持...

    实验二:熟悉常用的HDFS操作

    (2)熟练使用HDFS操作常用的 Shell命令。(3)熟悉HDFS操作常用的Java API。 A.2.2 实验平台 (1)操作系统:Linux(建议Ubuntu 16.04)。(2) Hadoop版本:2.7.1。 (3)JDK版本:1.7或以上版本。(4) Java IDE:Eclipse。

    大数据技术与应用——实验报告汇总.zip

    实验一(Hadoop分布式环境搭建) 实验二(shell指令和JavaAPI的HDFS操作) 实验三(shell指令操作HBase) 实验四(JavaApi操作HBase)

    大数据技术原理与应用实验

    实验五 HDFS Shell命令使用 45 实验六 Eclipse开发插件配置 64 实验七 HDFS Java API编程 69 第三章 分布式协调服务系统ZooKeeper 75 实验八 Zookeeper安装部署 75 实验九 Zookeeper Shell命令使用 79 实验十 ...

    实验四:NoSQL和关系数据库的操作比较

    (2)熟练使用4种数据库操作常用的 Shell命令。 (3)熟悉4种数据库操作常用的Java API。 A.4.2实验平台 (1)操作系统:Linux(建议Ubuntu 16.04)。(2)Hadoop版本:2.7.1。 (3)MySQL版本:5.7.15。(4)HBase版本:1.1.2。...

Global site tag (gtag.js) - Google Analytics