I recently had to do something similar both programmatically in a unit
test and from the hbase shell.  I'm not using an index, but this is
probably similar to what you're doing:

HTableDescriptor table = new HTableDescriptor("tableName");
HColumnDescriptor column = new HColumnDescriptor("columnFamily");
column.setMaxVersions(1);       // Limits versions to 1
table.addFamily(column);

HBaseAdmin hBaseAdmin = new HBaseAdmin(...);
hBaseAdmin.createTable(table);


>From the hbase shell:

create 'tableName', {NAME=>'columnFamily', VERSIONS=>1}

Hope this helps.

-James


On Wed, 2010-01-27 at 19:24 -0600, [email protected] wrote:
> Hi,
> 
>   Following code is I got used to create table with index.
>   Now, I think it's no need for us to keep multiple version of data.
>   How can I set my hbase table only to keep one version of data?
>   Better to give me some codes that I can add to my following function.
>   Thanks
> 
>   public void createTableWithIdx(String tablename,String
> columnfamily,String idx_columnfamily,String idx_column) throws IOException
> {
>         HTableDescriptor desc = new HTableDescriptor(tablename);
>         String[] temp;
>             String delimiter = ",";
>             temp = columnfamily.split(delimiter);
>             for(int i =0; i < temp.length ; i++){
>                   desc.addFamily(new HColumnDescriptor(temp[i]));
>             }
>         IndexedTableDescriptor idx_desc = new IndexedTableDescriptor(desc);
>         idx_desc.addIndex(new IndexSpecification(idx_column,
>                           Bytes.toBytes(idx_columnfamily+":"+idx_column)));
>         IndexedTableAdmin admin = null;
>         admin = new IndexedTableAdmin(config);
>         admin.createIndexedTable(idx_desc);
>         System.out.println(tablename+" "+" create table and index
> successfully");
>     }
> 
> 
> 
> 
> Fleming Chiu(邱宏明)
> 707-6128
> [email protected]
> 週一無肉日吃素救地球(Meat Free Monday Taiwan)
> 
> 
>  --------------------------------------------------------------------------- 
>                                                          TSMC PROPERTY       
>  This email communication (and any attachments) is proprietary information   
>  for the sole use of its                                                     
>  intended recipient. Any unauthorized review, use or distribution by anyone  
>  other than the intended                                                     
>  recipient is strictly prohibited.  If you are not the intended recipient,   
>  please notify the sender by                                                 
>  replying to this email, and then delete this email and any copies of it     
>  immediately. Thank you.                                                     
>  --------------------------------------------------------------------------- 
> 
> 
> 

Reply via email to