diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 9263518..0e517fb 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -721,8 +721,8 @@ module Hbase #---------------------------------------------------------------------------------------------- # Returns a list of snapshots - def list_snapshot - @admin.listSnapshots + def list_snapshot(regex = ".*") + @admin.listSnapshots(regex).to_a end # Apply config specific to a table/column to its descriptor @@ -748,8 +748,10 @@ module Hbase #---------------------------------------------------------------------------------------------- # Returns a list of namespaces in hbase - def list_namespace - @admin.listNamespaceDescriptors.map { |ns| ns.getName } + def list_namespace(regex = ".*") + pattern = java.util.regex.Pattern.compile(regex) + list = @admin.listNamespaceDescriptors.map { |ns| ns.getName } + list.select {|s| pattern.match(s) } end #---------------------------------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/hbase/replication_admin.rb b/hbase-shell/src/main/ruby/hbase/replication_admin.rb index d1ddee3..cc9e41f 100644 --- a/hbase-shell/src/main/ruby/hbase/replication_admin.rb +++ b/hbase-shell/src/main/ruby/hbase/replication_admin.rb @@ -45,8 +45,10 @@ module Hbase #--------------------------------------------------------------------------------------------- # Show replcated tables/column families, and their ReplicationType - def list_replicated_tables - @replication_admin.listReplicated() + def list_replicated_tables(regex = ".*") + pattern = java.util.regex.Pattern.compile(regex) + list = @replication_admin.listReplicated() + list.select {|s| pattern.match(s.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::TNAME))} end #---------------------------------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/disable_all.rb b/hbase-shell/src/main/ruby/shell/commands/disable_all.rb index 1793a42..212db24 100644 --- a/hbase-shell/src/main/ruby/shell/commands/disable_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/disable_all.rb @@ -31,8 +31,7 @@ EOF end def command(regex) - regex = /^#{regex}$/ unless regex.is_a?(Regexp) - list = admin.list.grep(regex) + list = admin.list(regex) count = list.size list.each do |table| formatter.row([ table ]) diff --git a/hbase-shell/src/main/ruby/shell/commands/drop_all.rb b/hbase-shell/src/main/ruby/shell/commands/drop_all.rb index 0ed96af..73398fb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/drop_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/drop_all.rb @@ -31,8 +31,7 @@ EOF end def command(regex) - regex = /^#{regex}$/ unless regex.is_a?(Regexp) - list = admin.list.grep(regex) + list = admin.list(regex) count = list.size list.each do |table| formatter.row([ table ]) diff --git a/hbase-shell/src/main/ruby/shell/commands/enable_all.rb b/hbase-shell/src/main/ruby/shell/commands/enable_all.rb index f6ced26..2b899f2 100644 --- a/hbase-shell/src/main/ruby/shell/commands/enable_all.rb +++ b/hbase-shell/src/main/ruby/shell/commands/enable_all.rb @@ -31,8 +31,7 @@ EOF end def command(regex) - regex = /^#{regex}$/ unless regex.is_a?(Regexp) - list = admin.list.grep(regex) + list = admin.list(regex) count = list.size list.each do |table| formatter.row([ table ]) diff --git a/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb b/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb index 0b577fe..5d25604 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_namespace.rb @@ -34,8 +34,7 @@ EOF now = Time.now formatter.header([ "NAMESPACE" ]) - regex = /#{regex}/ unless regex.is_a?(Regexp) - list = admin.list_namespace.grep(regex) + list = admin.list_namespace(regex) list.each do |table| formatter.row([ table ]) end diff --git a/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb b/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb index b1494b8..0db1d83 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_replicated_tables.rb @@ -34,9 +34,7 @@ EOF now = Time.now formatter.header([ "TABLE:COLUMNFAMILY", "ReplicationType" ], [ 32 ]) - list = replication_admin.list_replicated_tables - regex = /#{regex}/ unless regex.is_a?(Regexp) - list = list.select {|s| regex.match(s.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::TNAME))} + list = replication_admin.list_replicated_tables(regex) list.each do |e| if e.get(org.apache.hadoop.hbase.client.replication.ReplicationAdmin::REPLICATIONTYPE) == org.apache.hadoop.hbase.client.replication.ReplicationAdmin::REPLICATIONGLOBAL replicateType = "GLOBAL" diff --git a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb index 9513518..4e68802 100644 --- a/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb +++ b/hbase-shell/src/main/ruby/shell/commands/list_snapshots.rb @@ -37,8 +37,7 @@ EOF now = Time.now formatter.header([ "SNAPSHOT", "TABLE + CREATION TIME"]) - regex = /#{regex}/ unless regex.is_a?(Regexp) - list = admin.list_snapshot.select {|s| regex.match(s.getName)} + list = admin.list_snapshot(regex) list.each do |snapshot| creation_time = Time.at(snapshot.getCreationTime() / 1000).to_s formatter.row([ snapshot.getName, snapshot.getTable + " (" + creation_time + ")" ])