HBASE-883 Secondary indexes; fixes

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@718820 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2008-11-19 00:43:01 +00:00
parent 3407263f66
commit ddc345efa6
6 changed files with 10 additions and 34 deletions

View File

@ -69,8 +69,6 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
new ImmutableBytesWritable(Bytes.toBytes(IS_ROOT));
public static final String IS_META = "IS_META";
public static final String ROW_KEY_COMPARATOR = "ROW_KEY_COMPARATOR";
public static final ImmutableBytesWritable IS_META_KEY =
new ImmutableBytesWritable(Bytes.toBytes(IS_META));

View File

@ -26,6 +26,8 @@ import java.io.IOException;
*/
public class IndexNotFoundException extends IOException {
private static final long serialVersionUID = 6533971528557000965L;
public IndexNotFoundException() {
super();
}

View File

@ -24,11 +24,9 @@ import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.WritableComparator;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.ObjectWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.io.WritableComparable;
/** Holds the specification for a single secondary index. */
public class IndexSpecification implements Writable {
@ -39,8 +37,6 @@ public class IndexSpecification implements Writable {
// Constructs the
private IndexKeyGenerator keyGenerator;
private WritableComparator<byte[]> keyComparator;
// Additional columns mapped into the indexed row. These will be available for
// filters when scanning the index.
private byte[][] additionalColumns;
@ -51,11 +47,9 @@ public class IndexSpecification implements Writable {
private String indexId;
/** Construct an "simple" index spec for a single column. */
public IndexSpecification(String indexId, byte[] indexedColumn,
boolean acending) {
public IndexSpecification(String indexId, byte[] indexedColumn) {
this(indexId, new byte[][] { indexedColumn }, null,
new SimpleIndexKeyGenerator(indexedColumn), acending == true ? null
: new ReverseByteArrayComparator());
new SimpleIndexKeyGenerator(indexedColumn));
}
/**
@ -68,13 +62,11 @@ public class IndexSpecification implements Writable {
* @param keyComparator
*/
public IndexSpecification(String indexId, byte[][] indexedColumns,
byte[][] additionalColumns, IndexKeyGenerator keyGenerator,
WritableComparator<byte[]> keyComparator) {
byte[][] additionalColumns, IndexKeyGenerator keyGenerator) {
this.indexId = indexId;
this.indexedColumns = indexedColumns;
this.additionalColumns = additionalColumns;
this.keyGenerator = keyGenerator;
this.keyComparator = keyComparator;
this.makeAllColumns();
}
@ -110,15 +102,6 @@ public class IndexSpecification implements Writable {
return keyGenerator;
}
/**
* Get the keyComparator.
*
* @return Return the keyComparator.
*/
public WritableComparator<byte[]> getKeyComparator() {
return keyComparator;
}
/**
* Get the additionalColumns.
*
@ -171,8 +154,6 @@ public class IndexSpecification implements Writable {
makeAllColumns();
HBaseConfiguration conf = new HBaseConfiguration();
keyGenerator = (IndexKeyGenerator) ObjectWritable.readObject(in, conf);
keyComparator = (WritableComparator<byte[]>) ObjectWritable.readObject(in,
conf);
}
/** {@inheritDoc} */
@ -193,8 +174,6 @@ public class IndexSpecification implements Writable {
HBaseConfiguration conf = new HBaseConfiguration();
ObjectWritable
.writeObject(out, keyGenerator, IndexKeyGenerator.class, conf);
ObjectWritable.writeObject(out, keyComparator, WritableComparable.class,
conf);
}
}

View File

@ -92,8 +92,6 @@ public class IndexedTableAdmin extends HBaseAdmin {
indexTableDesc.addFamily(new HColumnDescriptor(colFamily));
}
indexTableDesc.setRowKeyComparator(indexSpec.getKeyComparator());
return indexTableDesc;
}
}

View File

@ -26,9 +26,8 @@ This package provides support for secondary indexing by maintaining a separate,
The IndexSpecification class provides the metadata for the index. This includes:
<li> the columns that contribute to the index key,
<li> additional columns to put in the index table (and are thus made available to filters on the index table),
<li> an IndexKeyGenerator which constructs the index-row-key from the indexed column(s) and the original row,
<br> and
<li> (optionally) a custom key comparator for the indexed table. This can allow an index on a deserialized column value.
<li> an IndexKeyGenerator which constructs the index-row-key from the indexed column(s) and the original row.
IndexesSpecifications can be added to a table's metadata (HTableDescriptor) before the table is constructed.
Afterwards, updates and deletes to the original table will trigger the updates in the index, and

View File

@ -45,7 +45,7 @@ public class TestIndexedTable extends HBaseClusterTestCase {
private static final byte[] FAMILY = Bytes.toBytes("family:");
private static final byte[] COL_A = Bytes.toBytes("family:a");
private static final String INDEX_COL_A_ASC = "A-Acending";
private static final String INDEX_COL_A = "A";
private static final int NUM_ROWS = 10;
private static final int MAX_VAL = 10000;
@ -70,8 +70,8 @@ public class TestIndexedTable extends HBaseClusterTestCase {
desc.addFamily(new HColumnDescriptor(FAMILY));
// Create a new index that does lexicographic ordering on COL_A
IndexSpecification colAIndex = new IndexSpecification(INDEX_COL_A_ASC,
COL_A, true);
IndexSpecification colAIndex = new IndexSpecification(INDEX_COL_A,
COL_A);
desc.addIndex(colAIndex);
admin = new IndexedTableAdmin(conf);
@ -97,7 +97,7 @@ public class TestIndexedTable extends HBaseClusterTestCase {
}
private void assertRowsInOrder(int numRowsExpected) throws IndexNotFoundException, IOException {
Scanner scanner = table.getIndexedScanner(INDEX_COL_A_ASC,
Scanner scanner = table.getIndexedScanner(INDEX_COL_A,
HConstants.EMPTY_START_ROW, null, null, null);
int numRows = 0;
byte[] lastColA = null;