Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set TTL for a column family in HBase using shell and using Java API

Tags:

java

apache

hbase

I am new to HBase and I have searched at my end but I am unable to find a simple and straight forward way to set TTL attribute in a column family in HBase. Please specify both ways using shell and using Java API.

like image 741
Pranjal Sahu Avatar asked Mar 29 '15 16:03

Pranjal Sahu


People also ask

How does TTL work in HBase?

You can set ColumnFamilies a TTL length in seconds, and HBase will automatically delete rows or automatically expires the row once the expiration time is reached. This setting applies to all versions of a row in that table– even the current one. The TTL time encoded in the HBase for the row is specified in UTC.

How do I run a HBase command from the shell?

To access the HBase shell, you have to navigate to the HBase home folder. You can start the HBase interactive shell using “hbase shell” command as shown below. If you have successfully installed HBase in your system, then it gives you the HBase shell prompt as shown below.

How do I create a column family in HBase?

Simply press the "+" button in the "Alter table" page and add your new column family with all settings you need.

What is column family in HBase?

An HBase table contains column families , which are the logical and physical grouping of columns. There are column qualifiers inside of a column family, which are the columns. Column families contain columns with time stamped versions. Columns only exist when they are inserted, which makes HBase a sparse database.


1 Answers

Using the Java API:

HColumnDescriptor cfDescriptor = new HColumnDescriptor(Bytes.toBytes("cfName"));
cfDescriptor.setTimeToLive(20); // in seconds

tableDesc.addFamily(cfDescriptor);
admin.createTable(tableDesc);

And using shell:

alter ‘tableName′, NAME => ‘cfname′, TTL => 20
like image 75
Sleiman Jneidi Avatar answered Oct 19 '22 11:10

Sleiman Jneidi