You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by "Doug Meil (JIRA)" <ji...@apache.org> on 2012/12/03 16:11:59 UTC

[jira] [Updated] (HBASE-7221) RowKey utility class for rowkey construction

     [ https://issues.apache.org/jira/browse/HBASE-7221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Doug Meil updated HBASE-7221:
-----------------------------

    Attachment: hbase-common_hbase_7221_v3.patch

Ok, I think this one's a winner.  :-)

There is a RowKeySchema and a RowKey.  This creates fixed-length keys without delimiters (generally considered to be a best practice), and enforces the defined lengths when the elements are set.  It's also bi-directional, so that you can pass in a byte-array (i.e., rowkey) from a table and then read the key elements back.

Creation example...
{code}
    int elements[] = {RowKeySchema.SIZEOF_MD5_HASH, RowKeySchema.SIZEOF_INT, RowKeySchema.SIZEOF_LONG};
    RowKeySchema schema = new RowKeySchema(elements);
    
    RowKey rowkey = schema.createRowKey();
    rowkey.setHash(0, hashVal);
    rowkey.setInt(1, intVal);
    rowkey.setLong(2, longVal);
	  
    byte bytes[] = rowkey.getBytes();

{code}
                
> RowKey utility class for rowkey construction
> --------------------------------------------
>
>                 Key: HBASE-7221
>                 URL: https://issues.apache.org/jira/browse/HBASE-7221
>             Project: HBase
>          Issue Type: Improvement
>            Reporter: Doug Meil
>            Assignee: Doug Meil
>            Priority: Minor
>         Attachments: HBASE_7221.patch, hbase-common_hbase_7221_2.patch, hbase-common_hbase_7221_v3.patch
>
>
> A common question in the dist-lists is how to construct rowkeys, particularly composite keys.  Put/Get/Scan specifies byte[] as the rowkey, but it's up to you to sensibly populate that byte-array, and that's where things tend to go off the rails.
> The intent of this RowKey utility class isn't meant to add functionality into Put/Get/Scan, but rather make it simpler for folks to construct said arrays.  Example:
> {code}
>    RowKey key = RowKey.create(RowKey.SIZEOF_MD5_HASH + RowKey.SIZEOF_LONG);
>    key.addHash(a);
>    key.add(b);
>    byte bytes[] = key.getBytes();
> {code} 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira