• 从零自学Hadoop(21):HBase数据模型相关操作下


    阅读目录

    本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。

    文章是哥(mephisto)写的,SourceLink

         上一篇,我们讲述了HBase的数据模型相关操作的上部分。

       下面我们开始介绍HBase的数据模型相关操作的下部分。

    变量

    一:定义变量

      这样我们就可以使用t这个变量来代替table1了。

    t=get_table 'table1'

      

    二:使用

    t.put 'row1','cf1:a','v1'
    t.get 'row1'
    t.scan 

    三:描述,名称

      可以查看表的描述,和变量所代替的表名

    t.describe
    t.name

    数据模型操作

    一:介绍

      有读get 写 put 扫描 scan 删除 delete 这几种数据模型操作。

    二:put

      我们先写入几条数据。

    put 'table1','row1','cf1:a','a1'
    put 'table1','row1','cf3:a','aa1'

      设置rowkey为row1的列族cf1中列为a的值为a1,列族cf3中列为a的值为aa1

    三:get

      获取表table1中rowkey为row1的数据

    get 'table1','row1'

      从图中我可以看到列族cf1的a列,和cf3的a列的数据。

    四:更新

    put 'table1','row1','cf3:a','aa2'

      从图中我们可以看到列族cf3的列a的值变了,而且时间戳也变了。不管value的值变成什么,或者是自己本身,没执行一次put命令,对应的列族的时间戳都会改变。

    五:scan

      构造数据

     put 'table1','row2','cf1:b','b1'
     put 'table1','row3','cf3:b','bb1'

      扫描

    scan 'table1'

      我们可以看到该表的每条,每列数据都会列出来。

      扫描列族cf1的数据

    scan 'table1' ,{COLUMN=>'cf1'}

      扫描第一行的数据

    scan 'table1' ,{LIMIT=>1}

      扫描起始行为row2的前2条数据

    scan 'table1' ,{LIMIT=>2,STARTROW=>'row2'}

      扫描时间戳在一定范围内的数据

    scan 'table1' ,{TIMERANGE=>[1474459901241,1474460092018]}
    scan 'table1' ,{TIMERANGE=>[1474459901241,1474460092019]}

      这里比较奇葩,起始的时间41可以查出41的数据,截至时间18查不出18的数据,19才能查出18的数据。所以这点我们应该留点心。

      倒序扫描数据

    scan 'table1' ,{REVERSED => true}

      数据按照rowkey,列族,列族中的列倒序排列
      使用row过滤器扫描row1的数据

    scan 'table1' ,{ROWPREFIXFILTER => 'row1'}

    六:delete

      删除rowkey 为row1,列族cf1中列为a的数据

    delete 'table1','row1','cf1:a'

      我们可以试试这个语句

     delete 'table1','row1','cf1'

      发现没有数据被删除,所以删除语句是针对列的,而不是针对列族的。

    deleteall

      删除一行

    deleteall 'table1','row1'

     --------------------------------------------------------------------

      到此,本章节的内容讲述完毕。

    系列索引

      【源】从零自学Hadoop系列索引

     

    本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出原文链接,谢谢合作。

    文章是哥(mephisto)写的,SourceLink

  • 相关阅读:
    【LeetCode】006 ZigZag Conversion
    【LeetCode】009 Palindrome Number
    【LeetCode】008 String to Integer (atoi)
    【LeetCode】012 013 Roman Integer
    react-native 入门资源合集
    Thread和ExecutorService(一)
    DrawerLayout、CoordinatorLayout、CollapsingToolbarLayout的使用--AndroidSupportDesign练手
    Valid Number
    When Is Cheryl's Birthday
    【笔试】——常用运算符
  • 原文地址:https://www.cnblogs.com/mephisto/p/5917574.html
Copyright © 2020-2023  润新知