Author: gates
Date: Fri Apr 11 09:14:15 2008
New Revision: 647208

URL: http://svn.apache.org/viewvc?rev=647208&view=rev
Log:
PIG-178: Use of schema on secondary output of SPLIT throws 
IndexOutOfBoundsException.

Modified:
    incubator/pig/trunk/CHANGES.txt
    incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java
    incubator/pig/trunk/test/org/apache/pig/test/TestPigSplit.java

Modified: incubator/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=647208&r1=647207&r2=647208&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Fri Apr 11 09:14:15 2008
@@ -218,3 +218,6 @@
 
        PIG-111: Reworked configuration to be setable via properties.
        (Contributions from joa23, pi_song, and oae via gates).
+
+       PIG-178: Use of schema on secondary output of SPLIT throws
+       IndexOutOfBoundsException (kali via gates).

Modified: 
incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java?rev=647208&r1=647207&r2=647208&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java 
(original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/logicalLayer/LOSplitOutput.java 
Fri Apr 11 09:14:15 2008
@@ -43,7 +43,7 @@
 
     @Override
     public TupleSchema outputSchema() {
-        return opTable.get(inputs.get(index)).outputSchema();
+        return opTable.get(getInputs().get(0)).outputSchema();
     }
 
     @Override

Modified: incubator/pig/trunk/test/org/apache/pig/test/TestPigSplit.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/test/org/apache/pig/test/TestPigSplit.java?rev=647208&r1=647207&r2=647208&view=diff
==============================================================================
--- incubator/pig/trunk/test/org/apache/pig/test/TestPigSplit.java (original)
+++ incubator/pig/trunk/test/org/apache/pig/test/TestPigSplit.java Fri Apr 11 
09:14:15 2008
@@ -64,4 +64,36 @@
                f.delete();
        }
        
+    @Test
+    public void testSchemaWithSplit() throws Exception {
+        File f = File.createTempFile("tmp", "");
+
+        PrintWriter pw = new PrintWriter(f);
+        pw.println("2");
+        pw.println("12");
+        pw.println("42");
+        pw.close();
+        pig.registerQuery("a = load 'file:" + f + "' as (value);");
+        pig.registerQuery("split a into b if value < 20, c if value > 10;");
+        pig.registerQuery("b1 = order b by value;");
+        pig.registerQuery("c1 = order c by value;");
+
+        // order in lexicographic, so 12 comes before 2
+        Iterator<Tuple> iter = pig.openIterator("b1");
+        assertTrue("b1 has an element", iter.hasNext());
+        assertEquals("first item in b1", 
iter.next().getAtomField(0).longVal(), 12);
+        assertTrue("b1 has an element", iter.hasNext());
+        assertEquals("second item in b1", 
iter.next().getAtomField(0).longVal(), 2);
+        assertFalse("b1 is over", iter.hasNext());
+
+        iter = pig.openIterator("c1");
+        assertTrue("c1 has an element", iter.hasNext());
+        assertEquals("first item in b1", 
iter.next().getAtomField(0).longVal(), 12);
+        assertTrue("c1 has an element", iter.hasNext());
+        assertEquals("second item in b1", 
iter.next().getAtomField(0).longVal(), 42);
+        assertFalse("c1 is over", iter.hasNext());
+
+        f.delete();
+    }
+
 }


Reply via email to