You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2009/02/26 18:55:28 UTC

svn commit: r748238 - in /hadoop/hbase/trunk: CHANGES.txt bin/HBase.rb

Author: stack
Date: Thu Feb 26 17:55:27 2009
New Revision: 748238

URL: http://svn.apache.org/viewvc?rev=748238&view=rev
Log:
HBASE-1210 Allow truncation of output for scan and get commands in shell

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/bin/HBase.rb

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=748238&r1=748237&r2=748238&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu Feb 26 17:55:27 2009
@@ -57,6 +57,8 @@
                on absolute path (Nitay Joffe via Jean-Daniel Cryans)
    HBASE-1187  After disabling/enabling a table, the regions seems to 
                be assigned to only 1-2 region servers
+   HBASE-1210  Allow truncation of output for scan and get commands in shell
+               (Lars George via Stack)
 
 Release 0.19.0 - 01/21/2009
   INCOMPATIBLE CHANGES

Modified: hadoop/hbase/trunk/bin/HBase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/HBase.rb?rev=748238&r1=748237&r2=748238&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/HBase.rb (original)
+++ hadoop/hbase/trunk/bin/HBase.rb Thu Feb 26 17:55:27 2009
@@ -36,6 +36,7 @@
   ENDROW = STOPROW
   LIMIT = "LIMIT"
   METHOD = "METHOD"
+  MAXLENGTH = "MAXLENGTH"
 
   # Wrapper for org.apache.hadoop.hbase.client.HBaseAdmin
   class Admin
@@ -316,8 +317,10 @@
     def scan(args = {})
       now = Time.now 
       limit = -1
+      maxlength = -1
       if args != nil and args.length > 0
         limit = args["LIMIT"] || -1 
+        maxlength = args["MAXLENGTH"] || -1 
         filter = args["FILTER"] || nil
         startrow = args["STARTROW"] || ""
         stoprow = args["STOPROW"] || nil
@@ -348,7 +351,7 @@
         row = String.from_java_bytes r.getRow()
         for k, v in r
           column = String.from_java_bytes k
-          cell = toString(column, v)
+          cell = toString(column, v, maxlength)
           @formatter.row([row, "column=%s, %s" % [column, cell]])
         end
         count += 1
@@ -381,7 +384,7 @@
 
     # Make a String of the passed cell.
     # Intercept cells whose format we know such as the info:regioninfo in .META.
-    def toString(column, cell)
+    def toString(column, cell, maxlength)
       if isMetaTable()
         if column == 'info:regioninfo'
           hri = Writables.getHRegionInfoOrNull(cell.getValue())
@@ -392,13 +395,15 @@
         end
       end
       cell.toString()
+      val = cell.toString()
+      maxlength != -1 ? val[0, maxlength] : val    
     end
   
     # Get from table
     def get(row, args = {})
       now = Time.now 
       result = nil
-      if args == nil or args.length == 0
+      if args == nil or args.length == 0 or (args.length == 1 and args[MAXLENGTH] != nil)
         result = @table.getRow(row.to_java_bytes)
       else
         # Its a hash.
@@ -431,6 +436,7 @@
         end
       end
       # Print out results.  Result can be Cell or RowResult.
+      maxlength = args[MAXLENGTH] || -1
       h = nil
       if result.instance_of? RowResult
         h = String.from_java_bytes result.getRow()
@@ -438,7 +444,7 @@
         if result
           for k, v in result
             column = String.from_java_bytes k
-            @formatter.row([column, toString(column, v)])
+            @formatter.row([column, toString(column, v, maxlength)])
           end
         end
       else
@@ -446,7 +452,7 @@
         @formatter.header()
         if result 
           for c in result
-            @formatter.row([c.toString()])
+            @formatter.row([toString(nil, c, maxlength)])
           end
         end
       end