You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2014/10/10 19:08:27 UTC

svn commit: r1630941 - in /pig/trunk: CHANGES.txt src/org/apache/pig/parser/LogicalPlanGenerator.g test/org/apache/pig/test/TestSchema.java

Author: daijy
Date: Fri Oct 10 17:08:27 2014
New Revision: 1630941

URL: http://svn.apache.org/r1630941
Log:
PIG-4219: When parsing a schema, pig drops tuple inside of Bag if it contains only one field

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
    pig/trunk/test/org/apache/pig/test/TestSchema.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1630941&r1=1630940&r2=1630941&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Fri Oct 10 17:08:27 2014
@@ -92,6 +92,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-4219: When parsing a schema, pig drops tuple inside of Bag if it contains only one field (lbendig via daijy)
+
 PIG-4226: Upgrade Tez to 0.5.1 (daijy)
 
 PIG-4220: MapReduce-based Rank failing with NPE due to missing Counters (knoguchi)

Modified: pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g?rev=1630941&r1=1630940&r2=1630941&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g (original)
+++ pig/trunk/src/org/apache/pig/parser/LogicalPlanGenerator.g Fri Oct 10 17:08:27 2014
@@ -430,14 +430,9 @@ tuple_type returns[LogicalSchema logical
 bag_type returns[LogicalSchema logicalSchema]
  : ^( BAG_TYPE IDENTIFIER? tuple_type? )
    {
-       if ($tuple_type.logicalSchema!=null && $tuple_type.logicalSchema.size()==1 && $tuple_type.logicalSchema.getField(0).type==DataType.TUPLE) {
-           $logicalSchema = $tuple_type.logicalSchema;
-       }
-       else {
-           LogicalSchema s = new LogicalSchema();
-           s.addField(new LogicalFieldSchema($IDENTIFIER.text, $tuple_type.logicalSchema, DataType.TUPLE));
-           $logicalSchema = s;
-       }
+       LogicalSchema s = new LogicalSchema();
+       s.addField(new LogicalFieldSchema($IDENTIFIER.text, $tuple_type.logicalSchema, DataType.TUPLE));
+       $logicalSchema = s;
    }
 ;
 

Modified: pig/trunk/test/org/apache/pig/test/TestSchema.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestSchema.java?rev=1630941&r1=1630940&r2=1630941&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestSchema.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestSchema.java Fri Oct 10 17:08:27 2014
@@ -879,10 +879,27 @@ public class TestSchema {
         }
     }
 
-     @Test(expected=ParserException.class)
-     public void testGetStringFromSchemaNegative() throws Exception {
-         String schemaString = "a:int b:long"; // A comma is missing between fields
-         Utils.getSchemaFromString(schemaString);
-         fail("The schema string is invalid, so parsing should fail!");
-     }
+    @Test(expected = ParserException.class)
+    public void testGetStringFromSchemaNegative() throws Exception {
+        String schemaString = "a:int b:long"; // A comma is missing between fields
+        Utils.getSchemaFromString(schemaString);
+        fail("The schema string is invalid, so parsing should fail!");
+    }
+    
+    @Test
+    public void testGetInitialSchemaStringFromSchema() throws ParserException {
+        String[] schemaStrings = {
+                "my_list:{array:(array_element:(num1:int,num2:int))}",
+                "my_list:{array:(array_element:(num1:int,num2:int),c:chararray)}",
+                "bag:{mytuple3:(mytuple2:(mytuple:(f1:int)))}",
+                "bag:{mytuple:(f1:int)}",
+                "{((num1:int,num2:int))}"
+        };
+        for (String schemaString : schemaStrings) {
+            String s1 = Utils.getSchemaFromString(schemaString).toString();
+            //check if we get back the initial schema string
+            String s2 = s1.substring(1, s1.length() - 1).replaceAll("\\s|bag_0:|tuple_0:", "");
+            assertTrue(schemaString.equals(s2));
+        }
+    }
 }