In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you what are the common operations of HBase Shell, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
HBase Shell is a command line tool of HBase through which we can maintain HBase. We can use sudo-u hbase hbase shell to enter the HBase shell.
In HBase shell, you can use status, version, and whoami to get the status, version, login user, and authentication method of the current service, respectively.
> status3 servers, 1 dead, 1.3333 average load > version0.98.6-cdh6.3.1, rUnknown, Tue Jan 27 16:43:50 PST 2015 > whoamihbase (auth:SIMPLE) groups: hbase
The help commands in HBase shell are very powerful, using help to get a list of all commands and help 'command_name' to get details of a command. For example:
> help 'list'List all tables in hbase. Optional regular expression parameter couldbe used to filter the output. Examples: hbase > list hbase > list' abc.*' hbase > list' ns:abc.*' hbase > list' ns:.*'1. Namespace
In the HBase system, the namespace namespace refers to a logical grouping of HBase tables. Tables in the same namespace have similar uses and are also used for security control of settings such as quotas and permissions.
HBase defines two predefined namespaces built into the system by default:
Hbase: system namespace for internal tables that contain hbase
Default: all tables that do not specify a namespace automatically enter that namespace
We can create namespaces through the create_namespace command
> create_namespace 'debugo_ns'0 row (s) in 2.0910 seconds
Delete namespaces through drop_namespace
> drop_namespace 'debugo_ns'0 row (s) in 1.9540 seconds
Change the properties of the table through alter_namespac in the following format:
Alter_namespace 'my_ns', {METHOD = >' set', 'PROPERTY_NAME' = >' PROPERTY_VALUE'}
Displays the namespace and the meta-information set:
> describe_namespace 'debugo_ns'DESCRIPTION {NAME = >' debugo_ns'} 1 row (s) in 1.9540 seconds
Show all namespaces
> list_namespaceNAMESPACE debugo_ns default hbase 3 row (s) in 0.0910 seconds
To create a table under HBase, you need to use create table_name, column_family1, this command:
> create 'user','info'0 row (s) in 0.9030 seconds= > Hbase::Table-user
At this time the table is created under default. If you need to create a table under the namespace debugo_ns, you need to use create namespace:table_name:
> create_namespace 'debugo_ns'0 row (s) in 2.0910 secondscreate' debugo_ns:users', 'info'0 row (s) in 0.4640 seconds= > Hbase::Table-debugo_ns:users
The List command lists all the tables in the current HBase instance and supports matching using regular expressions.
> list_namespace_tables' debugo_ns'TABLE users 1 row (s) in 0.0400 seconds
Using list_namespace_tables, you can also directly output all tables under a namespace
> list_namespace_tables' debugo_ns'TABLE users 1 row (s) in 0.0400 seconds2. DDL statement
The first is to create the HBase table, which we have already used the create command. The first parameter after it is the table name, followed by a list of column clusters. Each column cluster can independently specify the number of versions it uses, the effective storage time of the data (TTL), whether to turn on block caching and other information.
> create't 1, {NAME = > F1, VERSIONS = > 1, TTL = > 2592000, BLOCKCACHE = > true}, 'f2'
A table can also specify the number of region and the split method for its pre-split (pre-splitting) at creation time. When the table is initially created, HBase is assigned only one region to the table. This means that when we access the table data, we only access a region server, so we cannot make full use of the cluster resources. HBase provides a tool to manage the number of region in the table, that is, the configuration item for split in org.apache.hadoop.hbase.util.RegionSplitter and create in HBase shell. For example:
> create 't2percent,'F1 percent, {NUMREGIONS = > 3, SPLITALGO = > 'HexStringSplit'}
We use describe to view the meta-information in this table:
> describe 't2'DESCRIPTION ENABLED' T2, {NAME = >'F1', DATA_BLOCK_ENCODING = > 'NONE', BLOOMFILTER = >' ROW', REPLIC true ATION_SCOPE = > '013, VERSIONS = >' 1', COMPRESSION = > 'NONE', MIN_VERSIONS = >' 013, TTL = > 'FOREVER', KEEP_DELETED_CELLS = >' false', BLOCKSIZE = > '65536', IN_MEMOR Y = > 'false' BLOCKCACHE = > 'true'} 1 row (s) in 0.0690 seconds
Enable / disable this table through enable and disable, and accordingly check whether the table is disabled through is_enabled and is_disabled.
> disable 't2mm 0 row (s) in 1.4410 seconds > enable 't2pm 0 row (s) in 0.5940 seconds > is_enabled 't2'true0 row (s) in 0.0400 secondshbase (main): 042 secondshbase 0 > is_disabled 't2'false0 row (s) in 0.0490 seconds
Use exists to check if the table exists
> exists' t2'Table T2 does exist0 row (s) in 0.0590 seconds
Use alter to change the properties of a table, such as a column cluster, which involves updating information to all region. In previous versions, alter operations required to disable table first, but it was no longer needed in the current version.
> alter's in, {NAME = >'F1', VERSIONS = > 5} Updating all regions with the new schema...0/1 regions updated.1/1 regions updated.Done.0 row (s) in 2.3470 seconds
Another very common operation is to add and remove column clusters:
> alter 't1recording alter 'f3' Updated all regions with the new schema...0/1 regions updated.1/1 regions updated.Done.0 row (s) in 2.3130 seconds > alter 't1' recording' delete' = > f3'
Or:
> alter't 1mm, {NAME = > 'f3mm, METHOD = >' delete'} Updating all regions with the new schema...0/1 regions updated.1/1 regions updated.Done.0 row (s) in 2.2930 seconds
To delete a table, you need to disable the table.
> disable 't1room0 row (s) in 1.4310 seconds > drop 't1hou0 row (s) in 0.2440 seconds3. Put and get
In HBase shell, we can insert data through the put command. For example, we create a new table with three column clusters: id, address, and info, and insert some data. The columns under the column cluster do not need to be created in advance, but are passed when needed.
:
You can specify it.
> create 'member','id','address','info'0 row (s) in 0.4570 seconds= > Hbase::Table-memberput' member',' debugo','id','11'put 'member',' debugo','info:age','27'put' member',' debugo','info:birthday','1987-04-04'put 'member',' debugo','info:industry',' it'put 'member',' debugo','address:city' 'beijing'put 'member',' debugo','address:country','china'put 'member',' Sariel',' id', '21'put' member', 'Sariel','info:age',' 26'put 'member',' Sariel','info:birthday', '1988-05-09' put 'member',' Sariel','info:industry', 'it'put' member', 'Sariel','address:city',' beijing'put 'member' 'Sariel','address:country', 'china'put' member', 'Elvis',' id',' 22'put 'member',' Elvis','info:age', '26'put' member', 'Elvis','info:birthday',' 1988-09-14 'put' member', 'Elvis','info:industry',' it'put 'member',' Elvis','address:city', 'beijing'put' member', 'Elvis' 'address:country', 'china'
Get all the data of an id
> get 'member',' Sariel'COLUMN CELL address:city timestamp=1425871035382, value=beijing address:country timestamp=1425871035424 Value=china id: timestamp=1425871035176, value=21 info:age timestamp=1425871035225 Value=26 info:birthday timestamp=1425871035296, value=1988-05-09 info:industry timestamp=1425871035334, value=it 6 row (s) in 0.0530 seconds
Get all the data in an id, a column cluster (one column):
> get 'member',' Sariel', 'info'COLUMN CELL info:age timestamp=1425871035225 Value=26 info:birthday timestamp=1425871035296, value=1988-05-09 info:industry timestamp=1425871035334 Value=it 3 row (s) in 0.0320 seconds > get 'member',' Sariel', 'info:age'COLUMN CELL info:age timestamp=1425871035225 Value=26 1 row (s) in 0.0270 seconds
As you can see from describe 'member', column clusters save only one version by default. Let's modify it to 2, and then update some information.
> alter 'member', {NAME= >' info', VERSIONS = > 2} Updating all regions with the new schema...0/1 regions updated.1/1 regions updated.Done.0 row (s) in 2.2580 seconds > put 'member',' debugo','info:age','29' > put 'member',' debugo','info:age','28' > get 'member',' debugo', {COLUMN= > 'info:age' VERSIONS= > 2} COLUMN CELL info:age timestamp=1425884510241, value=28 info:age timestamp=1425884510195 Value=29 2 row (s) in 0.0400 seconds4. Other DML statements
With the delete command, we can delete the 'info:age' field whose id is a value, and the following get ignores it
> delete 'member','debugo','info:age'0 row (s) in 0.0420 seconds > get 'member','debugo','info:age'COLUMN CELL0 row (s) in 0.3270 seconds
Delete the entire row through deleteall
> delete 'member','debugo','info:age'0 row (s) in 0.0420 seconds > get 'member','debugo','info:age'COLUMN CELL0 row (s) in 0.3270 seconds
Add to the 'Sariel'' info:age' field and increment it using incr. It is important to note, however, that this value needs to be a numeric value, and incr cannot be used if a string identified by single quotation marks. When using Java API development, we can use the toBytes function to convert values into byte bytes. In HBase shell, we can only initialize this column through incr
> delete 'member','Sariel','info:age'0 row (s) in 0.0270 seconds > incr 'member','Sariel','info:age',260 row (s) in 0.0290 seconds > incr 'member','Sariel','info:age'0 row (s) in 0.0290 seconds > incr' member','Sariel','info:age',-10 row (s) in 0.0230 seconds > get 'member','Sariel' 'info:age'COLUMN CELL info:age timestamp=1425890213341, value=\ x00\ x1A 1 row (s) in 0.0280 seconds
Hexadecimal 1A is 26, the result obtained by adding 1 and minus 1 above. Let's count the number of rows through count.
> count 'member'2 row (s) in 0.0750 seconds= > 2
Truncate the table through truncate. Hbase is to drop disable first, and then drop to rebuild the table to achieve the function of truncate.
Hbase (main): 010 member'Truncating 0 > truncate 'member'Truncating' member' table (it may take a while):-Disabling table... -Dropping table... -Creating table...0 row (s) in 2.3260 seconds5. Scan and filter
Scan the whole table through scan. We recovered the data from the previous put.
> scan 'member'ROW COLUMN+CELL Elvis column=address:city, timestamp=1425891057211, value= beijing Elvis column=address:country, timestamp=1425891057258 Value= china Elvis column=id:, timestamp=1425891057038, value=22 Elvis column=info:age, timestamp=1425891057083, value=26 Elvis column=info:birthday, timestamp=1425891057129, value= 1988-09-14 Elvis column=info:industry, timestamp=1425891057172 Value= it Sariel column=address:city, timestamp=1425891056965, value= beijing Sariel column=address:country, timestamp=1425891057003 Value= china Sariel column=id:, timestamp=1425891056767, value=21 Sariel column=info:age, timestamp=1425891056808, value=26 Sariel column=info:birthday, timestamp=1425891056883, value= 1988-05-09 Sariel column=info:industry, timestamp=1425891056924 Value= it debugo column=address:city, timestamp=1425891056642, value= beijing debugo column=address:country, timestamp=1425891056726 Value= china debugo column=id:, timestamp=1425891056419, value=11 debugo column=info:age, timestamp=1425891056499, value=27 debugo column=info:birthday, timestamp=1425891056547, value= 1987-04-04 debugo column=info:industry, timestamp=1425891056597 Value = it 3 row (s) in 0.0660 seconds3 row (s) in 0.0590 seconds
Specify to scan one of the columns:
> scan 'member', {COLUMNS= >' info:birthday'}
Or the entire column cluster:
> scan 'member', {COLUMNS= >' info'} ROW COLUMN+CELL Elvis column=info:age, timestamp=1425891057083, value=26 Elvis column=info:birthday, timestamp=1425891057129 Value=1988-09-14 Elvis column=info:industry, timestamp=1425891057172, value=it Sariel column=info:age, timestamp=1425891056808, value=26 Sariel column=info:birthday, timestamp=1425891056883 Value=1988-05-09 Sariel column=info:industry, timestamp=1425891056924, value=it debugo column=info:age, timestamp=1425891056499, value=27 debugo column=info:birthday, timestamp=1425891056547 Value=1987-04-04 debugo column=info:industry, timestamp=1425891056597, value=it 3 row (s) in 0.0650 seconds
In addition to the COLUMNS modifier, HBase also supports Limit (limit the number of rows of query results) and STARTROW (the starting row of ROWKEY). First navigate to region based on this key, and then scan backwards), STOPROW (ending line), TIMERANGE (limited timestamp range), VERSIONS (number of versions), and FILTER (filter rows by condition), and so on. For example, let's start with the rowkey of Sariel and find the latest version of the next line:
> scan 'member', {STARTROW = >' Sariel', LIMIT= > 1, VERSIONS= > 1} ROW COLUMN+CELL Sariel column=address:city, timestamp=1425891056965, value=beijing Sariel column=address:country, timestamp=1425891057003, value=china Sariel column=id:, timestamp=1425891056767, value=21 Sariel column=info:age, timestamp=1425891056808, value=26 Sariel column=info:birthday, timestamp=1425891056883, value=1988-05-09 Sariel column=info:industry, timestamp=1425891056924, value=it1 row (s) in 0.0410 seconds
Filter is a very powerful modifier that can be filtered by a series of conditions. For example, we want to limit the value of a column to 26:
> scan 'member', FILTER= > "ValueFilter (=,' binary:26')" ROW COLUMN+CELL Elvis column=info:age, timestamp=1425891057083, value=26 Sariel column=info:age, timestamp=1425891056808, value=262 row (s) in 0.0620 seconds
The value contains the value of 6:
> scan 'member', FILTER= > "ValueFilter (=,' substring:6')" Elvis column=info:age, timestamp=1425891057083, value=26 Sariel column=info:age, timestamp=1425891056808, value=262 row (s) in 0.0620 seconds
The prefix in the column name is birthday:
> scan 'member', FILTER= > "ColumnPrefixFilter (' birth')" ROW COLUMN+CELL Elvis column=info:birthday, timestamp=1425891057129, value=1988-09-14 Sariel column=info:birthday, timestamp=1425891056883 Value=1988-05-09 debugo column=info:birthday, timestamp=1425891056547, value=1987-04-04 3 row (s) in 0.0450 seconds
Multiple filter conditions are supported in FILTER through a combination of parentheses, AND, and OR.
> scan 'member', FILTER= > "ColumnPrefixFilter (' birth') AND ValueFilter ValueFilter (=, 'substring:1987')" ROW COLUMN+CELL Debugo column=info:birthday, timestamp=1425891056547, value=1987-04-041 row (s) in 0.0450 seconds
The same column of the same rowkey has multiple version, which is distinguished by timestamp. Each column cluster has multiple column. FIRSTKEYONLY, on the other hand, fetches only the first version of the first column of each column cluster. On the other hand, KEYONLY only takes out the key for each column and discards the information of the VALUE, which is generally used in combination with other filter. For example:
> scan 'member', FILTER= > "FirstKeyOnlyFilter ()" ROW COLUMN+CELL Elvis column=address:city, timestamp=1425891057211, value=beijing Sariel column=address:city, timestamp=1425891056965, value=beijing debugo column=address:city, timestamp=1425891056642 Value=beijing 3 row (s) in 0.0230 seconds > scan 'member', FILTER= > "KeyOnlyFilter ()" hbase (main): 055 member', FILTER= 0 > scan' member', FILTER= > "KeyOnlyFilter ()" ROW COLUMN+CELL Elvis column=address:city, timestamp=1425891057211, value=Elvis column=id:, timestamp=1425891057038, value=.
PrefixFilter is to judge the prefix of Rowkey, which is a very common function.
> scan 'member', FILTER= > "PrefixFilter (' E')" ROW COLUMN+CELL Elvis column=address:city, timestamp=1425891057211, value=beijing. 1 row (s) in 0.0460 seconds and above are all the contents of this article entitled "what are the common operations of HBase Shell?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.