You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/11/17 02:46:57 UTC

svn commit: r1202993 - /hbase/branches/0.89-fb/bin/list_cfs.rb

Author: nspiegelberg
Date: Thu Nov 17 01:46:57 2011
New Revision: 1202993

URL: http://svn.apache.org/viewvc?rev=1202993&view=rev
Log:
list tables and CFs in a cell

Summary:
This is a quick and convenient way to get a list of all tables in a cell, along
with their column families (need this for backups)

First JRuby script I've written.  Open to other ideas if folks have any.

Karthik, Kannan, Jerry, what list should I send diffs like this to?  There was
talk about a Hbase-diffs list today but I don't see it in phabricator. (yet?)

Test Plan:
HASHOUT001-ASH3 output:
[hadoop@hbasectrl005.ash3 ~/HASHOUT001-ASH3-HBASE/bin]$ ./hbase org.jruby.Main
list_cfs.rb  2>/dev/null
hashout_general_purpose	appid,soft
hashout_general_purpose_test	appid
test_table	my_cf

ERIS002-SNC4 output: https://our.intern.facebook.com/intern/paste/?pid=40913

Reviewers: kranganathan, kannan, paultuckfield, gqchen

Reviewed By: kannan

CC: hbase-ops@lists, madhuvaidya, kannan, hbase-eng@lists, kranganathan, ryan

Differential Revision: 354434

Added:
    hbase/branches/0.89-fb/bin/list_cfs.rb   (with props)

Added: hbase/branches/0.89-fb/bin/list_cfs.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/bin/list_cfs.rb?rev=1202993&view=auto
==============================================================================
--- hbase/branches/0.89-fb/bin/list_cfs.rb (added)
+++ hbase/branches/0.89-fb/bin/list_cfs.rb Thu Nov 17 01:46:57 2011
@@ -0,0 +1,34 @@
+# List all tables in a human and machine readable format.
+# table[tab]cf1,cf2,cf3
+#
+#  ${HBASE_HOME}/bin/hbase org.jruby.Main list_cfs.rb
+
+require 'java'
+
+import org.apache.hadoop.hbase.HBaseConfiguration
+import org.apache.hadoop.hbase.HConstants
+import org.apache.hadoop.hbase.client.HBaseAdmin
+import org.apache.hadoop.hbase.util.Bytes
+
+config = HBaseConfiguration.new
+config.set 'fs.default.name', config.get(HConstants::HBASE_DIR)
+
+admin = HBaseAdmin.new(config)
+
+scanner = admin.listTables
+tables = {}
+
+scanner.each { |row|
+  table = row.getNameAsString
+  cfs = []
+  a = row.getFamilies.each { |cf_java|
+    cf = Bytes.toString(cf_java.getName)
+    cfs[0,0] = cf
+  }
+  tables[table] = cfs.uniq
+}
+
+tables.keys.each { |table|
+  cfs = tables[table].sort.join(',')
+  puts "%s\t%s" % [table, cfs]
+}

Propchange: hbase/branches/0.89-fb/bin/list_cfs.rb
------------------------------------------------------------------------------
    svn:executable = *