Browse Source

HADOOP-4205. Reverted to 697291 because of an erroneous commit of this file.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@697295 13f79535-47bb-0310-9956-ffa450edef68
Zheng Shao 16 years ago
parent
commit
6f7d4072df
1 changed files with 23 additions and 22 deletions
  1. 23 22
      src/contrib/hive/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java

+ 23 - 22
src/contrib/hive/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java

@@ -82,30 +82,27 @@ public class CliDriver {
         e.printStackTrace();
       }
 
-    } else {
+    } 
+    else {
       ret = qp.run(cmd);
       Vector<Vector<String>> res = new Vector<Vector<String>>();
-      while (qp.getResults(res))
-      {
-        SessionState ss = SessionState.get();
-        OutputStream out = ss.out;
-        try 
-        {
+      while (qp.getResults(res)) {
+        SessionState ss  = SessionState.get();
+        PrintStream out = ss.out;
 
-          for (Vector<String> row:res)
+        for (Vector<String> row:res)
+        {
+          boolean firstCol = true;
+          for (String col:row)
           {
-            for (String col:row)
-            {
-              out.write(col == null ? Utilities.nullStringOutput.getBytes() : col.getBytes());
+            if (!firstCol)
               out.write(Utilities.tabCode);
-            } 
-            out.write(Utilities.newLineCode);
-          }
-          res.clear();
-
-        } catch (IOException e) {
-          e.printStackTrace();
+            out.print(col == null ? Utilities.nullStringOutput : col);
+            firstCol = false;
+          } 
+          out.write(Utilities.newLineCode);
         }
+        res.clear();
       }
     }
     return ret;
@@ -151,16 +148,20 @@ public class CliDriver {
     SessionState.initHiveLog4j();
 
     CliSessionState ss = new CliSessionState (new HiveConf(SessionState.class));
+    ss.in = System.in;
+    try {
+      ss.out = new PrintStream(System.out, true, "UTF-8");
+      ss.err = new PrintStream(System.err, true, "UTF-8");
+    } catch (UnsupportedEncodingException e) {
+      System.exit(3);
+    }
+
     SessionState.start(ss);
 
     if(! oproc.process_stage2(ss)) {
       System.exit(2);
     }
 
-    ss.in = System.in;
-    ss.out = System.out;
-    ss.err = System.err;
-
     sp = new SetProcessor();
     qp = new Driver();