PIG-5031: Tez failing to compile when replicate join is done with a limit vertex on left (knoguchi)


git-svn-id: https://svn.apache.org/repos/asf/pig/trunk@1760601 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index a30ae10..3982473 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -46,6 +46,8 @@
  
 BUG FIXES
 
+PIG-5031: Tez failing to compile when replicate join is done with a limit vertex on left (knoguchi)
+
 PIG-5019: Pig generates tons of warnings for udf with enabled warnings aggregation (murshyd via rohini)
 
 PIG-4974: A simple map reference fail to cast (knoguchi)
diff --git a/src/org/apache/pig/backend/hadoop/executionengine/tez/plan/TezCompiler.java b/src/org/apache/pig/backend/hadoop/executionengine/tez/plan/TezCompiler.java
index 46f7f72..9395749 100644
--- a/src/org/apache/pig/backend/hadoop/executionengine/tez/plan/TezCompiler.java
+++ b/src/org/apache/pig/backend/hadoop/executionengine/tez/plan/TezCompiler.java
@@ -849,6 +849,7 @@
             } else {
                 curTezOp.plan.addAsLeaf(op);
             }
+            phyToTezOpMap.put(op, curTezOp);
 
         } catch (Exception e) {
             int errCode = 2034;
diff --git a/test/org/apache/pig/test/data/GoldenFiles/tez/TEZC-Limit-4.gld b/test/org/apache/pig/test/data/GoldenFiles/tez/TEZC-Limit-4.gld
new file mode 100644
index 0000000..4ccfb85
--- /dev/null
+++ b/test/org/apache/pig/test/data/GoldenFiles/tez/TEZC-Limit-4.gld
@@ -0,0 +1,61 @@
+#--------------------------------------------------
+# There are 1 DAGs in the session
+#--------------------------------------------------
+#--------------------------------------------------
+# TEZ DAG plan: pig-0_scope-0
+#--------------------------------------------------
+Tez vertex scope-42	->	Tez vertex scope-39,
+Tez vertex scope-32	->	Tez vertex scope-39,
+Tez vertex scope-39
+
+Tez vertex scope-42
+# Plan on vertex
+Local Rearrange[tuple]{int}(false) - scope-28	->	 scope-39
+|   |
+|   Project[int][0] - scope-24
+|
+|---b: New For Each(false,false)[bag] - scope-22
+    |   |
+    |   Cast[int] - scope-17
+    |   |
+    |   |---Project[bytearray][0] - scope-16
+    |   |
+    |   Cast[int] - scope-20
+    |   |
+    |   |---Project[bytearray][1] - scope-19
+    |
+    |---b: Load(file:///tmp/input:org.apache.pig.builtin.PigStorage) - scope-15
+Tez vertex scope-32
+# Plan on vertex
+a: Split - scope-43
+|   |
+|   a: Store(file:///tmp/pigoutput/a:org.apache.pig.builtin.PigStorage) - scope-11
+|   |
+|   POValueOutputTez - scope-38	->	 [scope-39]
+|   |
+|   |---c: Limit - scope-14
+|
+|---a: New For Each(false,false)[bag] - scope-7
+    |   |
+    |   Cast[int] - scope-2
+    |   |
+    |   |---Project[bytearray][0] - scope-1
+    |   |
+    |   Cast[int] - scope-5
+    |   |
+    |   |---Project[bytearray][1] - scope-4
+    |
+    |---a: Load(file:///tmp/input:org.apache.pig.builtin.PigStorage) - scope-0
+Tez vertex scope-39
+# Plan on vertex
+d: Store(file:///tmp/pigoutput/d:org.apache.pig.builtin.PigStorage) - scope-31
+|
+|---d: FRJoin[tuple] - scope-25	<-	 scope-42
+    |   |
+    |   Project[int][0] - scope-23
+    |   |
+    |   Project[int][0] - scope-24
+    |
+    |---c: Limit - scope-41
+        |
+        |---POValueInputTez - scope-40	<-	 scope-32
diff --git a/test/org/apache/pig/tez/TestTezCompiler.java b/test/org/apache/pig/tez/TestTezCompiler.java
index b238975..428b16e 100644
--- a/test/org/apache/pig/tez/TestTezCompiler.java
+++ b/test/org/apache/pig/tez/TestTezCompiler.java
@@ -353,6 +353,19 @@
     }
 
     @Test
+    public void testLimitReplJoin() throws Exception {
+        String query =
+                "a = load 'file:///tmp/input' as (x:int, y:int);" +
+                "b = load 'file:///tmp/input' as (x:int, y:int);" +
+                "c = limit a 1;" +
+                "d = join c by x, b by x using 'replicated';" +
+                "store a into 'file:///tmp/pigoutput/a';" +
+                "store d into 'file:///tmp/pigoutput/d';";
+
+        run(query, "test/org/apache/pig/test/data/GoldenFiles/tez/TEZC-Limit-4.gld");
+    }
+
+    @Test
     public void testDistinct() throws Exception {
         String query =
                 "a = load 'file:///tmp/input' as (x:int, y:int);" +