pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject svn commit: r1208931 - in /pig/branches/branch-0.10: CHANGES.txt src/org/apache/pig/builtin/STRSPLIT.java test/e2e/pig/tests/nightly.conf
Date Thu, 01 Dec 2011 02:07:39 GMT
Author: olga
Date: Thu Dec  1 02:07:38 2011
New Revision: 1208931

URL: http://svn.apache.org/viewvc?rev=1208931&view=rev
Log:
PIG-2311: STRSPLIT needs to allow bytearray arguments (xuting via olgan)

Modified:
    pig/branches/branch-0.10/CHANGES.txt
    pig/branches/branch-0.10/src/org/apache/pig/builtin/STRSPLIT.java
    pig/branches/branch-0.10/test/e2e/pig/tests/nightly.conf

Modified: pig/branches/branch-0.10/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/CHANGES.txt?rev=1208931&r1=1208930&r2=1208931&view=diff
==============================================================================
--- pig/branches/branch-0.10/CHANGES.txt (original)
+++ pig/branches/branch-0.10/CHANGES.txt Thu Dec  1 02:07:38 2011
@@ -24,6 +24,8 @@ INCOMPATIBLE CHANGES
 
 IMPROVEMENTS
 
+PIG-2311: STRSPLIT needs to allow bytearray arguments (xuting via olgan)
+
 PIG-2300: Pig Docs - release 0.10.0 (and 0.9.1) (chandec via daijy)
 
 PIG-2230: Improved error message for invalid parameter format (xuitingz via olgan)

Modified: pig/branches/branch-0.10/src/org/apache/pig/builtin/STRSPLIT.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/src/org/apache/pig/builtin/STRSPLIT.java?rev=1208931&r1=1208930&r2=1208931&view=diff
==============================================================================
--- pig/branches/branch-0.10/src/org/apache/pig/builtin/STRSPLIT.java (original)
+++ pig/branches/branch-0.10/src/org/apache/pig/builtin/STRSPLIT.java Thu Dec  1 02:07:38
2011
@@ -20,12 +20,19 @@ package org.apache.pig.builtin;
 import java.io.IOException;
 
 import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.regex.PatternSyntaxException;
 
 import org.apache.pig.EvalFunc;
 import org.apache.pig.PigWarning;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.FuncSpec;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+
 
 /**
  * Wrapper around Java's String.split<br>
@@ -70,4 +77,36 @@ public class STRSPLIT extends EvalFunc<T
         // this only happens if the try block did not complete normally
         return null;
     }
+    
+    /*
+     * The outputSchema of STRSPLIT cannot be set as DataType.chararry otherwise in some
cases,
+     * it will cause error. For example, when stringsize() is called.
+    */
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.TUPLE)); 
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.pig.EvalFunc#getArgToFuncMapping()
+     */
+    @Override
+    public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
+        List<FuncSpec> funcList = new ArrayList<FuncSpec>();
+        Schema s = new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY)); 
+        
+        Schema s1 = new Schema();
+        s1.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        s1.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        
+        Schema s2 = new Schema();
+        s2.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        s2.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        s2.add(new Schema.FieldSchema(null, DataType.INTEGER));
+        
+        funcList.add(new FuncSpec(this.getClass().getName(), s));
+        funcList.add(new FuncSpec(this.getClass().getName(), s1));
+        funcList.add(new FuncSpec(this.getClass().getName(), s2));
+        return funcList;
+    }
 }

Modified: pig/branches/branch-0.10/test/e2e/pig/tests/nightly.conf
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.10/test/e2e/pig/tests/nightly.conf?rev=1208931&r1=1208930&r2=1208931&view=diff
==============================================================================
--- pig/branches/branch-0.10/test/e2e/pig/tests/nightly.conf (original)
+++ pig/branches/branch-0.10/test/e2e/pig/tests/nightly.conf Thu Dec  1 02:07:38 2011
@@ -3981,7 +3981,24 @@ store E into ':OUTPATH:';\, 
                                  store C into ':OUTPATH:';?,
                      }
                  ],
-             }
+             },{
+             'name' => 'STRSPLIT',
+             'tests' => [
+                 {
+                     # See PIG-2311
+                     'num' => 1,
+                     'pig' => q?a = load ':INPATH:/singlefile/studenttab10k' AS (a0);
+                     		b= filter a by NOT (a0 is null);
+                     		c= foreach b generate STRSPLIT(a0);
+                             store c into ':OUTPATH:';?,
+                     'verify_pig_script' => q?a = load ':INPATH:/singlefile/studenttab10k'
AS (a0);
+                     		b= filter a by NOT (a0 is null);
+                     		b= foreach b generate (chararray)a0 as a0 ;
+                     		c= foreach b generate STRSPLIT(a0);
+                             store c into ':OUTPATH:';?,
+                 }
+             ],
+          },//
         ],
     },
 ;



Mime
View raw message