hbase-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nick Dimiduk (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HBASE-7221) RowKey utility class for rowkey construction
Date Wed, 23 Jan 2013 03:18:16 GMT

    [ https://issues.apache.org/jira/browse/HBASE-7221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13560356#comment-13560356
] 

Nick Dimiduk commented on HBASE-7221:
-------------------------------------

I very much agree HBase should provide a canonical tool for building things like compound
byte-arrays. Overall, I don't like the idea of a stateful utility class, so -1.

This would be much more elegant (and less bug-prone) via a static method and an approach similar
to the format-string style. The major down-side being you'd need a mini-language for representing
these formats. The example in your class header, under this approach, would something like
{{byte[] key = RowKey.format("%16x%4d%8d", hashVal, intVal, longVal);}}. With a {{Formatter}}
implemented, you could have an accessor static method, call it {{split}}, that behaved similarly,
ie {{byte[][] splits = RowKey.split("%16x%4d%8d", key);}}. The key idea here being the format
and split strings are of identical form. Then the consumer can decide how to re-interpret
the splits. Or maybe you get fancy with out-parameters or something, but that doesn't seem
idiomatic.

general nit: your line-lengths are well past 100 characters in some cases.

{code}
 * A stateful utility class for creating rowkeys for HBase tables, particularly composite
keys.  RowKey
 * creates fixed length keys without the need for delimeters in between key elements (i.e.,
parts of the 
 * rowkey), which is a best practice in HBase.  A RowKey instance is instantiated from an
associated RowKeySchema, 
{code}

nit: s/delimeters/delimiters

nit: RowKeySchema has superfluous imports.

nit: TestRowKey has superfluous imports.

{code}
    boolean passed = true;
    try {
      RowKey rowkey = schema.createRowKey();
      rowkey.setHash(1, intVal);  // trying to set 'int' on an element that is sized for a
hash.
    } catch (Exception e) {
	    // we are expecting a sizing exception because we are setting a hash onto an element
	    // sized for an int.
	    passed = false;
    }
    if (passed) {
      Assert.fail("Test did not fail!");
     }
{code}

nit: forego this {{passed}} business and put your assert right inline.
                
> 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

Mime
View raw message