hbase shell基础和常用命令详解(转)-ggjucheng-hadoop2-MapReduce详解

hbase提供了一个shell的终端给用户交互。使用命令hbase shell进入命令界面。通过执行 help可以看到命令的帮助信息。

以一个学生在网上的成绩表为例,演示HBase的使用。

[En]

Demonstrate the use of hbase with an example of a student’s score sheet on the Internet.

name grad course math art Tom 5 97 87 Jim 4 89 80

这里的Grad表只有自己的列族,当然对于表是一个有两列的列族,这个列族由数学和艺术两列组成,当然,我们可以根据需要在课程中创建更多的列族,比如计算机、物理等相应的列来加入课程的列族。

[En]

Here grad for the table is only its own column family, course for the table is a column family with two columns, this column family consists of two columns math and art, of course, we can create more column families in course according to our needs, such as computer,physics and other corresponding columns to join the course column family.

(1)建立一个表scores,有两个列族grad和courese

代码如下:

[En]

The code is as follows:

您可以使用LIST命令查看当前HBase中有哪些表。使用Describe命令查看表结构。(请记住,所有指示和列名都需要引号)

[En]

You can use the list command to see which tables are in the current HBase. Use the describe command to view the table structure. (remember that all indications and column names need quotation marks)

(2)按设计的表结构插入值:

代码如下:

[En]

The code is as follows:

这样,表结构就向上了,实际上是比较自由的,可以方便地在列族中自由添加子列。如果柱族下没有子柱,则可以添加冒号或不添加冒号。

[En]

In this way, the table structure is up, in fact, it is relatively free, and it is convenient to add child columns freely in the column family. If there are no subcolumns under the column family, it is OK to add colons or not.

put命令比较简单,只有这一种用法:

t1指表名,r1指行键名,c1指列名,value指单元格值。ts1指时间戳,一般都省略掉了。

(3)根据键值查询数据

你可能会发现,HBase外壳操作的规则是,一个一般的顺序是操作关键字后跟表名、行名、列名这样的顺序,如果有其他条件,再用大括号添加。

[En]

You may find the rule, HBase shell operation, a general order is to operate keywords followed by table name, row name, column name such an order, if there are other conditions and then use curly braces to add.

get有用法如下:

(4)扫描所有数据

还可以指定一些修饰符:TIMERANGE、FILTER、LIMIT、STARTROW、STOPROW、TIMESTAMP、MAXLENGTH或COLUMNS。不带任何修饰符,如上例所示,将显示所有数据行。

[En]

You can also specify some modifiers: TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH,or COLUMNS. Without any modifier, which is the above example, all data rows will be displayed.

例句如下:

[En]

The example sentences are as follows:

代码如下:

[En]

The code is as follows:

过滤器筛选器有两种方式来指示:

[En]

The filter filter has two ways to indicate:

a. Using a filterString – more information on this is available in the

Filter Language document attached to the HBASE-4176 JIRA

b. Using the entire package name of the filter.

还有一个CACHE_BLOCKS修饰词,开关scan的缓存的,默认是开启的(CACHE_BLOCKS=>true),可以选择关闭(CACHE_BLOCKS=>false)。

(5)删除指定数据

代码如下:

[En]

The code is as follows:

DELETE DATA命令也没有太大变化,只有一个例外:

[En]

The delete data command hasn’t changed much either, except for one:

另外,还有一个删除全部的命令,可以删除整行的作用域,请谨慎使用!

[En]

In addition, there is a deleteall command, you can delete the scope of the entire line, use with caution!

如果需要删除整个表,请使用TRUNCATE命令。事实上,没有直接的FULL TABLE DELETE命令,它也是三个DISABLE、DROP、CREATE命令的组合。

[En]

If you need to delete a full table, use the truncate command. In fact, there is no direct full table delete command, which is also a combination of three disable,drop,create commands.

(6)修改表结构

代码如下:

[En]

The code is as follows:

alter命令使用如下(如果无法成功的版本,需要先通用表disable):

a、改变或添加一个列族:

b、删除一个列族:

代码如下:

[En]

The code is as follows:

c、也可以修改表属性如MAX_FILESIZE

d、可以添加一个表协同处理器

一张桌子上可以配置多个协处理器,序列将自动增长以进行识别。加载协处理器(或过滤器)需要以下规则:

[En]

Multiple co-processors can be configured on a table, and a sequence will automatically grow for identification. Loading a co-processor (or a filter) requires the following rules:

e、移除coprocessor如下:

f、可以一次执行多个alter命令:

(7)统计行数:

代码如下:

[En]

The code is as follows:

count一般会比较耗时,使用mapreduce进行统计,统计结果会缓存,默认是10行。统计间隔默认的是1000行(INTERVAL)。

(8)disable 和 enable 操作

很多操作需要先暂停表的可用性,比如上边说的alter操作,删除表也需要这个操作。disable_all和enable_all能够操作更多的表。

(9)表的删除

停止该表的可用性,然后执行删除命令。

[En]

Stop the availability of the table, and then execute the delete command.

以上是一些常用命令的详细讲解,所有具体的HBase外壳命令如下,分为几个命令组,大家可以看到英语的一般用法,使用帮助“cmd”来了解详细用法。

[En]

The above is a detailed explanation of some commonly used commands, all the specific hbase shell commands are as follows, divided into several command groups, you can see the general use of English, detailed usage using help “cmd” to understand.

代码如下:

[En]

The code is as follows:

Original: https://www.cnblogs.com/ggjucheng/p/3379607.html
Author: Hongten
Title: hbase shell基础和常用命令详解(转)-ggjucheng-hadoop2-MapReduce详解

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6759/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

发表回复

登录后才能评论
免费咨询
免费咨询
扫码关注
扫码关注
联系站长

站长Johngo!

大数据和算法重度研究者!

持续产出大数据、算法、LeetCode干货,以及业界好资源!

2022012703491714

微信来撩,免费咨询:xiaozhu_tec

分享本页
返回顶部