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/09/16 07:42:46 UTC

svn commit: r1625216 - in /pig/trunk: CHANGES.txt src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java test/org/apache/pig/test/TestMultiQuery.java

Author: daijy
Date: Tue Sep 16 05:42:45 2014
New Revision: 1625216

URL: http://svn.apache.org/r1625216
Log:
PIG-4170: Multiquery with different type of key gives wrong result

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java
    pig/trunk/test/org/apache/pig/test/TestMultiQuery.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1625216&r1=1625215&r2=1625216&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Sep 16 05:42:45 2014
@@ -70,6 +70,8 @@ OPTIMIZATIONS
  
 BUG FIXES
 
+PIG-4170: Multiquery with different type of key gives wrong result (daijy)
+
 PIG-4104: Accumulator UDF throws OOM in Tez (rohini)
 
 PIG-4169: NPE in ConstantCalculator (cheolsoo)

Modified: pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java?rev=1625216&r1=1625215&r2=1625216&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java (original)
+++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/MultiQueryPackager.java Tue Sep 16 05:42:45 2014
@@ -242,9 +242,15 @@ public class MultiQueryPackager extends 
 
     @Override
     public Tuple getValueTuple(PigNullableWritable keyWritable,
-            NullableTuple ntup, int index) throws ExecException {
+            NullableTuple ntup, int origIndex) throws ExecException {
         this.keyWritable = keyWritable;
-        return packagers.get(((int) index) & idxPart).getValueTuple(
-                keyWritable, ntup, index);
+        int index = origIndex & idxPart;
+        PigNullableWritable newKey = keyWritable;
+        if (!sameMapKeyType && !inCombiner && isKeyWrapped.get(index)) {                                       
+            Tuple tup = (Tuple)this.keyWritable.getValueAsPigType();
+            newKey = HDataType.getWritableComparableTypes(tup.get(0), packagers.get(index).getKeyType());
+            newKey.setIndex((byte)origIndex);
+        }
+        return packagers.get(index).getValueTuple(newKey, ntup, origIndex);
     }
 }

Modified: pig/trunk/test/org/apache/pig/test/TestMultiQuery.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestMultiQuery.java?rev=1625216&r1=1625215&r2=1625216&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestMultiQuery.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestMultiQuery.java Tue Sep 16 05:42:45 2014
@@ -813,6 +813,32 @@ public class TestMultiQuery {
         }
     }
 
+    @Test
+    public void testMultiQueryJiraPig4170() throws Exception {
+
+        Storage.Data data = Storage.resetData(myPig);
+        data.set("inputLocation", Storage.tuple(1, "hello"), Storage.tuple(2, "world"));
+
+        myPig.setBatchOn();
+        myPig.registerQuery("A = load 'inputLocation' using mock.Storage() as (a:int, b:chararray);");
+        myPig.registerQuery("A1 = group A by a;");
+        myPig.registerQuery("A2 = group A by b;");
+        myPig.registerQuery("store A1 into 'output1' using mock.Storage();");
+        myPig.registerQuery("store A2 into 'output2' using mock.Storage();");
+
+        myPig.executeBatch();
+
+        myPig.registerQuery("A = load 'output1' using mock.Storage() as (a:int, c:bag{(i:int, s:chararray)});");
+        Iterator<Tuple> iter = myPig.openIterator("A");
+        iter.next().toString().equals("(1,{(1,hello)})");
+        iter.next().toString().equals("(2,{(2,world)})");
+
+        myPig.registerQuery("A = load 'output2' using mock.Storage() as (b:chararray, c:bag{(i:int, s:chararray)});");
+        iter = myPig.openIterator("A");
+        iter.next().toString().equals("(hello,{(1,hello)})");
+        iter.next().toString().equals("(world,{(2,world)})");
+    }
+
     // --------------------------------------------------------------------------
     // Helper methods