Class Key

  • All Implemented Interfaces:
    Cloneable, Comparable<Key>, org.apache.hadoop.io.Writable, org.apache.hadoop.io.WritableComparable<Key>

    public class Key
    extends Object
    implements org.apache.hadoop.io.WritableComparable<Key>, Cloneable
    This is the Key used to store and access individual values in Accumulo. A Key is a tuple composed of a row, column family, column qualifier, column visibility, timestamp, and delete marker. Keys are comparable and therefore have a sorted order defined by compareTo(Key).
    • Constructor Summary

      Constructors 
      Constructor Description
      Key()
      Creates a key with empty row, empty column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(byte[] row)
      Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(byte[] row, byte[] cf)
      Creates a key with the specified row, the specified column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(byte[] row, byte[] cf, byte[] cq)
      Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(byte[] row, byte[] cf, byte[] cq, byte[] cv)
      Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(byte[] row, byte[] colFamily, byte[] colQualifier, byte[] colVisibility, long timestamp)
      Creates a key.
      Key​(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted)
      Creates a key.
      Key​(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy)
      Creates a key.
      Key​(byte[] row, byte[] cf, byte[] cq, long ts)
      Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and delete marker false.
      Key​(byte[] row, byte[] cf, byte[] cq, ColumnVisibility cv, long ts)
      Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified timestamp, and delete marker false.
      Key​(byte[] row, int rOff, int rLen, byte[] cf, int cfOff, int cfLen, byte[] cq, int cqOff, int cqLen, byte[] cv, int cvOff, int cvLen, long ts)
      Creates a key.
      Key​(byte[] row, long ts)
      Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, the specified timestamp, and delete marker false.
      Key​(CharSequence row)
      Converts CharSequence to Text and creates a Key using Key(Text).
      Key​(CharSequence row, CharSequence cf)
      Converts CharSequence to Text and creates a Key using Key(Text,Text).
      Key​(CharSequence row, CharSequence cf, CharSequence cq)
      Converts CharSequence to Text and creates a Key using Key(Text,Text,Text).
      Key​(CharSequence row, CharSequence cf, CharSequence cq, long ts)
      Converts CharSequence to Text and creates a Key using Key(Text,Text,Text,long).
      Key​(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv)
      Converts CharSequence to Text and creates a Key using Key(Text,Text,Text,Text).
      Key​(CharSequence row, CharSequence cf, CharSequence cq, CharSequence cv, long ts)
      Converts CharSequence to Text and creates a Key using Key(Text,Text,Text,Text,long).
      Key​(CharSequence row, CharSequence cf, CharSequence cq, ColumnVisibility cv, long ts)
      Converts CharSequence to Text and creates a Key using Key(Text,Text,Text,ColumnVisibility,long).
      Key​(Key other)
      Creates a key with the same row, column family, column qualifier, column visibility, timestamp, and delete marker as the given key.
      Key​(TKey tkey)
      Creates a key from Thrift.
      Key​(org.apache.hadoop.io.Text row)
      Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(org.apache.hadoop.io.Text row, long ts)
      Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, the specified timestamp, and delete marker false.
      Key​(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf)
      Creates a key with the specified row, the specified column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq)
      Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, long ts)
      Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and delete marker false.
      Key​(org.apache.hadoop.io.Text row, org.apache.hadoop.io.Text cf, org.apache.hadoop.io.Text cq, ColumnVisibility cv, long ts)
      Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified timestamp, and delete marker false.
      Key​(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 key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      Key​(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 key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified timestamp, and delete marker false.
    • Field Detail

      • row

        protected byte[] row
      • colFamily

        protected byte[] colFamily
      • colQualifier

        protected byte[] colQualifier
      • colVisibility

        protected byte[] colVisibility
      • timestamp

        protected long timestamp
      • deleted

        protected boolean deleted
    • Constructor Detail

      • Key

        public Key()
        Creates a key with empty row, empty column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
      • Key

        public Key​(org.apache.hadoop.io.Text row)
        Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
        Parameters:
        row - row ID
        See Also:
        builder()
      • Key

        public Key​(org.apache.hadoop.io.Text row,
                   long ts)
        Creates a key with the specified row, empty column family, empty column qualifier, empty column visibility, the specified timestamp, and delete marker false.
        Parameters:
        row - row ID
        ts - timestamp
        See Also:
        builder()
      • Key

        public Key​(byte[] row,
                   int rOff,
                   int rLen,
                   byte[] cf,
                   int cfOff,
                   int cfLen,
                   byte[] cq,
                   int cqOff,
                   int cqLen,
                   byte[] cv,
                   int cvOff,
                   int cvLen,
                   long ts)
        Creates a key. The delete marker defaults to false. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should call Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy) instead.
        Parameters:
        row - bytes containing row ID
        rOff - offset into row where key's row ID begins (inclusive)
        rLen - length of row ID in row
        cf - bytes containing column family
        cfOff - offset into cf where key's column family begins (inclusive)
        cfLen - length of column family in cf
        cq - bytes containing column qualifier
        cqOff - offset into cq where key's column qualifier begins (inclusive)
        cqLen - length of column qualifier in cq
        cv - bytes containing column visibility
        cvOff - offset into cv where key's column visibility begins (inclusive)
        cvLen - length of column visibility in cv
        ts - timestamp
        See Also:
        builder()
      • Key

        public Key​(byte[] row,
                   byte[] colFamily,
                   byte[] colQualifier,
                   byte[] colVisibility,
                   long timestamp)
        Creates a key. The delete marker defaults to false. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should call Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy) instead.
        Parameters:
        row - row ID
        colFamily - column family
        colQualifier - column qualifier
        colVisibility - column visibility
        timestamp - timestamp
        See Also:
        builder()
      • Key

        public Key​(byte[] row,
                   byte[] cf,
                   byte[] cq,
                   byte[] cv,
                   long ts,
                   boolean deleted,
                   boolean copy)
        Creates a key.
        Parameters:
        row - row ID
        cf - column family
        cq - column qualifier
        cv - column visibility
        ts - timestamp
        deleted - delete marker
        copy - if true, forces copy of byte array values into key
        See Also:
        builder()
      • Key

        public Key​(org.apache.hadoop.io.Text row,
                   org.apache.hadoop.io.Text cf)
        Creates a key with the specified row, the specified column family, empty column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(org.apache.hadoop.io.Text row,
                   org.apache.hadoop.io.Text cf,
                   org.apache.hadoop.io.Text cq)
        Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, timestamp Long.MAX_VALUE, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(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 key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, timestamp Long.MAX_VALUE, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(org.apache.hadoop.io.Text row,
                   org.apache.hadoop.io.Text cf,
                   org.apache.hadoop.io.Text cq,
                   long ts)
        Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(byte[] row,
                   byte[] cf,
                   byte[] cq,
                   long ts)
        Creates a key with the specified row, the specified column family, the specified column qualifier, empty column visibility, the specified timestamp, and delete marker false. This constructor creates a copy of each specified array. If you don't want to create a copy of the arrays, you should call Key(byte[] row, byte[] cf, byte[] cq, byte[] cv, long ts, boolean deleted, boolean copy) instead.
        Since:
        1.8.0
        See Also:
        builder()
      • Key

        public Key​(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 key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified timestamp, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(org.apache.hadoop.io.Text row,
                   org.apache.hadoop.io.Text cf,
                   org.apache.hadoop.io.Text cq,
                   ColumnVisibility cv,
                   long ts)
        Creates a key with the specified row, the specified column family, the specified column qualifier, the specified column visibility, the specified timestamp, and delete marker false.
        See Also:
        builder()
      • Key

        public Key​(Key other)
        Creates a key with the same row, column family, column qualifier, column visibility, timestamp, and delete marker as the given key.
      • Key

        public Key​(TKey tkey)
        Creates a key from Thrift.
        Parameters:
        tkey - Thrift key
    • Method Detail

      • builder

        public static KeyBuilder.RowStep builder​(boolean copyBytes)
        Create a Key builder.
        Parameters:
        copyBytes - if the bytes of the Key components should be copied
        Returns:
        the builder at the KeyBuilder.RowStep
        Since:
        2.0
      • builder

        public static KeyBuilder.RowStep builder()
        Create a Key builder. Using the builder makes it easy to mix types, like String and byte[], for different fields. Copy bytes defaults to true.
        Returns:
        the builder at the KeyBuilder.RowStep
        Since:
        2.0
        See Also:
        builder(boolean)
      • getRow

        public org.apache.hadoop.io.Text getRow​(org.apache.hadoop.io.Text r)
        Writes the row ID into the given Text. This method gives users control over allocation of Text objects by copying into the passed in text.
        Parameters:
        r - Text object to copy into
        Returns:
        the Text that was passed in
      • getRowData

        public ByteSequence getRowData()
        Returns the row ID as a byte sequence. This method returns a pointer to the key's internal data and does not copy it.
        Returns:
        ByteSequence that points to the internal key row ID data
      • getRow

        public org.apache.hadoop.io.Text getRow()
        Gets the row ID as a Text object.
        Returns:
        Text containing the row ID
      • compareRow

        public int compareRow​(org.apache.hadoop.io.Text r)
        Compares this key's row ID with another.
        Parameters:
        r - row ID to compare
        Returns:
        same as getRow().compareTo(r)
      • getColumnFamilyData

        public ByteSequence getColumnFamilyData()
        Returns the column family as a byte sequence. This method returns a pointer to the key's internal data and does not copy it.
        Returns:
        ByteSequence that points to the internal key column family data
      • getColumnFamily

        public org.apache.hadoop.io.Text getColumnFamily​(org.apache.hadoop.io.Text cf)
        Writes the column family into the given Text. This method gives users control over allocation of Text objects by copying into the passed in text.
        Parameters:
        cf - Text object to copy into
        Returns:
        the Text that was passed in
      • getColumnFamily

        public org.apache.hadoop.io.Text getColumnFamily()
        Gets the column family as a Text object.
        Returns:
        Text containing the column family
      • compareColumnFamily

        public int compareColumnFamily​(org.apache.hadoop.io.Text cf)
        Compares this key's column family with another.
        Parameters:
        cf - column family to compare
        Returns:
        same as getColumnFamily().compareTo(cf)
      • getColumnQualifierData

        public ByteSequence getColumnQualifierData()
        Returns the column qualifier as a byte sequence. This method returns a pointer to the key's internal data and does not copy it.
        Returns:
        ByteSequence that points to the internal key column qualifier data
      • getColumnQualifier

        public org.apache.hadoop.io.Text getColumnQualifier​(org.apache.hadoop.io.Text cq)
        Writes the column qualifier into the given Text. This method gives users control over allocation of Text objects by copying into the passed in text.
        Parameters:
        cq - Text object to copy into
        Returns:
        the Text that was passed in
      • getColumnQualifier

        public org.apache.hadoop.io.Text getColumnQualifier()
        Gets the column qualifier as a Text object.
        Returns:
        Text containing the column qualifier
      • compareColumnQualifier

        public int compareColumnQualifier​(org.apache.hadoop.io.Text cq)
        Compares this key's column qualifier with another.
        Parameters:
        cq - column qualifier to compare
        Returns:
        same as getColumnQualifier().compareTo(cq)
      • setTimestamp

        public void setTimestamp​(long ts)
        Sets the timestamp.
        Parameters:
        ts - timestamp
      • getTimestamp

        public long getTimestamp()
        Gets the timestamp.
        Returns:
        timestamp
      • isDeleted

        public boolean isDeleted()
        Determines if this key is deleted (i.e., has a delete marker = true).
        Returns:
        true if key is deleted, false if not
      • setDeleted

        public void setDeleted​(boolean deleted)
        Sets the delete marker on this key.
        Parameters:
        deleted - delete marker (true to delete)
      • getColumnVisibilityData

        public ByteSequence getColumnVisibilityData()
        Returns the column visibility as a byte sequence. This method returns a pointer to the key's internal data and does not copy it.
        Returns:
        ByteSequence that points to the internal key column visibility data
      • getColumnVisibility

        public final org.apache.hadoop.io.Text getColumnVisibility()
        Gets the column visibility as a Text object.
        Returns:
        Text containing the column visibility
      • getColumnVisibility

        public final org.apache.hadoop.io.Text getColumnVisibility​(org.apache.hadoop.io.Text cv)
        Writes the column visibility into the given Text. This method gives users control over allocation of Text objects by copying into the passed in text.
        Parameters:
        cv - Text object to copy into
        Returns:
        the Text that was passed in
      • getColumnVisibilityParsed

        public final ColumnVisibility getColumnVisibilityParsed()
        Gets the column visibility. WARNING: using this method may inhibit performance since a new ColumnVisibility object is created on every call.
        Returns:
        ColumnVisibility representing the column visibility
        Since:
        1.5.0
      • set

        public void set​(Key k)
        Sets this key's row, column family, column qualifier, column visibility, timestamp, and delete marker to be the same as another key's. This method does not copy data from the other key, but only references to it.
        Parameters:
        k - key to set from
      • readFields

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

        public boolean equals​(Key other,
                              PartialKey part)
        Compares part of a key. For example, compares just the row and column family, and if those are equal then return true.
        Parameters:
        other - key to compare to
        part - part of key to compare
        Returns:
        true if specified parts of keys match, false otherwise
      • compareTo

        public int compareTo​(Key other,
                             PartialKey part)
        Compares elements of a key given by a PartialKey. The corresponding elements (row, column family, column qualifier, column visibility, timestamp, and delete marker) are compared in order until unequal elements are found. The row, column family, column qualifier, and column visibility are compared lexicographically and sorted ascending. The timestamps are compared numerically and sorted descending so that the most recent data comes first. Lastly, a delete marker of true sorts before a delete marker of false. The result of the first unequal comparison is returned. For example, for PartialKey.ROW_COLFAM, this method compares just the row and column family. If the row IDs are not equal, return the result of the row comparison; otherwise, returns the result of the column family comparison.
        Parameters:
        other - key to compare to
        part - part of key to compare
        Returns:
        comparison result
        See Also:
        compareTo(Key)
      • hashCode

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

        public static StringBuilder appendPrintableString​(byte[] ba,
                                                          int offset,
                                                          int len,
                                                          int maxLen,
                                                          StringBuilder sb)
        Appends ASCII printable characters to a string, based on the given byte array, treating the bytes as ASCII characters. If a byte can be converted to a ASCII printable character it is appended as is; otherwise, it is appended as a character code, e.g., %05; for byte value 5. If len > maxlen, the string includes a "TRUNCATED" note at the end.
        Parameters:
        ba - byte array
        offset - offset to start with in byte array (inclusive)
        len - number of bytes to print
        maxLen - maximum number of bytes to convert to printable form
        sb - StringBuilder to append to
        Returns:
        given StringBuilder
      • toStringNoTruncate

        public String toStringNoTruncate()
        Stringify this Key, avoiding truncation of each component, only limiting each component to a length of Integer.MAX_VALUE
        Since:
        1.7.0
      • toStringNoTime

        public String toStringNoTime()
        Converts this key to a string, not including timestamp or delete marker.
        Returns:
        string form of key
      • getLength

        public int getLength()
        Returns the sums of the lengths of the row, column family, column qualifier, and column visibility.
        Returns:
        sum of key field lengths
      • getSize

        public int getSize()
        Same as getLength().
        Returns:
        sum of key field lengths
      • compress

        public static List<TKeyValue> compress​(List<? extends KeyValue> param)
        Compresses a list of key/value pairs before sending them via thrift.
        Parameters:
        param - list of key/value pairs
        Returns:
        list of Thrift key/value pairs
      • decompress

        public static void decompress​(List<TKeyValue> param)
        Decompresses a list of key/value pairs received from thrift. Decompression occurs in place, in the list.
        Parameters:
        param - list of Thrift key/value pairs
      • toThrift

        public TKey toThrift()
        Converts this key to Thrift.
        Returns:
        Thrift key