HBase ——Shell操作

Q:你觉得HBase是什么?

A:一种结构化的分布式数据存储系统,它基于列来存储数据。

基于HBase,可以实现以廉价PC机器集群存储海量数据的分布式数据库的解决方案。

一般用于数据量巨大但查询简单的场景,典型场景包括:账单记录,订单流水,交易记录,数据库的历史记录

  • 建立表

    HBase中没有数据库的概念,但是存在命名空间的概念,在使用上类似库名,但实际上只是一个目录名。

    另外要记住,HBase中大部分数据都是以HashMap的形式组织的,因此很多时候都能看到类似 key : value的格式。命名空间表的定义也是如此。

    任何表的定义必须有表名和列族,可以没有命名空间

    create 'ns1:tb1','cf1' #有命名空间的表,ns1是命名空间,cf1是列族
    create 'tb1','cf1'
    list #查看已有表
  • 删除表

    删除表之前必须了解,HBase作为分布式数据库是没有锁的,更不支持事务。因此,HBase的删除表之前必须先禁用表。

    disable 'tb1'
    drop 'tb1'
  • 插入数据

    在定义表的时候我们已经指定了列族,但是光有列族是不足以确定唯一数据的。插入数据时还必须指定行键和列键。

    插入数据,包括创建表都有多种属性可选,在此只介绍最基本的。hbase shell输入命令不加参数即可获得帮助指南。

    put 'tb1','rk1','cf1:c1','value' #rk1是行键,c1是属于cf1族的列健
  • 查找数据

    在上面已经提到了HBase适用于简单的查询业务场景,但是这种简单是相对于SQL的关联查找而言的。HBase在单表查询是足够强大的。

    HBase中记录分为三部分,ROW、COLUMN和CELL,COLUMN分为family列族和qualifier列键,CELL分为TimeStamp和Value。可以看出,一个唯一的value是由rowkey、family、qualifier、timestamp共同决定的。查找数据也是遵循的也是这个逻辑。

    get 'tb1','rk1'[,'cf1[:c1]'] #简单查找
    get 'tb1','rk1',{COLUMN=>['C1','C2','C3'],TIMESTAMP=>ts1} #多条件
  • 扫描数据

    get每次只能查找一个行键,而scan扫描是条件查找整张表

    scan 'tb1',{condition} #condition可以是列族/键、时间、版本、范围,具体见帮助
  • 删除数据

    hbase是列模式存储的,因此每次删除只能删除指定列键的row的value

    delete 'tb1','rk1','cf1[:c1]' #删除的是一条记录
  • 表操作

    Here is some help for this command:
    Alter a table. If the "hbase.online.schema.update.enable" property is set to
    false, then the table must be disabled (see help 'disable'). If the
    "hbase.online.schema.update.enable" property is set to true, tables can be
    altered without disabling them first. Altering enabled tables has caused problems
    in the past, so use caution and test it before using in production. You can use the alter command to add,
    modify or delete column families or change table configuration options.
    Column families work in a similar way as the 'create' command. The column family
    specification can either be a name string, or a dictionary with the NAME attribute.
    Dictionaries are described in the output of the 'help' command, with no arguments. For example, to change or add the 'f1' column family in table 't1' from
    current value to keep a maximum of 5 cell VERSIONS, do: hbase> alter 't1', NAME => 'f1', VERSIONS => 5 You can operate on several column families: hbase> alter 't1', 'f1', {NAME => 'f2', IN_MEMORY => true}, {NAME => 'f3', VERSIONS => 5} To delete the 'f1' column family in table 'ns1:t1', use one of: hbase> alter 'ns1:t1', NAME => 'f1', METHOD => 'delete'
    hbase> alter 'ns1:t1', 'delete' => 'f1' You can also change table-scope attributes like MAX_FILESIZE, READONLY,
    MEMSTORE_FLUSHSIZE, DURABILITY, etc. These can be put at the end;
    for example, to change the max size of a region to 128MB, do: hbase> alter 't1', MAX_FILESIZE => '134217728' You can add a table coprocessor by setting a table coprocessor attribute: hbase> alter 't1',
    'coprocessor'=>'hdfs:///foo.jar|com.foo.FooRegionObserver|1001|arg1=1,arg2=2' Since you can have multiple coprocessors configured for a table, a
    sequence number will be automatically appended to the attribute name
    to uniquely identify it. The coprocessor attribute must match the pattern below in order for
    the framework to understand how to load the coprocessor classes: [coprocessor jar file location] | class name | [priority] | [arguments] You can also set configuration settings specific to this table or column family: hbase> alter 't1', CONFIGURATION => {'hbase.hregion.scan.loadColumnFamiliesOnDemand' => 'true'}
    hbase> alter 't1', {NAME => 'f2', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}} You can also remove a table-scope attribute: hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'MAX_FILESIZE' hbase> alter 't1', METHOD => 'table_att_unset', NAME => 'coprocessor$1' You can also set REGION_REPLICATION: hbase> alter 't1', {REGION_REPLICATION => 2} There could be more than one alteration in one command: hbase> alter 't1', { NAME => 'f1', VERSIONS => 3 },
    { MAX_FILESIZE => '134217728' }, { METHOD => 'delete', NAME => 'f2' },
    OWNER => 'johndoe', METADATA => { 'mykey' => 'myvalue' }

数据导入导出

hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \

-Dimporttsv.separator=, \

