The set of HBase basic operations are referred to as CRUD operations. i.e. create, read, update, delete operations. HBase scan command is used to get data out of HBase tables. In this article, we will check how to read HBase tables using scan shell command and various examples.
HBase scan command
The HBase scan command is yet another HBase shell command that you can use to read the table. Scan command is similar to HBase get shell command but supports more options. The HBase scan command scans entire table and displays the table contents. You can execute HBase scan command with various other options or attributes such as TIMERANGE, FILTER, TIMESTAMP, LIMIT, MAXLENGTH, COLUMNS, CACHE, STARTROW and STOPROW.
We will use the table ‘personal’ that we have created as part of Insert data using HBase shell put command.
HBase Scan Command Syntax
Below is the HBase scan command syntax:
scan 'personal', {attributes => ‘value’}
HBase Scan Command Example
Example to read HBase table using scan command:
hbase(main):009:0> scan 'personal' ROW COLUMN+CELL 1 column=personal_data:age, timestamp=1505285659934, value=25 1 column=personal_data:city, timestamp=1505285653043, value=Bengaluru 1 column=personal_data:name, timestamp=1505285635428, value=Ram 2 column=personal_data:age, timestamp=1505286495492, value=24 2 column=personal_data:city, timestamp=1505286495492, value=Bengaluru 2 column=personal_data:name, timestamp=1505286495492, value=sham 2 row(s) in 0.0460 seconds
HBase Scan command with various attributes or options:
hbase(main):008:0> scan 'personal' , {COLUMNS => 'personal_data:name', LIMIT => 10, STARTROW => '3'} ROW COLUMN+CELL 3 column=personal_data:name, timestamp=1505286495492, value=Guru 4 column=personal_data:name, timestamp=1505286495492, value=John 5 column=personal_data:name, timestamp=1505286495492, value=Rock 3 row(s) in 0.0150 seconds
HBase scan commands with Filters
Below are some examples to demonstrate how to use filter in hbase shell.
Below example explain use of HBase KeyOnlyFilter:
This filter does not take any arguments. It returns only the key component of each k
hbase(main):018:0> scan 'emp',{ FILTER => "KeyOnlyFilter()"} ROW COLUMN+CELL 1 column=personal_data:city, timestamp=1501587154609, value= 1 column=personal_data:name, timestamp=1501587131490, value= 10 column=personal_data:city, timestamp=1501590338062, value= 11 column=personal_data:city, timestamp=1501590380498, value= 12 column=personal_data:city, timestamp=1501591062068, value= 13 column=personal_data:city, timestamp=1501592423889, value= 14 column=personal_data:city, timestamp=1501592816324, value= 15 column=personal_data:city, timestamp=1501596615499, value= 16 column=personal_data:city, timestamp=1505197739790, value= 16 column=personal_data:name, timestamp=1505197712574, value= 2 column=personal_data:city, timestamp=1501588125116, value= 3 column=personal_data:city, timestamp=1501588130621, value= 4 column=personal_data:city, timestamp=1501588135719, value= 5 column=personal_data:city, timestamp=1501588339919, value= 6 column=personal_data:city, timestamp=1501588345310, value= 7 column=personal_data:city, timestamp=1501589123534, value= 8 column=personal_data:city, timestamp=1501589222829, value= 9 column=personal_data:city, timestamp=1501590307575, value= 16 row(s) in 0.1070 seconds
For list of filters available in HBase, check out show_filter command section in “commonly used HBase Table management commands”
Read:
- Insert data using HBase shell put Command and Examples
- Read HBase Table using HBase shell get Command
- Hadoop HDFS Architecture Introduction and Design
- Create Tables using HBase Shell
- Official Apache HBase documentation
- HBase Architecture and its Components