First of all, the NPE comes from the fact that the SimpleIndexKeyGenerator.java 
needs to be initialized with the column to use in the index.
The default no-arg constructor is unfortunately exposed publicly for the 
purpose of serialization.

Second, why are you even calling keyGen.createIndexKey? It will be called 
internally as needed at index construction time.

Third, SimpleIndexKeyGenerator is designed to generate an index key using the 
single value of the column given in its constructor. It also suffixes that with 
the original row key. However, to index multiple columns as you suggest you'll 
have to implement your own IndexKeyGenerator implementation that builds the key 
out of multiple column values.  Note that the createIndexKey should be better 
documented. The input "columns" are specific column values so with the rowKey 
you should have everything you need to construct the new key.

> ---------- Forwarded message ----------
> From: Michelan Arendse <[email protected]>
> Date: Mon, Jun 7, 2010 at 3:09 AM
> Subject: Indexing on Multiple Columns
> To: "[email protected]" <[email protected]>
> 
> 
> Hi.
> 
> I am having trouble indexing multiple columns in hbase.
> This is my code:
> IndexKeyGenerator keyGen = new SimpleIndexKeyGenerator();
> 
>                  Map <byte[], byte[]> indexColumnsMap = new
> HashMap<byte[], byte[]>();
> 
>                  for ( int x =0; x < columns.length; x++)
>                        indexColumnsMap.put(Bytes.toBytes(x),
> Bytes.toBytes(columns[x]));
> 
>                  keyGen.createIndexKey(Bytes.toBytes(tableName+
> "IndexKey") , indexColumnsMap); // Problem lies here.
>                  hbAdmin.addIndex(Bytes.toBytes(tableName), new
> IndexSpecification(tableName + "Index", Bytes.toByteArrays(columns),
> null, keyGen ));
> 
> I am able to index the tables in hbase, but when I want to index the
> table on multiple columns I get the following error:
> Exception in thread "main" java.lang.NullPointerException
>      at org.apache.hadoop.hbase.util.Bytes.add(Bytes.java:1131)
>      at org.apache.hadoop.hbase.util.Bytes.add(Bytes.java:1121)
>      at 
> org.apache.hadoop.hbase.client.tableindexed.SimpleIndexKeyGenerator.createIndexKey(SimpleIndexKeyGenerator.java:46)
> 
> I read that SimpleIndexKeyGenerator is  used for single columns. If
> this is so please advise me on using another way of indexing the
> tables on multiple columns.
> 
> Thank you,
> 
> Michelan Arendse
> Junior Developer | AD:DYNAMO // happy business ;-)
> Office 0861 Dynamo (0861 396266)  | Fax +27 (0) 21 465 2587
> 
> Advertise Online Instantly - www.addynamo.com<http://www.addynamo.com>
> <http://www.addynamo.com>

Reply via email to