Author: daijy
Date: Tue Jan 20 23:24:03 2015
New Revision: 1653404

URL: http://svn.apache.org/r1653404
Log:
PIG-4340: PigStorage fails parsing empty map

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
    pig/trunk/test/org/apache/pig/test/TestConversions.java

Modified: pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1653404&r1=1653403&r2=1653404&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Jan 20 23:24:03 2015
@@ -44,6 +44,8 @@ PIG-4333: Split BigData tests into multi
  
 BUG FIXES
 
+PIG-4340: PigStorage fails parsing empty map (daijy)
+
 PIG-4366: Port local mode tests to Tez - part5 (daijy)
 
 PIG-4381: PIG grunt shell DEFINE commands fails when it spans multiple lines 
(daijy)

Modified: pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java?rev=1653404&r1=1653403&r2=1653404&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java (original)
+++ pig/trunk/src/org/apache/pig/builtin/Utf8StorageConverter.java Tue Jan 20 
23:24:03 2015
@@ -196,6 +196,7 @@ public class Utf8StorageConverter implem
 
     private Map<String, Object> consumeMap(PushbackInputStream in, 
ResourceFieldSchema fieldSchema) throws IOException {
         int buf;
+        boolean emptyMap = true;
 
         while ((buf=in.read())!='[') {
             if (buf==-1) {
@@ -207,9 +208,14 @@ public class Utf8StorageConverter implem
         while (true) {
             // Read key (assume key can not contains special character such as 
#, (, [, {, }, ], )
             while ((buf=in.read())!='#') {
+                // end of map
+                if (emptyMap && buf==']') {
+                    return m;
+                }
                 if (buf==-1) {
                     throw new IOException("Unexpect end of map");
                 }
+                emptyMap = false;
                 mOut.write(buf);
             }
             String key = bytesToCharArray(mOut.toByteArray());

Modified: pig/trunk/test/org/apache/pig/test/TestConversions.java
URL: 
http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestConversions.java?rev=1653404&r1=1653403&r2=1653404&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestConversions.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestConversions.java Tue Jan 20 23:24:03 
2015
@@ -386,6 +386,10 @@ public class TestConversions {
         m = ps.getLoadCaster().bytesToMap(s.getBytes(), rfs);
         assertNull(m);
 
+        s = "[]";
+        m = ps.getLoadCaster().bytesToMap(s.getBytes(), rfs);
+        assertTrue(m.isEmpty());
+
         s = "(a,b)";
         schema = Utils.getSchemaFromString("t:tuple()");
         rfs = new ResourceSchema(schema).getFields()[0];


Reply via email to