HBase condition query (Multi-condition query)

Source: Internet
Author: User
Apis involved in this article: HadoopHDFS: hadoop. apache. orgcommondocscurrentapiHBase: hbase. apache. orgapido

Apis involved in this article: Hadoop/HDFS: http://hadoop.apache.org/common/docs/current/api/ HBase: http://hbase.apache.org/apido

APIS involved in this article:

Hadoop/HDFS:

HBase :? Overview-summary.html

Begin!

HBase queries are implemented in either of the following ways:

1. Obtain a unique record based on the specified RowKey. get method (org. apache. hadoop. hbase. client. Get)

2. Obtain a batch of records according to the specified conditions. scan Method (org. apache. hadoop. hbase. client. Scan)

The scan method is used to implement the conditional query function. The following points are worth noting when using scan:

1. scan can improve the speed by using the setCaching and setBatch methods (changing the time by space );

2. scan can be defined by setStartRow and setEndRow. The smaller the range, the higher the performance.

Through the clever RowKey design, we can obtain elements in the record set in batches together (which should be under the same Region), which can achieve good performance when traversing the results.

3. scan can use the setFilter method to add a filter, which is also the basis for paging and multi-condition queries.

The following is an image example:

The file information is stored in the Table. Each file has five attributes: File id (long, globally unique), Creation Time (long), and file name (String), category name (String), owner (User ).

Query conditions that can be entered: file creation time range (such as files created from 20120901 to 20120914), file name ("good voice in China"), classification ("Variety "), owner ("Zhejiang TV ").

Suppose we have a total of the following files:

Content list

IDCreateTimeNameCategoryUserID

120120902 Chinese good voice 1st series variety 1

220120904 Chinese good voice 2nd series variety 1

320120906 Chinese good voice card game variety 1

420120908 Chinese good voice 3rd series variety 1

520120910 Chinese good voice 4th series variety 1

620120912 Chinese good voice contestants interview variety highlights 2

720120914 Chinese good voice 5th series variety 1

820120916 Chinese sound recording highlights 2

920120918 interview with Zhang Wei 3

1020120920 jiadobao herbal tea Advertisement Variety advertisement 4

Here, the UserID corresponds to another User table, which is not currently listed. We only need to know the meaning of UserID:

1 stands for Zhejiang Satellite TV; 2 stands for good voices; 3 stands for XX Weibo; 4 stands for sponsors.
When calling the query interface, enter find (20120901,20121001, "") in the preceding five conditions ").

In this case, we should have 1st, 2, 3, 4, 5, and 7 records. Article 3 because it does not belong to "Zhejiang Satellite TV", it should not be selected.

We can do this when designing RowKey: Using UserID + CreateTime + FileID to form a rowKey, which can meet the multi-condition query and quickly query speed.

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.