HBase Shell Basic additions and deletions to check crud operations

Source: Internet
Author: User

1.1 HBase Command mode

The HBase Shell command provides a TAB key completion instruction.

$ hbase Shell

After entering shell command mode, you can use the HBase shell command to manipulate the data.

Convert an hbase log date ' 08/08/16 20:56:29 ' into a timestamp, which you can get:

HBase (main):021:0> import Java.text.SimpleDateFormat
hbase (main):022:0> import java.text.ParsePosition
HBase (Main): 023:0>simpledateformat.new ("Yy/mm/ddhh:mm:ss"). Parse ("08/08/16 20:56:29", Parseposition.new ( 0)). GetTime ()


= 1218920189000


Conversely, it can be obtained by similar operations.

HBase (main):021:0> import java.util.Date
hbase (main):022:0> date.new (1218920189000). ToString ()


= "Sat 20:56:29 UTC 2008"


1.2 Common HBase shell commands

1.2.1 Creating a Table

Create a table car, name a column family for exp (expensive abbreviation).

HBase (Main): 020:0>create ' car ', ' exp '


1.2.2 Inserting data

Insert three data, manufacturer, model, and production date. The specific commands are as follows:

Put ' car ', ' row1 ', ' exp:make ', ' BMW '
put ' car ', ' row1 ', ' Exp:model ', ' 5 series '
put ' car ', ' row1 ', ' exp:year ', ' 201 2-12-20 '
 
put ' car ', ' row2 ', ' exp:make ', ' Benz '
put ' car ', ' row2 ', ' Exp:model ', ' c200 '
put ' car ', ' row2 ', ' exp : Year ', ' 2013 '


1.2.3 Query

Queries all specified results, using scan with a specific cosmetic statement.

             HBase (main):043:0> scan ' car ', {COLUMNS =>[' exp:make '}


If you need to limit the data that returns only one row, you can do so:

HBase (main):044:0> scan ' car ', {columns=> [' Exp:make '], LIMIT = 1}


Notes:hbase shell commands are case-sensitive, such as columns, limit, and other keywords.

To get to a row, use the Get command with the following specific instructions:

HBase (main):045:0> get ' car ', ' row1 '
COLUMN                CELL                                                     
 exp:make             TIMESTAMP=1363919137232,VALUE=BMW                       
 Exp:model            timestamp=1363919183289, value= 5series                 
 exp:year             timestamp=1363919193544,value= 2012-12-20


1.2.4 Delete

Deletes the cell data, specifying the specific column name.

HBase (Main): 047:0>delete ' car ', ' row1 ', ' exp:year '


Check the specific data content, you can see the data has been deleted.

HBase (main):048:0> get ' car ', ' row1 '
COLUMN                CELL                                                     
 exp:make             TIMESTAMP=1363919137232,VALUE=BMW                       
 Exp:model            timestamp=1363919183289, value= 5series


To delete the table, you need to run the following command:

  HBase (Main): 050:0>disable ' car '
0 row (s) in 2.0460 seconds
    hbase (main):052:0> drop ' car '
0 row (s) in 1.0410 seconds


View the form and discover that it was deleted.

HBase (main):053:0> list
TABLE                                                                          
mytable                                                                        
1 row (s) in 0.0100 seconds


When you are not sure about a command, use the Help command.


NOTES: Reprint Please indicate the source, thank you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.