简体   繁体   中英

how to change hbase table scan results order

I am trying to copy specific data from one hbase table to another which requires scanning the table for only rowkeys and parsing a specific value from there. It works fine but I noticed the results seem to be returned in ascending sort order & in this case alphabetically. Is there a way to specify a reverse order or perhaps by insert timestamp?

          Scan scan = new Scan();
          scan.setMaxResultSize(1000);
          scan.setFilter(new FirstKeyOnlyFilter());

          ResultScanner scanner = TestHbaseTable.getScanner(scan);

          for(Result r : scanner){
            System.out.println(Bytes.toString(r.getRow())); 
            String rowKey = Bytes.toString(r.getRow());

            if(rowKey.startsWith("dm.") || rowKey.startsWith("bk.") || rowKey.startsWith("rt.")) {
                continue;
            } else if(rowKey.startsWith("yt")) {
                List<String> ytresult = Arrays.asList(rowKey.split("\\s*.\\s*"));

               .....

This table is huge so I would prefer to skip to the rows I actually need. Appreciate any help here.

Have you tried the.setReversed() property of the Scan? Keep in mind that in this case your start row would have to be the logical END of your rowKey range, and from there it would scan 'upwards'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM