Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created September 15, 2009 18:48
Show Gist options
  • Save kevinpet/187532 to your computer and use it in GitHub Desktop.
Save kevinpet/187532 to your computer and use it in GitHub Desktop.
package org.apache.hadoop.hbase.client.tableindexed;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;
import org.apache.hadoop.hbase.util.Bytes;
/**
* Creates index row keys which exactly match the indexed column. This allows a
* direct get() lookup on the index table, but at the cost that the column
* values must be unique.
*
* If you are indexing a column which can have duplicated values, consider
* {@link SimpleIndexKeyGenerator}.
*/
public class UniqueIndexKeyGenerator implements IndexKeyGenerator {
private byte[] column;
/**
* @param column the column to index
*/
public UniqueIndexKeyGenerator(byte[] column) {
this.column = column;
}
public UniqueIndexKeyGenerator() {
// For Writable
}
/** {@inheritDoc} */
public byte[] createIndexKey(byte[] rowKey, Map<byte[], byte[]> columns) {
return columns.get(column).clone();
}
/** {@inheritDoc} */
public void readFields(DataInput in) throws IOException {
column = Bytes.readByteArray(in);
}
/** {@inheritDoc} */
public void write(DataOutput out) throws IOException {
Bytes.writeByteArray(out, column);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment