hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1368624 - /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
Date Thu, 02 Aug 2012 17:54:34 GMT
Author: hashutosh
Date: Thu Aug  2 17:54:33 2012
New Revision: 1368624

URL: http://svn.apache.org/viewvc?rev=1368624&view=rev
Log:
HIVE-3320 : Handle CRLF line endings to avoid the extra spacing in generated test outputs
in Windows. (Utilities.Java :: readColumn) (Kanna Karanam via Ashutosh Chauhan)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java?rev=1368624&r1=1368623&r2=1368624&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/exec/Utilities.java Thu Aug  2 17:54:33
2012
@@ -145,6 +145,7 @@ import org.apache.hadoop.mapred.JobConf;
 import org.apache.hadoop.mapred.SequenceFileInputFormat;
 import org.apache.hadoop.mapred.SequenceFileOutputFormat;
 import org.apache.hadoop.util.ReflectionUtils;
+import org.apache.hadoop.util.Shell;
 
 /**
  * Utilities.
@@ -589,6 +590,7 @@ public final class Utilities {
     defaultTd = PlanUtils.getDefaultTableDesc("" + Utilities.ctrlaCode);
   }
 
+  public static final int carriageReturnCode = 13;
   public static final int newLineCode = 10;
   public static final int tabCode = 9;
   public static final int ctrlaCode = 1;
@@ -814,6 +816,7 @@ public final class Utilities {
 
   public static StreamStatus readColumn(DataInput in, OutputStream out) throws IOException
{
 
+    boolean foundCrChar = false;
     while (true) {
       int b;
       try {
@@ -822,6 +825,22 @@ public final class Utilities {
         return StreamStatus.EOF;
       }
 
+      // Default new line characters on windows are "CRLF" so detect if there are any windows
+      // native newline characters and handle them.
+      if (Shell.WINDOWS) {
+        // if the CR is not followed by the LF on windows then add it back to the stream
and
+        // proceed with next characters in the input stream.
+        if (foundCrChar && b != Utilities.newLineCode) {
+          out.write(Utilities.carriageReturnCode);
+          foundCrChar = false;
+        }
+
+        if (b == Utilities.carriageReturnCode) {
+          foundCrChar = true;
+          continue;
+        }
+      }
+
       if (b == Utilities.newLineCode) {
         return StreamStatus.TERMINATED;
       }



Mime
View raw message