Author: sms
Date: Wed Mar  4 01:42:07 2009
New Revision: 749874

URL: http://svn.apache.org/viewvc?rev=749874&view=rev
Log:
PIG-690: UNION doesn't work in the latest code (pradeepkth via sms)

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
    hadoop/pig/trunk/test/org/apache/pig/test/TestUnion.java
    hadoop/pig/trunk/test/org/apache/pig/test/Util.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=749874&r1=749873&r2=749874&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Wed Mar  4 01:42:07 2009
@@ -444,3 +444,5 @@
     via sms)
 
     PIG-577: outer join query looses name information (sms via pradeepkth)
+
+    PIG-690: UNION doesn't work in the latest code (pradeepkth via sms)

Modified: 
hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java?rev=749874&r1=749873&r2=749874&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java 
(original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/logicalLayer/schema/Schema.java 
Wed Mar  4 01:42:07 2009
@@ -1378,7 +1378,13 @@
 
                 // create the merged field
                 // the mergedSubSchema can be true if allowIncompatibleTypes
-                mergedFs = new FieldSchema(mergedAlias, mergedSubSchema) ;
+                try {
+                    mergedFs = new FieldSchema(mergedAlias, mergedSubSchema, 
mergedType) ;
+                } catch (FrontendException e) {
+                    int errCode = 2124;
+                    String errMsg = "Internal Error: Unexpected error creating 
field schema";
+                    throw new SchemaMergeException(errMsg, errCode, 
PigException.BUG, e);
+                }
 
             }
             outputList.add(mergedFs) ;

Modified: hadoop/pig/trunk/test/org/apache/pig/test/TestUnion.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/TestUnion.java?rev=749874&r1=749873&r2=749874&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/TestUnion.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/TestUnion.java Wed Mar  4 
01:42:07 2009
@@ -216,4 +216,38 @@
         assertFalse(it.hasNext());
     }
     
+    // Test schema merge in union when one of the fields is a bag
+    @Test
+    public void testSchemaMergeWithBag() throws Exception {
+        Util.createInputFile(cluster, "input1.txt", new String[] {"dummy"});
+        Util.createInputFile(cluster, "input2.txt", new String[] {"dummy"});
+        PigServer pig = new PigServer(ExecType.MAPREDUCE, 
cluster.getProperties());
+        Util.registerQuery(pig, "a = load 'input1.txt' ;" +
+                       "b = load 'input2.txt';" +
+                       "c = foreach a generate 1, {(1, 'str1')};" +
+                       "d = foreach b generate 2, {(2, 'str2')};" +
+                       "e = union c,d");
+        Iterator<Tuple> it = pig.openIterator("e");
+        Object[] expected = new Object[] { Util.getPigConstant("(1, {(1, 
'str1')})"),
+                Util.getPigConstant("(2, {(2, 'str2')})")};
+        Object[] results = new Object[2];
+        int i = 0;
+        while(it.hasNext()) {
+            if(i == 2) {
+                fail("Got more tuples than expected!");
+            }
+            Tuple t = it.next();
+            if(t.get(0).equals(1)) {
+                // this is the first tuple
+                results[0] = t;
+            } else {
+                results[1] = t;
+            }
+            i++;
+        }
+        for (int j = 0; j < expected.length; j++) {
+            assertTrue(expected[j].equals(results[j]));
+        }
+    }
+    
 }

Modified: hadoop/pig/trunk/test/org/apache/pig/test/Util.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/test/org/apache/pig/test/Util.java?rev=749874&r1=749873&r2=749874&view=diff
==============================================================================
--- hadoop/pig/trunk/test/org/apache/pig/test/Util.java (original)
+++ hadoop/pig/trunk/test/org/apache/pig/test/Util.java Wed Mar  4 01:42:07 2009
@@ -311,6 +311,12 @@
         Schema.setSchemaDefaultType(schema, defaultType);
         return schema;
     }
+    
+    static Object getPigConstant(String pigConstantAsString) throws 
ParseException {
+        ByteArrayInputStream stream = new 
ByteArrayInputStream(pigConstantAsString.getBytes()) ;
+        QueryParser queryParser = new QueryParser(stream) ;
+        return queryParser.Datum();
+    }
 
     public static File createFile(String[] data) throws Exception{
         File f = File.createTempFile("tmp", "");


Reply via email to