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.
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.
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.
Simply press the "+" button in the "Alter table" page and add your new column family with all settings you need.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With