From 44f1b745ce521161e2edba37eb2ed132c641e5ad Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Wed, 29 Oct 2014 17:46:19 -0700 Subject: [PATCH] HBASE-11775 Shell support for per cell TTLs --- hbase-shell/src/main/ruby/hbase/table.rb | 24 +++++++++++++++++------- hbase-shell/src/test/ruby/hbase/table_test.rb | 13 +++++++++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index f02ba81..07a850d 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -136,17 +136,19 @@ EOF set_attributes(p, attributes) if attributes visibility = args[VISIBILITY] set_cell_visibility(p, visibility) if visibility + ttl = args[TTL] + set_op_ttl(p, ttl) if ttl end #Case where attributes are specified without timestamp if timestamp.kind_of?(Hash) timestamp.each do |k, v| - if v.kind_of?(Hash) - set_attributes(p, v) if v - end - if v.kind_of?(String) - set_cell_visibility(p, v) if v - end - + if k == 'ATTRIBUTES' + set_attributes(p, v) + elsif k == 'VISIBILITY' + set_cell_visibility(p, v) + elsif k == "TTL" + set_op_ttl(p, v) + end end timestamp = nil end @@ -214,6 +216,8 @@ EOF visibility = args[VISIBILITY] set_attributes(incr, attributes) if attributes set_cell_visibility(incr, visibility) if visibility + ttl = args[TTL] + set_op_ttl(incr, ttl) if ttl end incr.addColumn(family, qualifier, value) @table.increment(incr) @@ -232,6 +236,8 @@ EOF visibility = args[VISIBILITY] set_attributes(append, attributes) if attributes set_cell_visibility(append, visibility) if visibility + ttl = args[TTL] + set_op_ttl(append, ttl) if ttl end append.add(family, qualifier, value.to_s.to_java_bytes) @table.append(append) @@ -540,6 +546,10 @@ EOF auths.to_java(:string))) end + def set_op_ttl(op, ttl) + op.setTTL(ttl.to_java(:long)) + end + #---------------------------- # Add general administration utilities to the shell # each of the names below adds this method name to the table diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index 7272229..fa2990d 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -530,5 +530,18 @@ module Hbase end end + define_test "mutation with TTL should expire" do + @test_table.put('ttlTest', 'x:a', 'foo', { TTL => 1000 } ) + begin + res = @test_table._get_internal('ttlTest', 'x:a') + assert_not_nil(res) + sleep 2 + res = @test_table._get_internal('ttlTest', 'x:a') + assert_nil(res) + ensure + @test_table.delete('ttlTest', 'x:a') + end + end + end end -- 1.7.12.4 (Apple Git-37)