HBase problems in processing Chinese strings

Source: Internet
Author: User

APIS involved in this article:

Hadoop/HDFS: http://hadoop.apache.org/common/docs/current/api/

HBase: http://hbase.apache.org/apidocs/index.html? Overview-summary.html

Begin!

 

When setting the startRowKey and endRowKey of scan, you often need to add a range after a condition string. (For example, SingleColumnValueFilter will also be used)

For example, if my condition string is "abc", You need to include the following content in the scan range.

Abc123

Abcdabc

Abccca

....

At this time, startRowKey can use "abc". The above string is larger than "abc" in the Lexicographic Order, and the value after the "abc" string is 0 ~

While endRowKey initially used "abc ~", Because when I check the ASCII code table '~ 'Is the second-to-last character. The value is 127, which is large enough and must be greater than 1, d, c, and other characters in the above string.

In this way, it is enough to process the English data and the system runs normally.

However, when I process Chinese data, Chinese is generally processed in the UTF-8 format, a Chinese character is expressed like "0xe6, 0xc2, 0xe1 ". 0xe6 must be greater than 127. So use '~ 'The Chinese character must be miserable.

My solution:

Use UltraEdit to enter the hexadecimal editing mode and change the value to FF. Then return to the text mode and copy the character. This character should be a non-printable character. It looks like the length of two spaces.

Then, when you set the endRowKey

New String (name + ""); // here is just an example. The quotation marks are the copied character. Use this string as the endRowKey, and all Chinese characters are included.

Note: Do not use str when using HBase APIs. getBytes converts String to byte [], instead of Bytes. toBytes (str); also use Bytes. toString (bytes); completes reverse conversion.

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.