PIG-5403: streaming job stuck with script failure when combined with ORDER BY (knoguchi)


git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1881193 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index e55dcf2..8335156 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -100,6 +100,8 @@
  
 BUG FIXES
 
+PIG-5403: streaming job stuck with script failure when combined with ORDER BY (knoguchi)
+
 PIG-5362: Parameter substitution of shell cmd results doesn't handle backslash addendum (szita)
 
 PIG-5395: Pig build is failing due to maven repo access point change (szita)
diff --git a/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POReservoirSample.java b/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POReservoirSample.java
index dc4c188..437849a 100644
--- a/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POReservoirSample.java
+++ b/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POReservoirSample.java
@@ -103,7 +103,9 @@
         Result res = null;
         while (rowProcessed < numSamples) {
             res = processInput();
-            if (res.returnStatus == POStatus.STATUS_OK) {
+            if (res.returnStatus == POStatus.STATUS_ERR) {
+              return res;
+            } else if (res.returnStatus == POStatus.STATUS_OK) {
                 samples[(int)rowProcessed] = res;
                 rowProcessed++;
             } else if (res.returnStatus == POStatus.STATUS_NULL) {
@@ -125,7 +127,9 @@
             while (true) {
                 // pick this as sample
                 res = processInput();
-                if (res.returnStatus == POStatus.STATUS_NULL) {
+                if (res.returnStatus == POStatus.STATUS_ERR) {
+                  return res;
+                } else if (res.returnStatus == POStatus.STATUS_NULL) {
                     continue;
                 } else if (res.returnStatus != POStatus.STATUS_OK) {
                     break;
diff --git a/test/e2e/pig/tests/negative.conf b/test/e2e/pig/tests/negative.conf
index d09a661..c159d1b 100644
--- a/test/e2e/pig/tests/negative.conf
+++ b/test/e2e/pig/tests/negative.conf
@@ -457,7 +457,7 @@
 store B into ':OUTPATH:';\,
                         'expected_err_regex' => "failed with exit status: 2",
                         },
-			{
+			                  {
                         'num' => 5,
 			'execonly' => 'mapred,tez',
                         'pig' => q\
@@ -470,6 +470,17 @@
 store C into ':OUTPATH:.2';\,
                         'expected_err_regex' => "failed with exit status: 1|Error while reading from POStream and passing it to the streaming",
                         },
+			                  {
+                        'num' => 6,
+			'execonly' => 'mapred,tez',
+                        'pig' => q\
+define BADCMD `perl PigStreamingBad.pl middle` ship(':SCRIPTHOMEPATH:/PigStreamingBad.pl');
+A = load ':INPATH:/singlefile/studenttab10k';
+B = stream A through BADCMD;
+C = ORDER B by *;
+store C into ':OUTPATH:.1';\,
+                        'expected_err_regex' => "failed with exit status: 2|Error while reading from POStream and passing it to the streaming",
+                        },
 
                 ]
 		},