-Dimporttsv.columns="HBASE_ROW_KEY,order:numb,order:date" \

customer file:///home/vagrant/hbase_import_data.csv

s注:customer是要导入数据的表名,order.numb为列键

注2:这是sh命令,运行时如出现hdfs端无jar包文件异常,将本地hbase上lib目录拷贝到hdfs

HBase ——Shell操作的更多相关文章

  1. 大数据技术之_11_HBase学习_01_HBase 简介+HBase 安装+HBase Shell 操作+HBase 数据结构+HBase 原理

    第1章 HBase 简介1.1 什么是 HBase1.2 HBase 特点1.3 HBase 架构1.3 HBase 中的角色1.3.1 HMaster1.3.2 RegionServer1.3.3 ...

  2. HBase Shell操作

    Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统.     Hbase不同于一般的关系型数据库(RDBMS ...

  3. 云计算与大数据实验:Hbase shell操作用户表

    [实验目的] 1)了解hbase服务 2)学会hbase shell命令操作用户表 [实验原理] HBase是一个分布式的.面向列的开源数据库,它利用Hadoop HDFS作为其文件存储系统,利用Ha ...

  4. 云计算与大数据实验:Hbase shell操作成绩表

    [实验目的] 1)了解hbase服务 2)学会hbase shell命令操作成绩表 [实验原理] HBase是一个分布式的.面向列的开源数据库,它利用Hadoop HDFS作为其文件存储系统,利用Ha ...

  5. HBase基础之常用过滤器hbase shell操作(转)

    创建表 create 'test1', 'lf', 'sf' lf: column family of LONG values (binary value)-- sf: column family o ...

  6. HBase基础之常用过滤器hbase shell操作

    创建表 create 'test1', 'lf', 'sf' lf: column family of LONG values (binary value) -- sf: column family ...

  7. Hbase shell 操作记录

    查看hbase版本 hbase(main):002:0> version 2.1.0-cdh6.2.0, rUnknown, Wed Mar 13 23:39:58 PDT 2019 Took ...

  8. Hbase Shell命令详解+API操作

    HBase Shell 操作 3.1 基本操作1.进入 HBase 客户端命令行,在hbase-2.1.3目录下 bin/hbase shell 2.查看帮助命令 hbase(main):001:0& ...

  9. Hbase框架原理及相关的知识点理解、Hbase访问MapReduce、Hbase访问Java API、Hbase shell及Hbase性能优化总结

    转自:http://blog.csdn.net/zhongwen7710/article/details/39577431 本blog的内容包含: 第一部分:Hbase框架原理理解 第二部分:Hbas ...

随机推荐

  1. CAS客户端和服务器配置https证书

    关于如何生成https证书可以看这篇文章: java生成Https证书,及证书导入的步骤和过程 下面整理cas如何整合https: cas服务器端部署(TLS[https]) 1.生成证书: 参照ja ...

  2. Pycharm怎么安装?

    摘要:工欲善其事必先利其器,每个人都有自己心中理想的集成开发环境,这里我们不做讨论,今天只介绍Pycharm怎么安装. 首先打开官网:https://www.jetbrains.com/pycharm ...

  3. P4254 [JSOI2008]Blue Mary开公司 (李超树)

    题意:插入一些一次函数线段 每次询问在x = x0处这些线段的最大值 题解:李超树模版题 维护优势线段 注意这题的输入是x=1时的b #include <iostream> #includ ...

  4. Codeforces Round #697 (Div. 3) D. Cleaning the Phone (思维,前缀和)

    题意:你的手机有\(n\)个app,每个app的大小为\(a_i\),现在你的手机空间快满了,你需要删掉总共至少\(m\)体积的app,每个app在你心中的珍惜值是\(b_i\),\(b_i\)的取值 ...

  5. hdu 1045 Fire Net 二分图匹配 && HDU-1281-棋盘游戏

    题意:任意两个个'车'不能出现在同一行或同一列,当然如果他们中间有墙的话那就没有什么事,问最多能放多少个'车' 代码+注释: 1 //二分图最大匹配问题 2 //难点在建图方面,如果这个图里面一道墙也 ...

  6. PowerShell随笔3 ---别名

    上一篇提到了别名,这个有必要说一下,因为我们常常会遇到以下两种情况: 自己写脚本,想快速一些,使用命名 看别人的脚本,发现别人和你想的一样,用了别名,但是你忘记了这个别名是什么意思. 我们可以通过Ge ...

  7. 一张图解决ThreadLocal

    一张图解决ThreadLocal 一.前言 年底梳理知识体系时,研究了一下ThreadLocal的源码,整理了一张核心图. 想着,都走到这一步了,那就写一篇深度解读的文章吧.看过我之前文章的小伙伴都知 ...

  8. python 迭代器 iter多次消费

    问题 Python 中的迭代器是我们经常使用的迭代工具, 但其只能消费一次,再次消费便会出现 StopIteration 报错. 解决方案 封装了一个类,当迭代器使用完后再次初始化. 代码 class ...

  9. zoj-3870 (二进制)

    For an upcoming programming contest, Edward, the headmaster of Marjar University, is forming a two-m ...

  10. PyQt5笔记

    PyQt5 窗口类继承QMainWindow. 1.消息盒子QMessageBox 弹出一个窗口,根据选择的不同执行不同的操作.比如点击关闭后,实用消息盒子确认是否关闭. # 关闭QWidget将产生 ...