Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!
Labels (2)
avatar
New Member

It is a very common operation to do prefix scan in HBase. For example, when reading HBase table from HBase, we may use the following table scan api:

val prefixFilter = new PrefixFilter(prefix)
val scan: Scan = new Scan()
scan.setFilter(prefixFilter)

However, the code above may appear to be very slow when scanning a large HBase table. The reason is: we need to set StartRow before using PrefixFilter. Without setting the start row properly, your HBase scan may have to begin with the very first region and waste lots of time to get to the first right place.

The recommended way is to use setRowPrefixFilter(byte[] rowPrefix), from its source code below, we can see that it helps us to set up the start row before doing table scan.

409  public Scan setRowPrefixFilter(byte[] rowPrefix) {
410    if (rowPrefix == null) {
411      setStartRow(HConstants.EMPTY_START_ROW);
412      setStopRow(HConstants.EMPTY_END_ROW);
413    } else {
414      this.setStartRow(rowPrefix);
415      this.setStopRow(calculateTheClosestNextRowKeyForPrefix(rowPrefix));
416    }
417    return this;
418  }

In addition, if you want to load HBase table into Spark, you can also use the Spark-HBase connector, which support Spark accessing HBase table as external data source. The method buildScan() can do hbase table scan and return RDD as result. Its related source code is here.

Thanks to Weiqing Yang and Ted Yu for the kind help.

11,882 Views
Version history
Last update:
‎09-06-2016 11:57 PM
Updated by:
Contributors