Hbase may be used because of business needs and real-time statistics requirements. Therefore, we have reposted some articles on hbase.
Reproduced from: Taobao QA Team, original address: http://qa.taobao.com /? P = 13871
Hbase provides rich access interfaces.
• Hbase Shell
• Java clietn API
• Jython, groovy DSL, Scala
• Rest
• Thrift (Ruby, Python, Perl, C ++ ...)
• Mapreduce
• Hive/Pig
Hbase shell is a common convenient method. We will use the theoretical analysis of the previous article in this series to practice it. We still use the blog representation example.
First you need an hbase environment, if you need to build your own can refer to http://hbase.apache.org/book/quickstart.html and http://hbase.apache.org/book/notsoquick.html. If you encounter problems configuring cygwin and SSH in windows, refer to the http://qa.taobao.com /? P = 10633.
Go to the hbase shell Console
>bin/hbase shell
It seems that the console is parsed by the jruby language. Enter "help" to quickly scan for supported commands.
Create a table
> create 'blog','article','author'
Review of knowledge points: column family is a part of schema, but column is not. Here, article and author are column family.
Add record
> Put 'blog ', '1', 'Article: title, 'head first hbase'
> Put 'blog ', '1', 'Article: content', 'hbase is the hadoop database. use it when you need random, realtime read/write access to your big data.'
> Put 'blog ', '1', 'Article: tags', 'hadoop, hbase, nosql'
> Put 'blog ', '1', 'author: name', 'hujinjun'
> Put 'blog ', '1', 'author: nickname', 'yiye dujiang'
Review of knowledge points: column is fully dynamic, and each row can have different columns.
Query by rowkey
> get 'blog','1'
Knowledge Point Review: htable is automatically sorted by rowkey Lexicographic Order (, 11, 2), each line contains any number
Columns, columns are automatically sorted by columnkey (Article: content, article: tags, article: title, author: name, Author: nickname)
Update exercise
Query the values before update:> get ‘blog’,’1’,’author:nickname’
Update nickname to 'yedu ':> put ‘blog’,’1’,’ahthor:nickname’,’yedu’
Query the updated results:> get ‘blog’,’1’,’author:nickname’
Knowledge Point Review: The query returns the most recent value by default.
Query multiple versions of nickname (2 in this example ).> get 'blog','1',{COLUMN => 'author:nickname',VERSIONS => 2}
Knowledge Point review: each column can have any number of values, which are automatically sorted by timestamp in reverse order.
How can I query only the old versions?>get 'blog','1',{COLUMN => 'author:nickname', TIMESTAMP => 1317180070811}
Knowledge Point Review: tabelname + rowkey + column + timestamp => Value
Delete record
Delete can delete only one column>delete 'blog','1','author:nickname'
Delete all columns of rowkey with deleteall>deleteall ‘blog’,’1’
Delete table
After the exercise is completed, delete the exercise table. before deleting the exercise table, you must disable it.
>disable ‘blog’
>drop ‘blog’
Summary
This article demonstrates how to create, delete, and add, delete, modify, and query records through hbase shell. You can refer to the operation results to further understand the review knowledge points, the next article in this series demonstrates how to use Java APIs to interact with hbase.