01 | HBase入门与进阶

数据存储

RDBMS:

  • Data is typed structured before stored
  • Entity ==> table
  • Record ==> row
  • Query: group by / join
  • 无法存储大数据
  • 无法进行大数据的实时查询

Hadoop/HDFS:

  • 能存

  • 无法进行实时查询

  • 随机读写能力欠缺

NoSQL:

  • HBase/Redis实时查询

什么是HBase

Apache HBase is the Hadoop database, a distributed, scalable, big data store.

Use Apache HBase when you need random, realtime read/write access to your Big Data. This project's goal is the hosting of very large tables -- billions of rows X millions of columns -- atop clusters of commodity hardware. Apache HBase is an open-source, distributed, versioned, non-relational database modeled after Google's Bigtable: A Distributed Storage System for Structured Data by Chang et al. Just as Bigtable leverages the distributed data storage provided by the Google File System, Apache HBase provides Bigtable-like capabilities on top of Hadoop and HDFS.

  • 随机、实时大数据读写

  • 几十亿行、上百亿列运行在普通机器上

  • 开源、分布式、多版本、非关系型数据库、来源自Google的Bigtable

  • 数据可存储至hdfs中(为数据存储提供可靠的保障)

  • 面向列存储(具备列存储的优点)

HBase在Hadoop生态圈里的位置

image-20200406153122892

  • HBase是hadoop生态圈中的重要组成部分
  • hbase构建在hdfs上:hbase可以的数据可以存在hdfs上面
  • 可以通过mr spark处理hbase中的数据,
  • 提供shell api的方式进行数据访问

HBase列式存储

行式存储与列式存储

  • 按行存储
  • 没有索引查询的时候,消耗大量io
  • 可以通过建立索引或者视图的方式提速

列式存储

  • 相同数据结构,方便压缩
  • 并行处理
  • 数据就是索引
  • 大大降低io

HBase特点

  1. 面向列:列族的概念(可以存放多个相关的列),列族/列独立索引

  2. 稀疏:对于空的列不会占据存储空间

  3. 数据类型单一:byte/string

  4. 无模式:每一行的数据所对应的列不一定相同,每行列是可以动态添加的

  5. 数据多版本:比如company是可以存放不同版本的值

    默认情况下版本号是自动分配的,是列插入时的时间戳

HBase VS MySQL

  1. 数据类型的差异

  2. 数据操作

    HBase无法进行关联操作,可通过MR/Spark/Phoenix

    HBase操作:Get/put/scan

  3. 存储模式(行式存储/列式存储)

user

id name age tel address

1 x

2 y

3 z

... ...

base_info:id name

private_info :age tel address

  1. Transaction:关系型数据库多行事务,HBase是单行事务

  2. 数据量

  3. 读写的吞吐量

HBase VS HDFS

  1. write parttern

  2. read parttern

  3. SQL:HBase无sql,HDFS有sql(hive)

  4. 数据量无本质区别

HBase的数据模型

image-20200407122809172

数据模型:

  • rowkey

    • 主键
    • 字符串(按字典顺序存储),在HBase内部保存字节数组
  • 列族:column family cf

    • 在创建表时就要指定

    • 列族是一系列列的集合

    • 一个列族所有列有着相同的前缀:

      Private_info: age

      Private_info: tel

      Private_info: address

      Basic_info: id

      Basic_info: name

  • 列:column

    • 属于某个列族

    • 每个记录被划分至若干个cf中,每个记录对应一个rowkey,每个cf由一个或多个列构成

  • 存储单元:cell/timestamp

    • HBase的row和column确定一个存储单元

    • 每个cell保存一份数据的多个版本

    • 在写入数据时时间戳可由HBase自动赋值,也可以显式赋值

    • 每个cell中,不同版本的数据按照时间戳的倒序排列

    {rowkey,column,version}==>HBase中的一个cell

HBase操作

shell操作

DDL 操作

DML操作

posted @ 2020-04-13 10:47  mhp  阅读(91)  评论(0)    收藏  举报