Class Range

java.lang.Object
org.apache.accumulo.core.data.Range
All Implemented Interfaces:
Comparable<Range>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<Range>

public class Range extends Object implements org.apache.hadoop.io.WritableComparable<Range>
This class is used to specify a range of Accumulo keys.
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Creates a range that goes from negative to positive infinity
     
    Creates a range that covers an entire row.
     
    Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow, boolean endRowInclusive)
    Creates a range from startRow to endRow.
     
    Range(CharSequence startRow, CharSequence endRow)
    Creates a range from startRow inclusive to endRow inclusive.
    protected
    Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop, boolean stopKeyInclusive, boolean infiniteStopKey)
    Creates a range from start to stop.
     
    Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive)
    Creates a range from startKey to endKey.
     
    Range(Key startKey, Key endKey)
    Creates a range from startKey inclusive to endKey inclusive.
     
    Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive, boolean infiniteStartKey, boolean infiniteStopKey)
    Creates a range from start to stop.
     
    Range(Range range)
    Copies a range.
     
    Range(org.apache.accumulo.core.data.thrift.TRange trange)
    Creates a range from a Thrift range.
     
    Range(org.apache.hadoop.io.Text row)
    Creates a range that covers an entire row.
     
    Range(org.apache.hadoop.io.Text startRow, boolean startRowInclusive, org.apache.hadoop.io.Text endRow, boolean endRowInclusive)
    Creates a range from startRow to endRow.
     
    Range(org.apache.hadoop.io.Text startRow, org.apache.hadoop.io.Text endRow)
    Creates a range from startRow inclusive to endRow inclusive.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Determines if the given key is after the ending key of this range.
    boolean
    Determines if the given key is before the start key of this range.
    bound(Column min, Column max)
    Creates a new range that is bounded by the columns passed in.
    clip(Range range)
    Creates a range which represents the intersection of this range and the passed in range.
    clip(Range range, boolean returnNullIfDisjoint)
    Creates a range which represents the intersection of this range and the passed in range.
    int
    Compares this range to another range.
    boolean
    Determines if the given key falls within this range.
    boolean
     
    boolean
    equals(Range otherRange)
    Determines if this range equals another.
    static Range
    Creates a range that covers an exact row.
    static Range
    Creates a range that covers an exact row and column family.
    static Range
    Creates a range that covers an exact row, column family, and column qualifier.
    static Range
    Creates a range that covers an exact row, column family, column qualifier, and column visibility.
    static Range
    Creates a range that covers an exact row, column family, column qualifier, column visibility, and timestamp.
    static Range
    exact(org.apache.hadoop.io.Text row)
    Creates a range that covers an exact row.
    static Range
    exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf)
    Creates a range that covers an exact row and column family.
    static Range
    exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq)
    Creates a range that covers an exact row, column family, and column qualifier.
    static Range
    exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cv)
    Creates a range that covers an exact row, column family, column qualifier, and column visibility.
    static Range
    exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cv, long ts)
    Creates a range that covers an exact row, column family, column qualifier, column visibility, and timestamp.
    static org.apache.hadoop.io.Text
    followingPrefix(org.apache.hadoop.io.Text prefix)
    Returns a Text that sorts just after all Texts beginning with a prefix.
    Gets the ending key, or null if the end is positive infinity.
    Gets the start key, or null if the start is negative infinity.
    int
     
    boolean
    Gets whether the end key of this range is inclusive.
    boolean
    Gets whether the start key is negative infinity.
    boolean
    Gets whether the end key is positive infinity.
    boolean
    Gets whether the start key of this range is inclusive.
    static List<Range>
    Merges overlapping and adjacent ranges.
    static Range
    prefix(CharSequence rowPrefix)
    Returns a Range that covers all rows beginning with a prefix.
    static Range
    Returns a Range that covers all column families beginning with a prefix within a given row.
    static Range
    Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family.
    static Range
    Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier.
    static Range
    prefix(org.apache.hadoop.io.Text rowPrefix)
    Returns a Range that covers all rows beginning with a prefix.
    static Range
    prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cfPrefix)
    Returns a Range that covers all column families beginning with a prefix within a given row.
    static Range
    prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cqPrefix)
    Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family.
    static Range
    prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cvPrefix)
    Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier.
    void
     
     
    org.apache.accumulo.core.data.thrift.TRange
    Converts this range to Thrift.
    void
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Range

      public Range()
      Creates a range that goes from negative to positive infinity
    • Range

      public Range(Key startKey, Key endKey)
      Creates a range from startKey inclusive to endKey inclusive.
      Parameters:
      startKey - starting key; set to null for negative infinity
      endKey - ending key; set to null for positive infinity
      Throws:
      IllegalArgumentException - if end key is before start key
    • Range

      public Range(CharSequence row)
      Creates a range that covers an entire row.
      Parameters:
      row - row to cover; set to null to cover all rows
    • Range

      public Range(org.apache.hadoop.io.Text row)
      Creates a range that covers an entire row.
      Parameters:
      row - row to cover; set to null to cover all rows
    • Range

      public Range(org.apache.hadoop.io.Text startRow, org.apache.hadoop.io.Text endRow)
      Creates a range from startRow inclusive to endRow inclusive.
      Parameters:
      startRow - starting row; set to null for negative infinity
      endRow - ending row; set to null for positive infinity
      Throws:
      IllegalArgumentException - if end row is before start row
    • Range

      public Range(CharSequence startRow, CharSequence endRow)
      Creates a range from startRow inclusive to endRow inclusive.
      Parameters:
      startRow - starting row; set to null for negative infinity
      endRow - ending row; set to null for positive infinity
      Throws:
      IllegalArgumentException - if end row is before start row
    • Range

      public Range(org.apache.hadoop.io.Text startRow, boolean startRowInclusive, org.apache.hadoop.io.Text endRow, boolean endRowInclusive)
      Creates a range from startRow to endRow.
      Parameters:
      startRow - starting row; set to null for negative infinity
      startRowInclusive - true to include start row, false to skip
      endRow - ending row; set to null for positive infinity
      endRowInclusive - true to include end row, false to skip
      Throws:
      IllegalArgumentException - if end row is before start row
    • Range

      public Range(CharSequence startRow, boolean startRowInclusive, CharSequence endRow, boolean endRowInclusive)
      Creates a range from startRow to endRow.
      Parameters:
      startRow - starting row; set to null for negative infinity
      startRowInclusive - true to include start row, false to skip
      endRow - ending row; set to null for positive infinity
      endRowInclusive - true to include end row, false to skip
      Throws:
      IllegalArgumentException - if end row is before start row
    • Range

      public Range(Key startKey, boolean startKeyInclusive, Key endKey, boolean endKeyInclusive)
      Creates a range from startKey to endKey.
      Parameters:
      startKey - starting key; set to null for negative infinity
      startKeyInclusive - true to include start key, false to skip
      endKey - ending key; set to null for positive infinity
      endKeyInclusive - true to include end key, false to skip
      Throws:
      IllegalArgumentException - if end key is before start key
    • Range

      public Range(Range range)
      Copies a range.
      Parameters:
      range - range to copy
    • Range

      public Range(Key start, Key stop, boolean startKeyInclusive, boolean stopKeyInclusive, boolean infiniteStartKey, boolean infiniteStopKey)
      Creates a range from start to stop.
      Parameters:
      start - set this to null when negative infinity is needed
      stop - set this to null when infinity is needed
      startKeyInclusive - determines if the ranges includes the start key
      stopKeyInclusive - determines if the range includes the end key
      infiniteStartKey - true if start key is negative infinity (null)
      infiniteStopKey - true if stop key is positive infinity (null)
      Throws:
      IllegalArgumentException - if stop is before start, or infiniteStartKey is true but start is not null, or infiniteStopKey is true but stop is not null
    • Range

      protected Range(Key start, boolean startKeyInclusive, boolean infiniteStartKey, Key stop, boolean stopKeyInclusive, boolean infiniteStopKey)
      Creates a range from start to stop. Unlike the public six-argument method, this one does not assure that stop is after start, which helps performance in cases where that assurance is already in place.
      Parameters:
      start - set this to null when negative infinity is needed
      startKeyInclusive - determines if the ranges includes the start key
      infiniteStartKey - true if start key is negative infinity (null)
      stop - set this to null when infinity is needed
      stopKeyInclusive - determines if the range includes the end key
      infiniteStopKey - true if stop key is positive infinity (null)
      Throws:
      IllegalArgumentException - if infiniteStartKey is true but start is not null, or infiniteStopKey is true but stop is not null
    • Range

      public Range(org.apache.accumulo.core.data.thrift.TRange trange)
      Creates a range from a Thrift range.
      Parameters:
      trange - Thrift range
  • Method Details

    • getStartKey

      public Key getStartKey()
      Gets the start key, or null if the start is negative infinity.
      Returns:
      start key
    • beforeStartKey

      public boolean beforeStartKey(Key key)
      Determines if the given key is before the start key of this range.
      Parameters:
      key - key to check
      Returns:
      true if the given key is before the range, otherwise false
    • getEndKey

      public Key getEndKey()
      Gets the ending key, or null if the end is positive infinity.
      Returns:
      ending key
    • afterEndKey

      public boolean afterEndKey(Key key)
      Determines if the given key is after the ending key of this range.
      Parameters:
      key - key to check
      Returns:
      true if the given key is after the range, otherwise false
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(Range otherRange)
      Determines if this range equals another.
      Parameters:
      otherRange - range to compare
      Returns:
      true if ranges are equals, false otherwise
      See Also:
    • compareTo

      public int compareTo(Range o)
      Compares this range to another range. Compares in order: start key, inclusiveness of start key, end key, inclusiveness of end key. Infinite keys sort first, and non-infinite keys are compared with Key.compareTo(Key). Inclusive sorts before non-inclusive.
      Specified by:
      compareTo in interface Comparable<Range>
      Parameters:
      o - range to compare
      Returns:
      comparison result
    • contains

      public boolean contains(Key key)
      Determines if the given key falls within this range.
      Parameters:
      key - key to consider
      Returns:
      true if the given key falls within the range, false otherwise
    • mergeOverlapping

      public static List<Range> mergeOverlapping(Collection<Range> ranges)
      Merges overlapping and adjacent ranges. For example given the following input:
       [a,c], (c, d], (g,m), (j,t]
       
      the following ranges would be returned:
       [a,d], (g,t]
       
      Parameters:
      ranges - to merge
      Returns:
      list of merged ranges
    • clip

      public Range clip(Range range)
      Creates a range which represents the intersection of this range and the passed in range. The following example will print true.
       Range range1 = new Range("a", "f");
       Range range2 = new Range("c", "n");
       Range range3 = range1.clip(range2);
       System.out.println(range3.equals(new Range("c", "f")));
       
      Parameters:
      range - range to clip to
      Returns:
      the intersection of this range and the given range
      Throws:
      IllegalArgumentException - if ranges does not overlap
    • clip

      public Range clip(Range range, boolean returnNullIfDisjoint)
      Creates a range which represents the intersection of this range and the passed in range. Unlike clip(Range), this method can optionally return null if the ranges do not overlap, instead of throwing an exception. The returnNullIfDisjoint parameter controls this behavior.
      Parameters:
      range - range to clip to
      returnNullIfDisjoint - true to return null if ranges are disjoint, false to throw an exception
      Returns:
      the intersection of this range and the given range, or null if ranges do not overlap and returnNullIfDisjoint is true
      Throws:
      IllegalArgumentException - if ranges does not overlap and returnNullIfDisjoint is false
      See Also:
    • bound

      public Range bound(Column min, Column max)
      Creates a new range that is bounded by the columns passed in. The start key in the returned range will have a column >= to the minimum column. The end key in the returned range will have a column <= the max column.
      Parameters:
      min - minimum column
      max - maximum column
      Returns:
      a column bounded range
      Throws:
      IllegalArgumentException - if the minimum column compares greater than the maximum column
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • readFields

      public void readFields(DataInput in) throws IOException
      Specified by:
      readFields in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • write

      public void write(DataOutput out) throws IOException
      Specified by:
      write in interface org.apache.hadoop.io.Writable
      Throws:
      IOException
    • isStartKeyInclusive

      public boolean isStartKeyInclusive()
      Gets whether the start key of this range is inclusive.
      Returns:
      true if start key is inclusive
    • isEndKeyInclusive

      public boolean isEndKeyInclusive()
      Gets whether the end key of this range is inclusive.
      Returns:
      true if end key is inclusive
    • toThrift

      public org.apache.accumulo.core.data.thrift.TRange toThrift()
      Converts this range to Thrift.
      Returns:
      Thrift range
    • isInfiniteStartKey

      public boolean isInfiniteStartKey()
      Gets whether the start key is negative infinity.
      Returns:
      true if start key is negative infinity
    • isInfiniteStopKey

      public boolean isInfiniteStopKey()
      Gets whether the end key is positive infinity.
      Returns:
      true if end key is positive infinity
    • exact

      public static Range exact(org.apache.hadoop.io.Text row)
      Creates a range that covers an exact row. Returns the same Range as Range(Text).
      Parameters:
      row - row to cover; set to null to cover all rows
    • exact

      public static Range exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf)
      Creates a range that covers an exact row and column family.
      Parameters:
      row - row to cover
      cf - column family to cover
    • exact

      public static Range exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq)
      Creates a range that covers an exact row, column family, and column qualifier.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
    • exact

      public static Range exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cv)
      Creates a range that covers an exact row, column family, column qualifier, and column visibility.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cv - column visibility to cover
    • exact

      public static Range exact(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cv, long ts)
      Creates a range that covers an exact row, column family, column qualifier, column visibility, and timestamp.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cv - column visibility to cover
      ts - timestamp to cover
    • followingPrefix

      public static org.apache.hadoop.io.Text followingPrefix(org.apache.hadoop.io.Text prefix)
      Returns a Text that sorts just after all Texts beginning with a prefix.
      Parameters:
      prefix - to follow
      Returns:
      prefix that immediately follows the given prefix when sorted, or null if no prefix can follow (i.e., the string is all 0xff bytes)
    • prefix

      public static Range prefix(org.apache.hadoop.io.Text rowPrefix)
      Returns a Range that covers all rows beginning with a prefix.
      Parameters:
      rowPrefix - prefix of rows to cover
    • prefix

      public static Range prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cfPrefix)
      Returns a Range that covers all column families beginning with a prefix within a given row.
      Parameters:
      row - row to cover
      cfPrefix - prefix of column families to cover
    • prefix

      public static Range prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cqPrefix)
      Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family.
      Parameters:
      row - row to cover
      cf - column family to cover
      cqPrefix - prefix of column qualifiers to cover
    • prefix

      public static Range prefix(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, org.apache.hadoop.io.Text cvPrefix)
      Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cvPrefix - prefix of column visibilities to cover
    • exact

      public static Range exact(CharSequence row)
      Creates a range that covers an exact row.
      Parameters:
      row - row to cover; set to null to cover all rows
      See Also:
    • exact

      public static Range exact(CharSequence row, CharSequence cf)
      Creates a range that covers an exact row and column family.
      Parameters:
      row - row to cover
      cf - column family to cover
      See Also:
    • exact

      public static Range exact(CharSequence row, CharSequence cf, CharSequence cq)
      Creates a range that covers an exact row, column family, and column qualifier.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      See Also:
    • exact

      public static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv)
      Creates a range that covers an exact row, column family, column qualifier, and column visibility.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cv - column visibility to cover
      See Also:
    • exact

      public static Range exact(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv, long ts)
      Creates a range that covers an exact row, column family, column qualifier, column visibility, and timestamp.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cv - column visibility to cover
      ts - timestamp to cover
      See Also:
    • prefix

      public static Range prefix(CharSequence rowPrefix)
      Returns a Range that covers all rows beginning with a prefix.
      Parameters:
      rowPrefix - prefix of rows to cover
      See Also:
    • prefix

      public static Range prefix(CharSequence row, CharSequence cfPrefix)
      Returns a Range that covers all column families beginning with a prefix within a given row.
      Parameters:
      row - row to cover
      cfPrefix - prefix of column families to cover
      See Also:
    • prefix

      public static Range prefix(CharSequence row, CharSequence cf, CharSequence cqPrefix)
      Returns a Range that covers all column qualifiers beginning with a prefix within a given row and column family.
      Parameters:
      row - row to cover
      cf - column family to cover
      cqPrefix - prefix of column qualifiers to cover
      See Also:
    • prefix

      public static Range prefix(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cvPrefix)
      Returns a Range that covers all column visibilities beginning with a prefix within a given row, column family, and column qualifier.
      Parameters:
      row - row to cover
      cf - column family to cover
      cq - column qualifier to cover
      cvPrefix - prefix of column visibilities to cover
      See Also: