[
https://issues.apache.org/jira/browse/HBASE-7221?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13589713#comment-13589713
]
Doug Meil commented on HBASE-7221:
----------------------------------
I must say that the class names in HBASE-7692 are similar to those in
HBASE-7221, which isn’t entirely surprising because HBASE-7221 is the ticket
that started this whole rowkey construction conversation in the first place.
StructRowKey (7692) is basically a RowKeySchema (7221). And 7692 also has
similar sounding-class names: BigDecimalRowKey, IntWritableRowKey, LongRowKey,
LongWritableRowKey.
But I think that 7692 is mixing terms and is harder to use and understand.
7221 refers to a RowKey as the “whole key” (e.g., 7221’s FixedLengthRowKey)
which is consistent with that usage in HBase, whereas a part of a RowKey in
7221 is called a RowKeyElement. To constrast 7692's classnames, is
BigDecimalRowKey the whole thing? Or a part of the rowkey?
The hashing, while it can be added to 7692, was designed in from the get-go
with 7221 because that’s the way we recommend folks to build keys. Lars/Ian,
as you pointed out earlier in this ticket there is a reason that you found the
7221 approach familiar even in the first approach - because it’s similar to
what you did internally.
Personally, I think this the 7221 approach is easier to understand and use, and
still has safety-nets built-in for length testing on setters.
{code}
RowKeySchema schema = new RowKeySchema.Builder()
.add(RowKeySchema.MD5_HASH)
.add(RowKeySchema.INT)
.add(RowKeySchema.LONG)
.add(RowKeySchema.BYTE)
.add(new RowKeyBytesElement(bytesVal.length))
.build();
FixedLengthRowKey rowkey = schema.createFixedLengthRowKey();
rowkey.setInt(0, hashVal); // this will hash the int because the schema
definition says so.
rowkey.setInt(1, intVal);
rowkey.setLong(2, longVal);
rowkey.setByte(3, byteVal);
rowkey.setBytes(4, bytesVal);
byte bytes[] = rowkey.getBytes();
{code}
I would like to point out that I like that 7692 already has variable-length key
support (e.g., if folks use URLs inside of keys). That would need a class
called VariableLengthRowKey to support that with the RowKeySchema approach
(another patch).
> RowKey utility class for rowkey construction
> --------------------------------------------
>
> Key: HBASE-7221
> URL: https://issues.apache.org/jira/browse/HBASE-7221
> Project: HBase
> Issue Type: Improvement
> Components: util
> Reporter: Doug Meil
> Assignee: Doug Meil
> Priority: Minor
> Attachments: HBASE_7221.patch, hbase-common_hbase_7221_2.patch,
> hbase-common_hbase_7221_v3.patch, hbase-common_hbase_7221_v4.patch,
> hbase-server_hbase_7221_v5.patch, hbase-server_hbase_7221_v6.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