Friday, May 16, 2014

How to convert Hbase table's TTL from epoch time to date

Hbase table is using epoch time as TTL(Time to Live) in milliseconds.
Here are 2 ways to convert it to readable time.

For example:
hbase(main):018:0> describe 't1'
DESCRIPTION                                                                                               ENABLED
 't1', {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VER true
 SIONS => '5', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'fa
 lse', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}
1 row(s) in 0.0410 seconds

1. hbase shell:

hbase(main):019:0> import java.util.Date
=> Java::JavaUtil::Date

hbase(main):024:0> Date.new(2147483647*1000).toString()
=> "Mon Jan 18 19:14:07 PST 2038"

2. python

>>> import time
>>> time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(2147483647))
'2038-01-18 19:14:07'

1 comment:

  1. AnyConv is dedicated to helping you transform your songs, videos, images and documents into different formats. AnyConv.com provides you to 100% free online file converter tool. Not need to any download and install on your computer, the whole process is online. https://anyconv.com/

    ReplyDelete

Popular Posts