You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by bi...@apache.org on 2012/04/24 08:52:49 UTC

svn commit: r1329567 - in /pig/trunk/src/org/apache/pig: PigServer.java newplan/logical/relational/LogicalPlan.java

Author: billgraham
Date: Tue Apr 24 06:52:48 2012
New Revision: 1329567

URL: http://svn.apache.org/viewvc?rev=1329567&view=rev
Log:
PIG-2587 - Compute LogicalPlan signature and store in job conf (billgraham)

Modified:
    pig/trunk/src/org/apache/pig/PigServer.java
    pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlan.java

Modified: pig/trunk/src/org/apache/pig/PigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/PigServer.java?rev=1329567&r1=1329566&r2=1329567&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/PigServer.java (original)
+++ pig/trunk/src/org/apache/pig/PigServer.java Tue Apr 24 06:52:48 2012
@@ -1232,7 +1232,7 @@ public class PigServer {
         if( jobPriority != null ) {
             pigContext.getProperties().setProperty( PigContext.JOB_PRIORITY, jobPriority );
         }
-       
+
         // In this plan, all stores in the plan will be executed. They should be ignored if the plan is reused.
         currDAG.countExecutedStores();
        
@@ -1241,7 +1241,9 @@ public class PigServer {
         if( currDAG.lp.size() == 0 ) {
            return PigStats.get(); 
         }
-        
+
+        pigContext.getProperties().setProperty("pig.logical.plan.signature", currDAG.lp.getSignature());
+
         PigStats stats = executeCompiledLogicalPlan();
         
         return stats;

Modified: pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlan.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlan.java?rev=1329567&r1=1329566&r2=1329567&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlan.java (original)
+++ pig/trunk/src/org/apache/pig/newplan/logical/relational/LogicalPlan.java Tue Apr 24 06:52:48 2012
@@ -18,6 +18,7 @@
 
 package org.apache.pig.newplan.logical.relational;
 
+import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -104,5 +105,22 @@ public class LogicalPlan extends BaseOpe
     		return ops.get( ops.size() - 1 ); // Last one
     	}
     }
-    
+
+    /**
+     * Returns the signature of the LogicalPlan. The signature is a unique identifier for a given
+     * plan generated by a Pig script. The same script run multiple times with the same version of
+     * Pig is guarenteed to produce the same signature, even if the input or output locations differ.
+     *
+     * @return a unique identifier for the logical plan
+     * @throws FrontendException if signature can't be computed
+     */
+    public String getSignature() throws FrontendException {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        PrintStream ps = new PrintStream(baos);
+
+        LogicalPlanPrinter printer = new LogicalPlanPrinter(this, ps);
+        printer.visit();
+
+        return Integer.toString(baos.toString().hashCode());
+    }
 }