Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 330 additions & 77 deletions hbase-shell/src/main/ruby/hbase/table.rb

Large diffs are not rendered by default.

48 changes: 43 additions & 5 deletions hbase-shell/src/main/ruby/shell/commands/append.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,56 @@ def help

hbase> t.append 'r1', 'c1', 'value', ATTRIBUTES=>{'mykey'=>'myvalue'}
hbase> t.append 'r1', 'c1', 'value', {VISIBILITY=>'PRIVATE|SECRET'}

Alternately, we can run the following commands for appending cell values for
multiple columns at specified table/row coordinates.

hbase> append 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> append 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, {VISIBILITY=>'PRIVATE|SECRET'}

The same commands also can be run on a table reference.

hbase> t.append 'r1', {'c1'=>'value1', 'c2'=>'value2'}, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> t.append 'r1', {'c1'=>'value1', 'c2'=>'value2'}, {VISIBILITY=>'PRIVATE|SECRET'}

EOF
end

def command(table_name, row, column, value, args = {})
# Executes an append command on a specified table.
#
# @param table_name [String] The name of the table
# @param row [String] The row key
# @param column [String, Hash] The column name or a hash of column names and values
# @param value [String, Hash] The value to append or a hash of column names and values
# @param args [Hash] optional arguments
def command(table_name, row, column, value = value_omitted = {}, args = args_omitted = {})
table = table(table_name)
@start_time = Time.now
append(table, row, column, value, args)
# Conditional block to omit passing optional arguments explicitly
if !value_omitted.nil?
# value field was not passed (will reach only for multi column append)
append(table, row, column)
elsif !args_omitted.nil?
# args field was not passed (must not be passed for multi column append)
append(table, row, column, value)
else
append(table, row, column, value, args)
end
end

def append(table, row, column, value, args = {})
if current_value = table._append_internal(row, column, value, args)
puts "CURRENT VALUE = #{current_value}"
def append(table, row, column, value = value_omitted = {}, args = args_omitted = {})
if column.is_a?(Hash)
# args field must not be passed; already contained in value field
raise(ArgumentError, 'wrong number of arguments') if args_omitted.nil?
if current_values = table._append_multi_column_internal(row, column, value)
puts "CURRENT VALUES = #{current_values}"
end
else
# value field must be passed by user
raise(ArgumentError, 'wrong number of arguments') unless value_omitted.nil?
if current_value = table._append_internal(row, column, value, args)
puts "CURRENT VALUE = #{current_value}"
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions hbase-shell/src/main/ruby/shell/commands/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def help

hbase> t.delete 'r1', 'c1', ts1
hbase> t.delete 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}

Alternately, we can put delete cell values for multiple columns at specified table/row and
optionally timestamp coordinates.

hbase> delete 'ns1:t1', 'r1', ['c1', 'c2'], ts1
hbase> delete 't1', 'r1', ['c1', 'c2'], ts1
hbase> delete 't1', 'r1', ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}

The same command can also be run on a table reference.

hbase> t.delete 'r1', ['c1', 'c2'], ts1
hbase> t.delete 'r1', ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}
EOF
end

Expand Down
24 changes: 21 additions & 3 deletions hbase-shell/src/main/ruby/shell/commands/deleteall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ def help
hbase> deleteall 't1', 'r1'
hbase> deleteall 't1', 'r1', 'c1'
hbase> deleteall 't1', 'r1', 'c1', ts1
//'' means no specific column, will delete all cells in the row which timestamp is lower than
//the one specified in the command
# '' means no specific column, will delete all cells in the row which timestamp is lower than
# the one specified in the command
hbase> deleteall 't1', 'r1', '', ts1
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}

ROWPREFIXFILTER can be used to delete row ranges
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1' //delete certain column family in the row ranges
# delete certain column family in the row ranges
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1'
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, '', ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
Expand All @@ -51,6 +52,23 @@ def help

hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> t.deleteall {ROWPREFIXFILTER => 'prefix', CACHE => 100}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}

Alternately, we can run the following commands for deleting all cell values for
multiple columns at specified table/row coordinates.

hbase> deleteall 't1', 'r1', ['c1', 'c2']
hbase> deleteall 't1', 'r1', ['c1', 'c2'], ts1
hbase> deleteall 't1', 'r1', ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}
# delete certain column families in the row ranges
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, ['c1', 'c2']
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, ['c1', 'c2'], ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}

The same commands can also be run on a table reference.

hbase> t.deleteall 'r1', ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> t.deleteall {ROWPREFIXFILTER => 'prefix', CACHE => 100}, ['c1', 'c2'], ts1, {VISIBILITY=>'PRIVATE|SECRET'}

EOF
end

Expand Down
33 changes: 30 additions & 3 deletions hbase-shell/src/main/ruby/shell/commands/get_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,45 @@ def help
t to table 't1', the corresponding command would be:

hbase> t.get_counter 'r1', 'c1'

Alternately, we can run the following commands to get counter cell values for multiple
columns at specified table/row coordinates.

hbase> get_counter 'ns1:t1', 'r1', ['c1', 'c2']
hbase> get_counter 't1', 'r1', ['c1', 'c2']

The same commands also can be run on a table reference.

hbase> t.get_counter 'r1', ['c1', 'c2']

EOF
end

# Gets the counter value(s) from a table for a specific row and column(s).
# If the column parameter is an array, it retrieves multiple counter values.
# If no counter is found, it prints an error message.
#
# @param table [String] the name of the table
# @param row [String] the row key
# @param column [String, Array<String>] the column name(s)
def command(table, row, column)
get_counter(table(table), row, column)
end

