hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r571317 - in /lucene/hadoop/trunk/src/contrib/hbase: CHANGES.txt src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java src/java/org/apache/hadoop/hbase/shell/SelectCommand.java
Date Thu, 30 Aug 2007 21:28:26 GMT
Author: stack
Date: Thu Aug 30 14:28:25 2007
New Revision: 571317

URL: http://svn.apache.org/viewvc?rev=571317&view=rev
Log:
HADOOP-1800 [hbaseshell] output should default utf8 encoding
M  src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
    Make a PrintStream that outputs utf8. Have all printing use it.
M  src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java
    Fix few places where we make Strings w/o stipulating UTF-8 encoding.


Modified:
    lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
    lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java

Modified: lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt?rev=571317&r1=571316&r2=571317&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt (original)
+++ lucene/hadoop/trunk/src/contrib/hbase/CHANGES.txt Thu Aug 30 14:28:25 2007
@@ -26,6 +26,7 @@
     HADOOP-1805 Region server hang on exit
     HADOOP-1785 TableInputFormat.TableRecordReader.next has a bug
                 (Ning Li via Stack)
+    HADOOP-1800 output should default utf8 encoding
 
   IMPROVEMENTS
     HADOOP-1737 Make HColumnDescriptor data publically members settable

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java?rev=571317&r1=571316&r2=571317&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/ConsoleTable.java
Thu Aug 30 14:28:25 2007
@@ -19,157 +19,168 @@
  */
 package org.apache.hadoop.hbase.shell;
 
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+
 /**
  * Manufactures console table, but stupid.
  */
 public class ConsoleTable {
+  private static PrintStream out;
+  static {
+    try {
+      out = new PrintStream(System.out, true, "UTF-8");
+    } catch (UnsupportedEncodingException e) {
+      e.printStackTrace();
+    }
+  }
   
   public static void printHead(String name) {
-    System.out.println("+------+----------------------+");
-    System.out.print("| No.  | ");
-    System.out.printf("%-20s", name);
-    System.out.println(" |");
+    out.println("+------+----------------------+");
+    out.print("| No.  | ");
+    out.printf("%-20s", name);
+    out.println(" |");
   }
 
   public static void printFoot() {
-    System.out.println("+------+----------------------+");
-    System.out.println();
+    out.println("+------+----------------------+");
+    out.println();
   }
 
   public static void printTable(int count, String name) {
-    System.out.println("+------+----------------------+");
+    out.println("+------+----------------------+");
 
     if (name.length() > 20) {
       int interval = 20;
 
-      System.out.print("| ");
-      System.out.printf("%-4s", count + 1);
-      System.out.print(" | ");
-      System.out.printf("%-20s", name.substring(0, interval));
-      System.out.println(" |");
+      out.print("| ");
+      out.printf("%-4s", count + 1);
+      out.print(" | ");
+      out.printf("%-20s", name.substring(0, interval));
+      out.println(" |");
 
       for (int i = 0; i < name.length() / interval; i++) {
-        System.out.print("| ");
-        System.out.printf("%-4s", "");
-        System.out.print(" | ");
+        out.print("| ");
+        out.printf("%-4s", "");
+        out.print(" | ");
 
         int end = ((interval * i) + interval + interval);
         if (end > name.length()) {
-          System.out.printf("%-20s", name.substring(end - interval,
+          out.printf("%-20s", name.substring(end - interval,
             name.length()));
         } else {
-          System.out.printf("%-20s", name.substring(end - interval, end));
+          out.printf("%-20s", name.substring(end - interval, end));
         }
-        System.out.println(" |");
+        out.println(" |");
       }
 
     } else {
-      System.out.print("| ");
-      System.out.printf("%-4s", count + 1);
-      System.out.print(" | ");
-      System.out.printf("%-20s", name);
-      System.out.println(" |");
+      out.print("| ");
+      out.printf("%-4s", count + 1);
+      out.print(" | ");
+      out.printf("%-20s", name);
+      out.println(" |");
     }
   }
 
   public static void selectHead() {
-    System.out.println("+------+----------------------+" +
+    out.println("+------+----------------------+" +
       "----------------------+----------------------+");
-    System.out.print("| No.  | ");
-    System.out.printf("%-20s", "Row");
-    System.out.printf(" | ");
-    System.out.printf("%-20s", "Column");
-    System.out.printf(" | ");
-    System.out.printf("%-20s", "Cell");
-    System.out.println(" | ");
+    out.print("| No.  | ");
+    out.printf("%-20s", "Row");
+    out.printf(" | ");
+    out.printf("%-20s", "Column");
+    out.printf(" | ");
+    out.printf("%-20s", "Cell");
+    out.println(" | ");
   }
 
   public static void printLine(int count, String key, String column,
       String cellData) {
-    System.out.println("+------+----------------------+" +
+    out.println("+------+----------------------+" +
       "----------------------+----------------------+");
 
     if (key.length() > 20 || column.length() > 20 || cellData.length() > 20) {
       int interval = 20;
-      System.out.print("| ");
-      System.out.printf("%-4s", count + 1);
-      System.out.print(" | ");
+      out.print("| ");
+      out.printf("%-4s", count + 1);
+      out.print(" | ");
       if (key.length() > 20)
-        System.out.printf("%-20s", key.substring(0, interval));
+        out.printf("%-20s", key.substring(0, interval));
       else
-        System.out.printf("%-20s", key);
-      System.out.print(" | ");
+        out.printf("%-20s", key);
+      out.print(" | ");
       if (column.length() > 20)
-        System.out.printf("%-20s", column.substring(0, interval));
+        out.printf("%-20s", column.substring(0, interval));
       else
-        System.out.printf("%-20s", column);
-      System.out.print(" | ");
+        out.printf("%-20s", column);
+      out.print(" | ");
       if (cellData.length() > 20)
-        System.out.printf("%-20s", cellData.substring(0, interval));
+        out.printf("%-20s", cellData.substring(0, interval));
       else
-        System.out.printf("%-20s", cellData);
-      System.out.println(" |");
+        out.printf("%-20s", cellData);
+      out.println(" |");
 
-      // System.out.println(getBiggerInt(new int[]{ 3, 1, 9}));
+      // out.println(getBiggerInt(new int[]{ 3, 1, 9}));
       int biggerStrLength = getBiggerInt(new int[] { key.length(),
         column.length(), cellData.length() });
 
       for (int i = 0; i < (biggerStrLength / interval); i++) {
-        System.out.print("| ");
-        System.out.printf("%-4s", "");
-        System.out.print(" | ");
+        out.print("| ");
+        out.printf("%-4s", "");
+        out.print(" | ");
 
         int end = ((interval * i) + interval + interval);
 
         if (end > key.length()) {
           if (key.length() > interval && end - interval < key.length()) {
-            System.out.printf("%-20s", key.substring(end - interval,
+            out.printf("%-20s", key.substring(end - interval,
               key.length()));
           } else {
-            System.out.printf("%-20s", "");
+            out.printf("%-20s", "");
           }
         } else {
-          System.out.printf("%-20s", key.substring(end - interval, end));
+          out.printf("%-20s", key.substring(end - interval, end));
         }
 
-        System.out.print(" | ");
+        out.print(" | ");
 
         if (end > column.length()) {
           if (column.length() > interval && end - interval < column.length())
{
-            System.out.printf("%-20s", column.substring(end - interval,
+            out.printf("%-20s", column.substring(end - interval,
               column.length()));
           } else {
-            System.out.printf("%-20s", "");
+            out.printf("%-20s", "");
           }
         } else {
-          System.out.printf("%-20s", column.substring(end - interval, end));
+          out.printf("%-20s", column.substring(end - interval, end));
         }
 
-        System.out.print(" | ");
+        out.print(" | ");
         if (end > cellData.length()) {
           if (cellData.length() > interval &&
               end - interval < cellData.length()) {
-            System.out.printf("%-20s",
+            out.printf("%-20s",
               cellData.substring(end - interval, cellData.length()));
           } else {
-            System.out.printf("%-20s", "");
+            out.printf("%-20s", "");
           }
         } else {
-          System.out.printf("%-20s", cellData.substring(end - interval, end));
+          out.printf("%-20s", cellData.substring(end - interval, end));
         }
-        System.out.println(" |");
+        out.println(" |");
       }
 
     } else {
-      System.out.print("| ");
-      System.out.printf("%-4s", count + 1);
-      System.out.print(" | ");
-      System.out.printf("%-20s", key);
-      System.out.print(" | ");
-      System.out.printf("%-20s", column);
-      System.out.print(" | ");
-      System.out.printf("%-20s", cellData);
-      System.out.println(" |");
+      out.print("| ");
+      out.printf("%-4s", count + 1);
+      out.print(" | ");
+      out.printf("%-20s", key);
+      out.print(" | ");
+      out.printf("%-20s", column);
+      out.print(" | ");
+      out.printf("%-20s", cellData);
+      out.println(" |");
     }
   }
 
@@ -184,9 +195,9 @@
   }
 
   public static void selectFoot() {
-    System.out.println("+------+----------------------+" +
+    out.println("+------+----------------------+" +
       "----------------------+----------------------+");
-    System.out.println();
+    out.println();
   }
   
 }

Modified: lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java?rev=571317&r1=571316&r2=571317&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java
(original)
+++ lucene/hadoop/trunk/src/contrib/hbase/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java
Thu Aug 30 14:28:25 2007
@@ -77,7 +77,7 @@
 
           for (Text columnKey : results.keySet()) {
             byte[] value = results.get(columnKey);
-            String cellData = new String(value);
+            String cellData = new String(value, HConstants.UTF8_ENCODING);
 
             if (columnKey.equals(HConstants.COL_REGIONINFO)) {
               DataInputBuffer inbuf = new DataInputBuffer();
@@ -105,7 +105,7 @@
         for (Map.Entry<Text, byte[]> entry : table.getRow(new Text(getRow())).entrySet())
{
 
           byte[] value = entry.getValue();
-          String cellData = new String(value);
+          String cellData = new String(value, HConstants.UTF8_ENCODING);
 
           if (entry.getKey().equals(HConstants.COL_REGIONINFO)) {
             DataInputBuffer inbuf = new DataInputBuffer();
@@ -138,7 +138,7 @@
 
           for (Text columnKey : r.keySet()) {
             byte[] value = r.get(columnKey);
-            String cellData = new String(value);
+            String cellData = new String(value, HConstants.UTF8_ENCODING);
             ConsoleTable.printLine(count, rowKey.toString(), columnKey.toString(),
                 cellData);
             count++;
@@ -180,7 +180,7 @@
 
         ConsoleTable.selectHead();
         for (int i = 0; i < rs3.length; i++) {
-          ConsoleTable.printLine(i, getRow(), getColumn(), new String(rs3[i]));
+          ConsoleTable.printLine(i, getRow(), getColumn(), new String(rs3[i], HConstants.UTF8_ENCODING));
         }
         ConsoleTable.selectFoot();
 



Mime
View raw message