You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by th...@apache.org on 2011/01/27 01:37:41 UTC

svn commit: r1063933 - in /pig/trunk: CHANGES.txt src/org/apache/pig/PigServer.java src/org/apache/pig/newplan/logical/relational/LOLoad.java test/org/apache/pig/test/TestUDFContext.java

Author: thejas
Date: Thu Jan 27 00:37:41 2011
New Revision: 1063933

URL: http://svn.apache.org/viewvc?rev=1063933&view=rev
Log:
PIG-1776: changing statement corresponding to alias after explain , then
  doing dump gives incorrect result 

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/PigServer.java
    pig/trunk/src/org/apache/pig/newplan/logical/relational/LOLoad.java
    pig/trunk/test/org/apache/pig/test/TestUDFContext.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1063933&r1=1063932&r2=1063933&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Thu Jan 27 00:37:41 2011
@@ -282,6 +282,9 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1776: changing statement corresponding to alias after explain , then 
+  doing dump gives incorrect result (thejas)
+
 PIG-1800: Missing Signature for maven staging release (rding)
 
 PIG-1815: pig task retains used instances of PhysicalPlan (thejas)

Modified: pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigServer.java?rev=1063933&r1=1063932&r2=1063933&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ pig/trunk/src/org/apache/pig/PigServer.java Thu Jan 27 00:37:41 2011
@@ -100,6 +100,7 @@ import org.apache.pig.impl.util.LogUtils
 import org.apache.pig.impl.util.ObjectSerializer;
 import org.apache.pig.impl.util.Pair;
 import org.apache.pig.impl.util.PropertiesUtil;
+import org.apache.pig.impl.util.UDFContext;
 import org.apache.pig.impl.util.Utils;
 import org.apache.pig.newplan.logical.LogicalPlanMigrationVistor;
 import org.apache.pig.newplan.logical.optimizer.LogicalPlanOptimizer;
@@ -1762,6 +1763,9 @@ public class PigServer {
             graph.ignoreNumStores = processedStores;
             graph.processedStores = processedStores;
             graph.fileNameMap = fileNameMap;
+            
+            //reset udf properties
+            UDFContext.getUDFContext().reset();
 
             try {
                 for (Iterator<String> it = getScriptCache().iterator(); it.hasNext(); lineNumber++) {

Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LOLoad.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LOLoad.java?rev=1063933&r1=1063932&r2=1063933&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/relational/LOLoad.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LOLoad.java Thu Jan 27 00:37:41 2011
@@ -206,4 +206,10 @@ public class LOLoad extends LogicalRelat
     public void resetUid() {
         uidOnlySchema = null;
     }
+    
+    @Override
+    public String toString(){
+        String str = super.toString();
+        return (str + "RequiredFields:" + requiredFields);
+    }
 }

Modified: pig/trunk/test/org/apache/pig/test/TestUDFContext.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestUDFContext.java?rev=1063933&r1=1063932&r2=1063933&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestUDFContext.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestUDFContext.java Thu Jan 27 00:37:41 2011
@@ -17,35 +17,29 @@
  */
 package org.apache.pig.test;
 
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.io.File;
 import java.io.FileWriter;
-import java.io.IOException;
 import java.util.Iterator;
 import java.util.Properties;
 
-import org.apache.pig.EvalFunc;
 import org.apache.pig.ExecType;
 import org.apache.pig.PigServer;
 import org.apache.pig.builtin.PigStorage;
 import org.apache.pig.data.Tuple;
-import org.apache.pig.impl.io.BufferedPositionedInputStream;
 import org.apache.pig.impl.io.FileLocalizer;
-import org.apache.pig.impl.logicalLayer.schema.Schema;
 import org.apache.pig.impl.util.UDFContext;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import junit.framework.TestCase;
 
-@RunWith(JUnit4.class)
-public class TestUDFContext extends TestCase {
+public class TestUDFContext {
     
     static MiniCluster cluster = null;
     
-    @Override 
     @Before
     public void setUp() throws Exception {
         cluster = MiniCluster.buildCluster();
@@ -87,4 +81,34 @@ public class TestUDFContext extends Test
         	assertEquals(tuple.get(3).toString(), "five");
         }
     }
+    
+    
+    /**
+     * Test that UDFContext is reset each time the plan is regenerated 
+     * @throws Exception
+     */
+    @Test
+    public void testUDFContextReset() throws Exception {
+        PigServer pig = new PigServer(ExecType.MAPREDUCE, cluster.getProperties());
+        pig.registerQuery(" l = load 'file' as (a :int, b : int, c : int);");
+        pig.registerQuery(" f = foreach l generate a, b;");        
+        pig.explain("f", System.out);
+        Properties props = UDFContext.getUDFContext().getUDFProperties(PigStorage.class);
+
+        // required fields property should be set because f results does not
+        // require the third column c, so properties should not be null
+        assertNotNull(props.get("l"));
+        
+        // the new statement for alias f below will require all columns,
+        // so this time required fields property for loader should not be set
+        pig.registerQuery(" f = foreach l generate a, b, c;");
+        pig.explain("f", System.out);
+        props = UDFContext.getUDFContext().getUDFProperties(PigStorage.class);
+
+        assertTrue("properties in udf context for load should be null", 
+                props.get("l") == null);
+
+        
+    }
+    
 }