On Tue, Nov 3, 2009 at 2:13 PM, Artyom Shvedchikov <[email protected]> wrote:
> Hallo, folks. > > We want to use partial-key lookup and compound keys (search using them) > with > Java API. > Can someone to provide info and example on using such keys and lookups. > > I'm not sure I understand you correctly, but partial key is fine as long as you are using a prefix. For example, if your key consists of account:timestamp:event_id, you would need to make sure that all these values are fixed width -- make account id an int, not a string, same thing with timestamp. To build your keys do something like byte[] row = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time), Bytes.toBytes(eventId)) Then to get all rows matching a given account and timestamp, do byte[] startRow = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time)); byte[] endRow = Bytes.add(Bytes.toBytes(acctId), Bytes.toBytes(time + 1)); ResultScanner scanner = table.getScanner(new Scan(startRow, endRow)); If you want to search by something that isn't a prefix of your row key, then you will need to either user a scanner filter or look into table indexed.
