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 2012/02/07 20:48:14 UTC

svn commit: r1241578 - in /pig/trunk: CHANGES.txt src/org/apache/pig/tools/grunt/GruntParser.java test/org/apache/pig/test/TestGrunt.java

Author: daijy
Date: Tue Feb  7 19:48:14 2012
New Revision: 1241578

URL: http://svn.apache.org/viewvc?rev=1241578&view=rev
Log:
PIG-2497: Order of execution of fs, store and sh commands in Pig is not maintained

Modified:
    pig/trunk/CHANGES.txt
    pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
    pig/trunk/test/org/apache/pig/test/TestGrunt.java

Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1241578&r1=1241577&r2=1241578&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Tue Feb  7 19:48:14 2012
@@ -395,6 +395,8 @@ BUG FIXES
 
 PIG-2493: UNION causes casting issues (vivekp via daijy)
 
+PIG-2497: Order of execution of fs, store and sh commands in Pig is not maintained (daijy)
+
 Release 0.9.2
 
 IMPROVEMENTS

Modified: pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java?rev=1241578&r1=1241577&r2=1241578&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java (original)
+++ pig/trunk/src/org/apache/pig/tools/grunt/GruntParser.java Tue Feb  7 19:48:14 2012
@@ -995,22 +995,28 @@ public class GruntParser extends PigScri
     
     @Override
     protected void processShCommand(String[] cmdTokens) throws IOException{
-        try {
-            Process executor = Runtime.getRuntime().exec(cmdTokens);
-            StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
-            StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);
-
-            outPrinter.start();
-            errPrinter.start();
-
-            int ret = executor.waitFor();
-            outPrinter.join();
-            errPrinter.join();
-            if (ret != 0) {
-                log.warn("Command failed with exit code = " + ret);
+        if(mExplain == null) { // process only if not in "explain" mode
+            try {
+                executeBatch();
+                
+                Process executor = Runtime.getRuntime().exec(cmdTokens);
+                StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
+                StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);
+    
+                outPrinter.start();
+                errPrinter.start();
+    
+                int ret = executor.waitFor();
+                outPrinter.join();
+                errPrinter.join();
+                if (ret != 0) {
+                    log.warn("Command failed with exit code = " + ret);
+                }
+            } catch (Exception e) {
+                log.warn("Exception raised from Shell command " + e.getLocalizedMessage());
             }
-        } catch (Exception e) {
-            log.warn("Exception raised from Shell command " + e.getLocalizedMessage());
+        } else {
+            log.warn("'sh' statement is ignored while processing 'explain -script' or '-check'");
         }
     }
     

Modified: pig/trunk/test/org/apache/pig/test/TestGrunt.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestGrunt.java?rev=1241578&r1=1241577&r2=1241578&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestGrunt.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestGrunt.java Tue Feb  7 19:48:14 2012
@@ -34,6 +34,8 @@ import org.apache.pig.ExecType;
 import org.apache.pig.PigException;
 import org.apache.pig.PigServer;
 import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.backend.executionengine.ExecJob;
+import org.apache.pig.backend.executionengine.ExecJob.JOB_STATUS;
 import org.apache.pig.impl.PigContext;
 import org.apache.pig.test.Util.ProcessReturnInfo;
 import org.apache.pig.tools.grunt.Grunt;
@@ -45,14 +47,17 @@ import org.apache.pig.impl.logicalLayer.
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.BufferedReader;
 import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 
 public class TestGrunt {
@@ -1086,6 +1091,32 @@ public class TestGrunt {
             fail();
         }
     }
+    
+    // See PIG-2497
+    @Test
+    public void testShellCommandOrder() throws Throwable {
+        PigServer server = new PigServer(ExecType.LOCAL, new Properties());
+        
+        File inputFile = File.createTempFile("test", "txt");
+        PrintWriter pwInput = new PrintWriter(new FileWriter(inputFile));
+        pwInput.println("1");
+        pwInput.close();
+        
+        File inputScript = File.createTempFile("test", "");
+        File outputFile = File.createTempFile("test", "txt");
+        outputFile.delete();
+        PrintWriter pwScript = new PrintWriter(new FileWriter(inputScript));
+        pwScript.println("a = load '" + inputFile.getAbsolutePath() + "';");
+        pwScript.println("store a into '" + outputFile.getAbsolutePath() + "';");
+        pwScript.println("sh rm -rf " + inputFile.getAbsolutePath());
+        pwScript.close();
+        
+        InputStream inputStream = new FileInputStream(inputScript.getAbsoluteFile());
+        server.setBatchOn();
+        server.registerScript(inputStream);
+        List<ExecJob> execJobs = server.executeBatch();
+        Assert.assertTrue(execJobs.get(0).getStatus() == JOB_STATUS.COMPLETED);
+    }
 
     @Test
     public void testSetPriority() throws Throwable {