暗能星系

    • 登录
    • 搜索

    Hbase基本使用

    大数据
    1
    2
    8
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • A
      anneng 最后由 编辑

      默认管理后台
      http://localhost:16010/

      连接
      $ ./bin/hbase shell
      hbase(main):001:0>
      

      创建表

      hbase(main):001:0> create 'test', 'cf'
      0 row(s) in 0.4170 seconds
      
      => Hbase::Table - test
      

      查看表

      hbase(main):002:0> list 'test'
      TABLE
      test
      1 row(s) in 0.0180 seconds
      
      => ["test"]
      
      hbase(main):003:0> describe 'test'
      Table test is ENABLED
      test
      COLUMN FAMILIES DESCRIPTION
      {NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>
      'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f
      alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE
       => '65536'}
      1 row(s)
      Took 0.9998 seconds
      

      添加值

      hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
      0 row(s) in 0.0850 seconds
      
      hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
      0 row(s) in 0.0110 seconds
      
      hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
      0 row(s) in 0.0100 seconds
      

      浏览所有数据

      hbase(main):006:0> scan 'test'
      ROW                                      COLUMN+CELL
       row1                                    column=cf:a, timestamp=1421762485768, value=value1
       row2                                    column=cf:b, timestamp=1421762491785, value=value2
       row3                                    column=cf:c, timestamp=1421762496210, value=value3
      3 row(s) in 0.0230 seconds
      

      获取单行数据

      hbase(main):007:0> get 'test', 'row1'
      COLUMN                                   CELL
       cf:a                                    timestamp=1421762485768, value=value1
      1 row(s) in 0.0350 seconds
      

      使能和禁用表

      hbase(main):008:0> disable 'test'
      0 row(s) in 1.1820 seconds
      
      hbase(main):009:0> enable 'test'
      0 row(s) in 0.1770 seconds
      

      删除表

      hbase(main):011:0> drop 'test'
      0 row(s) in 0.1370 seconds
      

      退出shell
      quit

      停止

      $ ./bin/stop-hbase.sh
      stopping hbase....................
      $
      
      1 条回复 最后回复 回复 引用 0
      • A
        anneng 最后由 编辑

        You may have to modify properties of the existing table to add more column families or to modify the table attributes. HBase has ‘alter’ command’. In this article, we will check alter HBase table using shell command with some common examples to alter HBase table.

        Alter HBase Table using shell command

        Alter HBase Table using shell command
        This command alters the column family schema. You can use the HBase Alter shell command used to make changes to an existing table. Using this command, you can change the table properties or attributes such as set version, set and delete table scope operators, and delete a column family from an existing table.

        HBase Alter Table Syntax
        Below is the HBase alter table syntax:

        alter <tablename>, NAME=>’<column familyname>’, VERSIONS=><new version no>
        You can add or remove column from the HBase table. You can also modify the table properties.

        HBase Alter Table Examples
        Below are some of the common examples of HBase alter table command.

        HBase Alter Table add column family
        Let’s say you have created the table with column family name colFam1 and want to add one more column family. Below is the example:

        hbase(main):005:0> alter 'test_table', {NAME=> 'colFam2'}
        Updating all regions with the new schema...
        1/1 regions updated.
        Done.
        

        0 row(s) in 2.5210 seconds
        HBase Alter Table drop column family
        Below is the example to drop column family from HBase table:

        hbase(main):011:0> alter 'test_table', {NAME => 'colFam2', METHOD => 'delete'}
        Updating all regions with the new schema...
        1/1 regions updated.
        Done.
        

        0 row(s) in 2.7310 seconds
        You can use the other method to delete column from HBase table

        hbase(main):013:0> alter 'test_table', 'delete'=> 'colFam2'
        Updating all regions with the new schema...
        1/1 regions updated.
        Done.
        

        0 row(s) in 2.4470 seconds
        Alter HBase Table to add versions
        Below is the example to add versions to existing table:

        hbase(main):015:0> alter 'test_table', {NAME=> 'colFam1',VERSIONS => 2}
        Updating all regions with the new schema...
        0/1 regions updated.
        1/1 regions updated.
        Done.
        

        0 row(s) in 3.2200 seconds
        Alter HBase Table to add Time TO Live (TTL)
        Below is the example to add Time TO Live (TTL) to existing table:

        hbase(main):016:0> alter 'test_table', {NAME=> 'colFam1',TTL => 2000 }
        Updating all regions with the new schema...
        1/1 regions updated.
        Done.
        

        0 row(s) in 2.2140 seconds
        Alter HBase Table to enable snappy Compression
        Below is the example to enable snappy compression on the existing HBase column family:

        hbase(main):017:0> alter 'test_table', {NAME=> 'colFam1',COMPRESSION=>'snappy'}
        Updating all regions with the new schema...
        1/1 regions updated.
        Done.
        
        1 条回复 最后回复 回复 引用 0
        • First post
          Last post
        Powered by 暗能星系