pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r1730454 - in /pig/branches/branch-0.15: CHANGES.txt src/org/apache/pig/builtin/PluckTuple.java test/org/apache/pig/builtin/TestPluckTuple.java
Date Mon, 15 Feb 2016 06:27:46 GMT
Author: daijy
Date: Mon Feb 15 06:27:46 2016
New Revision: 1730454

URL: http://svn.apache.org/viewvc?rev=1730454&view=rev
Log:
PIG-4808: PluckTuple overwrites regex if used more than once in the same script

Modified:
    pig/branches/branch-0.15/CHANGES.txt
    pig/branches/branch-0.15/src/org/apache/pig/builtin/PluckTuple.java
    pig/branches/branch-0.15/test/org/apache/pig/builtin/TestPluckTuple.java

Modified: pig/branches/branch-0.15/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.15/CHANGES.txt?rev=1730454&r1=1730453&r2=1730454&view=diff
==============================================================================
--- pig/branches/branch-0.15/CHANGES.txt (original)
+++ pig/branches/branch-0.15/CHANGES.txt Mon Feb 15 06:27:46 2016
@@ -28,6 +28,8 @@ OPTIMIZATIONS
 
 BUG FIXES
 
+PIG-4808: PluckTuple overwrites regex if used more than once in the same script (eval via
daijy)
+
 PIG-4587: Applying isFirstReduceOfKey for Skewed left outer join skips records (rohini)
 
 PIG-4760: TezDAGStats.convertToHadoopCounters is not used, but impose MR counter limit (daijy)

Modified: pig/branches/branch-0.15/src/org/apache/pig/builtin/PluckTuple.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.15/src/org/apache/pig/builtin/PluckTuple.java?rev=1730454&r1=1730453&r2=1730454&view=diff
==============================================================================
--- pig/branches/branch-0.15/src/org/apache/pig/builtin/PluckTuple.java (original)
+++ pig/branches/branch-0.15/src/org/apache/pig/builtin/PluckTuple.java Mon Feb 15 06:27:46
2016
@@ -61,7 +61,7 @@ import com.google.common.collect.Lists;
  */
 public class PluckTuple extends EvalFunc<Tuple> {
     private static final TupleFactory mTupleFactory = TupleFactory.getInstance();
-    private static Pattern pattern;
+    private Pattern pattern;
 
     private boolean isInitialized = false;
     private int[] indicesToInclude;
@@ -85,10 +85,10 @@ public class PluckTuple extends EvalFunc
             Schema inputSchema = getInputSchema();
             for (int i = 0; i < inputSchema.size(); i++) {
                 String alias = inputSchema.getField(i).alias;
-                if ((alias.startsWith(prefix) || pattern.matcher(alias).matches()) &&
this.match) {
+                if (this.match && (alias.startsWith(prefix) || pattern.matcher(alias).matches())
) {
                     indicesToInclude.add(i);
                 }
-                else if (!alias.startsWith(prefix) && !pattern.matcher(alias).matches()
&& !this.match){
+                else if (!this.match && !alias.startsWith(prefix) && !pattern.matcher(alias).matches()
){
                     indicesToInclude.add(i);
                 }
             }
@@ -117,10 +117,10 @@ public class PluckTuple extends EvalFunc
                 } catch (FrontendException e) {
                     throw new RuntimeException(e); // Should never happen
                 }
-                if ((alias.startsWith(prefix) || pattern.matcher(alias).matches()) &&
this.match) {
+                if (this.match && (alias.startsWith(prefix) || pattern.matcher(alias).matches()))
{
                     indicesToInclude.add(i);
                 }
-                else if (!alias.startsWith(prefix) && !pattern.matcher(alias).matches()
&& !this.match){
+                else if (!this.match && !alias.startsWith(prefix) && !pattern.matcher(alias).matches()){
                     indicesToInclude.add(i);
                 }
             }

Modified: pig/branches/branch-0.15/test/org/apache/pig/builtin/TestPluckTuple.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.15/test/org/apache/pig/builtin/TestPluckTuple.java?rev=1730454&r1=1730453&r2=1730454&view=diff
==============================================================================
--- pig/branches/branch-0.15/test/org/apache/pig/builtin/TestPluckTuple.java (original)
+++ pig/branches/branch-0.15/test/org/apache/pig/builtin/TestPluckTuple.java Mon Feb 15 06:27:46
2016
@@ -122,6 +122,29 @@ public class TestPluckTuple {
     }
 
     @Test
+    public void testTwoPluckTuples() throws Exception {
+        Data data = resetData(pigServer);
+
+        data.set("a",
+            Utils.getSchemaFromString("xa:int,yb:chararray,zc:long"),
+            tuple(1, "hey", 3L),
+            tuple(2, "woah", 4L)
+            );
+
+        String query = "a = load 'a' using mock.Storage();" +
+            "define pluck1 PluckTuple('.a');" +
+            "define pluck2 PluckTuple('.b');" +
+            "b = foreach a generate flatten(pluck1(*)), flatten(pluck2(*));";
+        pigServer.registerQuery(query);
+        Iterator<Tuple> it = pigServer.openIterator("b");
+        assertTrue(it.hasNext());
+        assertEquals(tuple(1,"hey"), it.next());
+        assertTrue(it.hasNext());
+        assertEquals(tuple(2,"woah"), it.next());
+        assertFalse(it.hasNext());
+    }
+
+    @Test
     public void testNegativeOutput() throws Exception {
         Data data = resetData(pigServer);
 



Mime
View raw message