简体   繁体   English

如何更改 hbase 表扫描结果顺序

[英]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.我正在尝试将特定数据从一个 hbase 表复制到另一个,这需要仅扫描表中的行键并从那里解析特定值。 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?您是否尝试过 Scan 的 .setReversed() 属性? 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'.请记住,在这种情况下,您的起始行必须是您的 rowKey 范围的逻辑 END,并且从那里它会“向上”扫描。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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