HBASE-5548 Add ability to get a table in the shell; ADDENDUM
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1332766 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
49db96433d
commit
8152b444ef
|
@ -134,7 +134,7 @@ EOF
|
|||
#----------------------------------------------------------------------------------------------
|
||||
# Delete a cell
|
||||
def _delete_internal(row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
|
||||
deleteall_internal(row, column, timestamp)
|
||||
_deleteall_internal(row, column, timestamp)
|
||||
end
|
||||
|
||||
#----------------------------------------------------------------------------------------------
|
||||
|
@ -432,8 +432,6 @@ EOF
|
|||
|
||||
#----------------------------------------------------------------------------------------
|
||||
# Helper methods
|
||||
#everthing below here is 'private' - can only be called from within the class context
|
||||
private
|
||||
|
||||
# Returns a list of column names in the table
|
||||
def get_all_columns
|
||||
|
|
|
@ -45,7 +45,7 @@ EOF
|
|||
|
||||
def deleteall(table, row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP)
|
||||
format_simple_command do
|
||||
table.deleteall_internal(row, column, timestamp)
|
||||
table._deleteall_internal(row, column, timestamp)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,8 @@ EOF
|
|||
def command(table, row, column, value)
|
||||
get_counter(table(table), row, column, value)
|
||||
end
|
||||
def command(table, row, column, value = nil)
|
||||
|
||||
def get_counter(table, row, column, value = nil)
|
||||
if cnt = table._get_counter_internal(row, column)
|
||||
puts "COUNTER VALUE = #{cnt}"
|
||||
else
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'shell'
|
||||
require 'shell/formatter'
|
||||
require 'hbase'
|
||||
require 'hbase/hbase'
|
||||
require 'hbase/table'
|
||||
|
||||
include HBaseConstants
|
||||
|
||||
|
@ -186,10 +190,10 @@ module Hbase
|
|||
define_test "truncate should empty a table" do
|
||||
table(@test_name).put(1, "x:a", 1)
|
||||
table(@test_name).put(2, "x:a", 2)
|
||||
assert_equal(2, table(@test_name).count)
|
||||
assert_equal(2, table(@test_name)._count_internal)
|
||||
# This is hacky. Need to get the configuration into admin instance
|
||||
admin.truncate(@test_name, $TEST_CLUSTER.getConfiguration)
|
||||
assert_equal(0, table(@test_name).count)
|
||||
assert_equal(0, table(@test_name)._count_internal)
|
||||
end
|
||||
|
||||
define_test "truncate should yield log records" do
|
||||
|
|
|
@ -166,11 +166,11 @@ module Hbase
|
|||
|
||||
define_test "get_counter should work with integer keys" do
|
||||
@test_table.incr(12345, 'x:cnt')
|
||||
assert_kind_of(Fixnum, @test_table.get_counter(12345, 'x:cnt'))
|
||||
assert_kind_of(Fixnum, @test_table._get_counter_internal(12345, 'x:cnt'))
|
||||
end
|
||||
|
||||
define_test "get_counter should return nil for non-existent counters" do
|
||||
assert_nil(@test_table.get_counter(12345, 'x:qqqq'))
|
||||
assert_nil(@test_table._get_counter_internal(12345, 'x:qqqq'))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -185,7 +185,7 @@ module Hbase
|
|||
create_test_table(@test_name)
|
||||
@test_table = table(@test_name)
|
||||
|
||||
# Test data
|
||||
# Instert test data
|
||||
@test_ts = 12345678
|
||||
@test_table.put(1, "x:a", 1)
|
||||
@test_table.put(1, "x:b", 2, @test_ts)
|
||||
|
@ -195,12 +195,12 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "count should work w/o a block passed" do
|
||||
assert(@test_table.count > 0)
|
||||
assert(@test_table._count_internal > 0)
|
||||
end
|
||||
|
||||
define_test "count should work with a block passed (and yield)" do
|
||||
rows = []
|
||||
cnt = @test_table.count(1) do |cnt, row|
|
||||
cnt = @test_table._count_internal(1) do |cnt, row|
|
||||
rows << row
|
||||
end
|
||||
assert(cnt > 0)
|
||||
|
@ -210,7 +210,7 @@ module Hbase
|
|||
#-------------------------------------------------------------------------------
|
||||
|
||||
define_test "get should work w/o columns specification" do
|
||||
res = @test_table.get('1')
|
||||
res = @test_table._get_internal('1')
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -218,7 +218,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with integer keys" do
|
||||
res = @test_table.get(1)
|
||||
res = @test_table._get_internal(1)
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -226,7 +226,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with hash columns spec and a single string COLUMN parameter" do
|
||||
res = @test_table.get('1', COLUMN => 'x:a')
|
||||
res = @test_table._get_internal('1', COLUMN => 'x:a')
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -234,7 +234,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with hash columns spec and a single string COLUMNS parameter" do
|
||||
res = @test_table.get('1', COLUMNS => 'x:a')
|
||||
res = @test_table._get_internal('1', COLUMNS => 'x:a')
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -242,7 +242,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with hash columns spec and an array of strings COLUMN parameter" do
|
||||
res = @test_table.get('1', COLUMN => [ 'x:a', 'x:b' ])
|
||||
res = @test_table._get_internal('1', COLUMN => [ 'x:a', 'x:b' ])
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -250,7 +250,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with hash columns spec and an array of strings COLUMNS parameter" do
|
||||
res = @test_table.get('1', COLUMNS => [ 'x:a', 'x:b' ])
|
||||
res = @test_table._get_internal('1', COLUMNS => [ 'x:a', 'x:b' ])
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -258,7 +258,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with hash columns spec and TIMESTAMP only" do
|
||||
res = @test_table.get('1', TIMESTAMP => @test_ts)
|
||||
res = @test_table._get_internal('1', TIMESTAMP => @test_ts)
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_nil(res['x:a'])
|
||||
|
@ -267,24 +267,24 @@ module Hbase
|
|||
|
||||
define_test "get should fail with hash columns spec and strange COLUMN value" do
|
||||
assert_raise(ArgumentError) do
|
||||
@test_table.get('1', COLUMN => {})
|
||||
@test_table._get_internal('1', COLUMN => {})
|
||||
end
|
||||
end
|
||||
|
||||
define_test "get should fail with hash columns spec and strange COLUMNS value" do
|
||||
assert_raise(ArgumentError) do
|
||||
@test_table.get('1', COLUMN => {})
|
||||
@test_table._get_internal('1', COLUMN => {})
|
||||
end
|
||||
end
|
||||
|
||||
define_test "get should fail with hash columns spec and no TIMESTAMP or COLUMN[S]" do
|
||||
assert_raise(ArgumentError) do
|
||||
@test_table.get('1', { :foo => :bar })
|
||||
@test_table._get_internal('1', { :foo => :bar })
|
||||
end
|
||||
end
|
||||
|
||||
define_test "get should work with a string column spec" do
|
||||
res = @test_table.get('1', 'x:b')
|
||||
res = @test_table._get_internal('1', 'x:b')
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_nil(res['x:a'])
|
||||
|
@ -292,7 +292,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with an array columns spec" do
|
||||
res = @test_table.get('1', 'x:a', 'x:b')
|
||||
res = @test_table._get_internal('1', 'x:a', 'x:b')
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -300,7 +300,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "get should work with an array or arrays columns spec (yeah, crazy)" do
|
||||
res = @test_table.get('1', ['x:a'], ['x:b'])
|
||||
res = @test_table._get_internal('1', ['x:a'], ['x:b'])
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['x:a'])
|
||||
|
@ -309,14 +309,14 @@ module Hbase
|
|||
|
||||
define_test "get with a block should yield (column, value) pairs" do
|
||||
res = {}
|
||||
@test_table.get('1') { |col, val| res[col] = val }
|
||||
@test_table._get_internal('1') { |col, val| res[col] = val }
|
||||
assert_equal(res.keys.sort, [ 'x:a', 'x:b' ])
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
define_test "scan should work w/o any params" do
|
||||
res = @test_table.scan
|
||||
res = @test_table._scan_internal
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -328,7 +328,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support STARTROW parameter" do
|
||||
res = @test_table.scan STARTROW => '2'
|
||||
res = @test_table._scan_internal STARTROW => '2'
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_nil(res['1'])
|
||||
|
@ -338,7 +338,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support STOPROW parameter" do
|
||||
res = @test_table.scan STOPROW => '2'
|
||||
res = @test_table._scan_internal STOPROW => '2'
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -348,7 +348,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support LIMIT parameter" do
|
||||
res = @test_table.scan LIMIT => 1
|
||||
res = @test_table._scan_internal LIMIT => 1
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -358,7 +358,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support TIMESTAMP parameter" do
|
||||
res = @test_table.scan TIMESTAMP => @test_ts
|
||||
res = @test_table._scan_internal TIMESTAMP => @test_ts
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -370,7 +370,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support TIMERANGE parameter" do
|
||||
res = @test_table.scan TIMERANGE => [0, 1]
|
||||
res = @test_table._scan_internal TIMERANGE => [0, 1]
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_nil(res['1'])
|
||||
|
@ -378,7 +378,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support COLUMNS parameter with an array of columns" do
|
||||
res = @test_table.scan COLUMNS => [ 'x:a', 'x:b' ]
|
||||
res = @test_table._scan_internal COLUMNS => [ 'x:a', 'x:b' ]
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -390,7 +390,7 @@ module Hbase
|
|||
end
|
||||
|
||||
define_test "scan should support COLUMNS parameter with a single column name" do
|
||||
res = @test_table.scan COLUMNS => 'x:a'
|
||||
res = @test_table._scan_internal COLUMNS => 'x:a'
|
||||
assert_not_nil(res)
|
||||
assert_kind_of(Hash, res)
|
||||
assert_not_nil(res['1'])
|
||||
|
@ -403,19 +403,19 @@ module Hbase
|
|||
|
||||
define_test "scan should fail on invalid COLUMNS parameter types" do
|
||||
assert_raise(ArgumentError) do
|
||||
@test_table.scan COLUMNS => {}
|
||||
@test_table._scan_internal COLUMNS => {}
|
||||
end
|
||||
end
|
||||
|
||||
define_test "scan should fail on non-hash params" do
|
||||
assert_raise(ArgumentError) do
|
||||
@test_table.scan 123
|
||||
@test_table._scan_internal 123
|
||||
end
|
||||
end
|
||||
|
||||
define_test "scan with a block should yield rows and return rows counter" do
|
||||
rows = {}
|
||||
res = @test_table.scan { |row, cells| rows[row] = cells }
|
||||
res = @test_table._scan_internal { |row, cells| rows[row] = cells }
|
||||
assert_equal(rows.keys.size, res)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,8 +18,9 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'hbase'
|
||||
require 'hbase/table'
|
||||
require 'shell'
|
||||
require 'shell/formatter'
|
||||
|
||||
class ShellCommandsTest < Test::Unit::TestCase
|
||||
Shell.commands.each do |name, klass|
|
||||
|
|
|
@ -37,17 +37,23 @@ end
|
|||
|
||||
module Hbase
|
||||
module TestHelpers
|
||||
require 'hbase'
|
||||
require 'hbase/hbase'
|
||||
require 'shell'
|
||||
require 'shell/formatter'
|
||||
|
||||
def setup_hbase
|
||||
@formatter = Shell::Formatter::Console.new()
|
||||
@hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
|
||||
formatter = ::Shell::Formatter::Console.new
|
||||
hbase = ::Hbase::Hbase.new($TEST_CLUSTER.getConfiguration)
|
||||
@shell = ::Shell::Shell.new(hbase, formatter)
|
||||
end
|
||||
|
||||
def table(table)
|
||||
@hbase.table(table, @formatter)
|
||||
@shell.hbase_table(table)
|
||||
end
|
||||
|
||||
def admin
|
||||
@hbase.admin(@formatter)
|
||||
@shell.hbase_admin
|
||||
end
|
||||
|
||||
def create_test_table(name)
|
||||
|
|
Loading…
Reference in New Issue