def get_counter(table, row, column)
if cnt = table._get_counter_internal(row, column)
puts "COUNTER VALUE = #{cnt}"
# when column is an array, then it is a case of multi column get counter
if column.is_a?(Array)
if cnts = table._get_counter_multi_column_internal(row, column)
puts "COUNTER VALUES = #{cnts}"
else
puts 'No counters found at specified coordinates'
end
else
puts 'No counter found at specified coordinates'
if cnt = table._get_counter_internal(row, column)
puts "COUNTER VALUE = #{cnt}"
else
puts 'No counter found at specified coordinates'
end
end
end
end
Expand Down
42 changes: 39 additions & 3 deletions hbase-shell/src/main/ruby/shell/commands/incr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,54 @@ def help
hbase> t.incr 'r1', 'c1', 1
hbase> t.incr 'r1', 'c1', 10, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> t.incr 'r1', 'c1', 10, {VISIBILITY=>'PRIVATE|SECRET'}

Alternately, we can run the following commands for incrementing cell values for
multiple columns at specified table/row coordinates.

hbase> incr 'ns1:t1', 'r1', ['c1', 'c2']
hbase> incr 't1', 'r1', ['c1', 'c2']
hbase> incr 't1', 'r1', {'c1'=>1, 'c2'=>1}
hbase> incr 't1', 'r1', {'c1'=>10, 'c2'=>20}
hbase> incr 't1', 'r1', {'c1'=>10, 'c2'=>20}, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> incr 't1', 'r1', ['c1', 'c2'], {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> incr 't1', 'r1', {'c1'=>10, 'c2'=>20}, {VISIBILITY=>'PRIVATE|SECRET'}

The same commands also can be run on a table reference.

hbase> t.incr 'r1', ['c1', 'c2']
hbase> t.incr 'r1', {'c1'=>1, 'c2'=>1}
hbase> t.incr 'r1', {'c1'=>10, 'c2'=>20}, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> t.incr 'r1', {'c1'=>10, 'c2'=>20}, {VISIBILITY=>'PRIVATE|SECRET'}
EOF
end

# Methods to increment counter(s) for specified column(s) of a row for the table.
#
# @param table [String] The name of the table
# @param row [String] The row key
# @param column [String, Hash, Array] The column name or a hash or array of columns
# @param value [Integer, Hash] THe value to increment by or a hash of values
# @param args [Hash] Additional arguments
def command(table, row, column, value = nil, args = {})
incr(table(table), row, column, value, args)
end

def incr(table, row, column, value = nil, args = {})
if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}"
# when column is a hash map, then it is a case of multi column increment
if column.is_a?(Hash) || column.is_a?(Array)
raise(ArgumentError, 'wrong number of arguments') unless args == {}
value = {} if value.nil?
if cnts = table._incr_multi_column_internal(row, column, value)
puts "COUNTER VALUES = #{cnts}"
else
puts 'No counters found at specified coordinates'
end
else
puts 'No counter found at specified coordinates'
if cnt = table._incr_internal(row, column, value, args)
puts "COUNTER VALUE = #{cnt}"
else
puts 'No counter found at specified coordinates'
end
end
end
end
Expand Down
50 changes: 46 additions & 4 deletions hbase-shell/src/main/ruby/shell/commands/put.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,58 @@ def help
t to table 't1', the corresponding command would be:

hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}

Alternately, we can put cell values for multiple columns at specified table/row and
optionally timestamp coordinates.

hbase> put 'ns1:t1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}
hbase> put 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}
hbase> put 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, ts1
hbase> put 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
hbase> put 't1', 'r1', {'c1'=>'value1', 'c2'=>'value2'}, ts1, {VISIBILITY=>'PRIVATE|SECRET'}

The same commands also can be run on a table reference.

hbase> t.put 'r1', {'c1'=>'value1', 'c2'=>'value2'}, ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
EOF
end

def command(table, row, column, value, timestamp = nil, args = {})
put table(table), row, column, value, timestamp, args
# Method to put values in specified table/row/column and optionally timestamp coordinates.
# @param table [String] The name of the table
# @param row [String] The row key
# @param column [String, Hash] The column name or a hash of column names and values
# @param value [String, Hash] The value to append or a hash of column names and values,
# optional in case of multi column put.
# @param timestamp [Integer, Hash] optional timestamp for the cell value ora hash of additional args
# @param args [Hash] optional arguments. Must be nil in case of multi column put
def command(table, row, column, value = value_omitted = {}, timestamp = nil, args = args_omitted = {})
# Conditional block to omit passing optional arguments explicitly
if !value_omitted.nil?
# value field was not passed (will reach only for multi column put)
put table(table), row, column
elsif !args_omitted.nil?
# args field was not passed (must not be passed for multi column put)
put table(table), row, column, value, timestamp
else
put table(table), row, column, value, timestamp, args
end
end

def put(table, row, column, value, timestamp = nil, args = {})
def put(table, row, column, value = value_omitted = {}, timestamp = nil, args = args_omitted = {})
@start_time = Time.now
table._put_internal(row, column, value, timestamp, args)
# when column is a hash map, then it is a case of multi column put
if column.is_a?(Hash)
# args field must not be passed; already contained in timestamp field
raise(ArgumentError, 'wrong number of arguments') if args_omitted.nil?
value = nil unless value != {}
timestamp = {} if timestamp.nil?
table._put_multi_column_internal(row, column, value, timestamp)
else
# value field must be passed by user
raise(ArgumentError, 'wrong number of arguments') unless value_omitted.nil?
table._put_internal(row, column, value, timestamp, args)
end
end
end
end
Expand Down
Loading