Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why would you want to return every record in your 100000 records table? You're doing a full table scan and just as in any large database this is slow. </p> <p>Try thinking about a more useful use case in which you would like to return some columns of a record or a range of records.</p> <p>HBase does only have one index on it's table, the row key. Make use of that. Try defining your row key so that you can get the data you need just by specifying the row key.</p> <p>Let's say you would like to know the value of <code>Subject:History</code> for the rows with a row key between 80000 and 80100. (Note that <code>setCaching(100)</code> means HBase will fetch 100 records per RPC and is this case thus one. Fetching 100 rows obviously requires more memory opposed to fetching, let's say, one row. Keep that in mind in a large multi-user environment.)</p> <pre><code>Long start, end; start = System.currentTimeMillis(); Scan s = new Scan(String.valueOf(80000).getBytes(), String.valueOf(80100).getBytes()); s.setCaching(100); s.addColumn("Subject".getBytes(), "History".getBytes()); ResultScanner scanner = table.getScanner(s); try { for (Result rr = scanner.next(); rr != null; rr=scanner.next()) { System.out.println("Found row: " + new String(rr.getRow(), "UTF-8") + " value: " + new String(rr.getValue("Subject".getBytes(), "History".getBytes()), "UTF-8"))); } end = System.currentTimeMillis(); } finally { scanner.close(); } System.out.println("Scan: " + (end - start)); </code></pre> <p>This might look stupid because how would you know which rows you need just by an integer? Well, exactly, but that's why you need to design a row key according to what you're about to query instead of just using an incremental value as you would in a traditional database.</p> <p>Try this example. It should be fast. </p> <p>Note: I didn't run the example. I just typed it here. Maybe there are some small syntax errors you should correct but I hope the idea is clear.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload