Uploaded image for project: 'HBase'
  1. HBase
  2. HBASE-4811

Support reverse Scan

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.20.6, 0.94.7
    • 0.98.0
    • Client
    • None
    • Reviewed
    • Hide
      == What is it?

      HBase 0.98 introduces a reverse scanner, so that you can scan rows in reverse order as well as the default order. Previously, if you wanted to scan in reverse, you needed to save rows in reverse order.

      == Why do you want it?

      One common use case is data stored with timestamps. Previously, when you created the schema, you needed to make a design decision about whether you wanted faster access to records with old timestamps or new ones. If you wanted to be able to scan in reverse, you needed to store the data twice, sorted forward and reverse.

      With the reverse scanner in HBase 0.98, you can choose whether to scan your data in either direction. The reverse scanner is only a few percent slower than the default scanner.

      == How do you set it up?
      No setup is required.

      == How do you use it?
      Use the Scan.setReversed(boolean reversed) API call:
      Scan.setReversed(true)

      If you specify a startRow and stopRow, to scan in reverse, the startRow needs to be lexicographically after the stopRow.

      Refer to the API documentation for more information about the Scan API (http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html).

      NOTE: Rows are reversed only. Columns in a row still sort forward even if you specify reverse on your scan.
      Show
      == What is it? HBase 0.98 introduces a reverse scanner, so that you can scan rows in reverse order as well as the default order. Previously, if you wanted to scan in reverse, you needed to save rows in reverse order. == Why do you want it? One common use case is data stored with timestamps. Previously, when you created the schema, you needed to make a design decision about whether you wanted faster access to records with old timestamps or new ones. If you wanted to be able to scan in reverse, you needed to store the data twice, sorted forward and reverse. With the reverse scanner in HBase 0.98, you can choose whether to scan your data in either direction. The reverse scanner is only a few percent slower than the default scanner. == How do you set it up? No setup is required. == How do you use it? Use the Scan.setReversed(boolean reversed) API call: Scan.setReversed(true) If you specify a startRow and stopRow, to scan in reverse, the startRow needs to be lexicographically after the stopRow. Refer to the API documentation for more information about the Scan API ( http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html ). NOTE: Rows are reversed only. Columns in a row still sort forward even if you specify reverse on your scan.
    • Phoenix

    Description

      Reversed scan means scan the rows backward.
      And StartRow bigger than StopRow in a reversed scan.

      For example, for the following rows:

      aaa/c1:q1/value1
      aaa/c1:q2/value2
      bbb/c1:q1/value1
      bbb/c1:q2/value2
      ccc/c1:q1/value1
      ccc/c1:q2/value2
      ddd/c1:q1/value1
      ddd/c1:q2/value2
      eee/c1:q1/value1
      eee/c1:q2/value2

      you could do a reversed scan from 'ddd' to 'bbb'(exclude) like this:

      Scan scan = new Scan();
      scan.setStartRow('ddd');
      scan.setStopRow('bbb');
      scan.setReversed(true);
      for(Result result:htable.getScanner(scan)){
      System.out.println(result);
      }

      Aslo you could do the reversed scan with shell like this:
      hbase> scan 'table',

      {REVERSED => true,STARTROW=>'ddd', STOPROW=>'bbb'}

      And the output is:
      ddd/c1:q1/value1
      ddd/c1:q2/value2
      ccc/c1:q1/value1
      ccc/c1:q2/value2

      All the documentation I find about HBase says that if you want forward and reverse scans you should just build 2 tables and one be ascending and one descending. Is there a fundamental reason that HBase only supports forward Scan? It seems like a lot of extra space overhead and coding overhead (to keep them in sync) to support 2 tables.

      I am assuming this has been discussed before, but I can't find the discussions anywhere about it or why it would be infeasible.

      Attachments

        1. 4811-0.94-v25.txt
          147 kB
          Lars Hofhansl
        2. 4811-trunk-v29.patch
          153 kB
          Ted Yu
        3. hbase-4811-trunkv28.patch
          153 kB
          Chunhui Shen
        4. hbase-4811-trunkv27.patch
          162 kB
          Chunhui Shen
        5. hbase-4811-trunkv26.patch
          162 kB
          Chunhui Shen
        6. hbase-4811-trunkv25.patch
          162 kB
          Chunhui Shen
        7. hbase-4811-trunkv24.patch
          162 kB
          Chunhui Shen
        8. hbase-4811-trunkv24.patch
          162 kB
          Chunhui Shen
        9. hbase-4811-0.94-v24.patch
          147 kB
          Chunhui Shen
        10. 4811-0.94-v23.txt
          151 kB
          Lars Hofhansl
        11. 4811-0.94-v22.txt
          147 kB
          Lars Hofhansl
        12. hbase-4811-trunkv21.patch
          161 kB
          Chunhui Shen
        13. hbase-4811-0.94 v21.patch
          147 kB
          Chunhui Shen
        14. hbase-4811-trunkv20.patch
          163 kB
          Chunhui Shen
        15. hbase-4811-trunkv19.patch
          153 kB
          Chunhui Shen
        16. hbase-4811-trunkv18.patch
          152 kB
          Chunhui Shen
        17. hbase-4811-trunkv17.patch
          152 kB
          Chunhui Shen
        18. 4811-0.94-v3.txt
          91 kB
          Lars Hofhansl
        19. hbase-4811-trunkv16.patch
          152 kB
          Chunhui Shen
        20. hbase-4811-trunkv15.patch
          152 kB
          Chunhui Shen
        21. hbase-4811-trunkv14.patch
          145 kB
          Chunhui Shen
        22. hbase-4811-trunkv13.patch
          152 kB
          Chunhui Shen
        23. hbase-4811-trunkv12.patch
          151 kB
          Chunhui Shen
        24. hbase-4811-trunkv11.patch
          139 kB
          Chunhui Shen
        25. 4811-trunk-v10.txt
          138 kB
          Ted Yu
        26. hbase-4811-trunkv9.patch
          138 kB
          Chunhui Shen
        27. hbase-4811-trunkv8.patch
          138 kB
          Chunhui Shen
        28. hbase-4811-trunkv7.patch
          136 kB
          Chunhui Shen
        29. hbase-4811-trunkv6.patch
          136 kB
          Chunhui Shen
        30. 4811-trunk-v5.patch
          135 kB
          Ted Yu
        31. hbase-4811-trunkv4.patch
          135 kB
          Chunhui Shen
        32. hbase-4811-trunkv1.patch
          133 kB
          Chunhui Shen
        33. HBase-4811-0.94-v2.txt
          93 kB
          Liang Xie
        34. HBase-4811-0.94.3modified.txt
          55 kB
          Liang Xie

        Issue Links

          Activity

            People

              zjushch Chunhui Shen
              johnyoh John Carrino
              Votes:
              2 Vote for this issue
              Watchers:
              34 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: