Author: dvryaboy
Date: Tue Mar  9 23:37:13 2010
New Revision: 921185

URL: http://svn.apache.org/viewvc?rev=921185&view=rev
Log:
PIG-1248: add missing files for this patch.

Added:
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LENGTH.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LcFirst.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/RegexExtractAll.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Reverse.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Split.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Trim.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UcFirst.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestLength.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestReverse.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestSplit.java
    
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestUcFirst.java

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LENGTH.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LENGTH.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LENGTH.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LENGTH.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+ * string.LENGTH implements eval function to find length of a string
+ * Example:
+ *      register piggybank.jar;
+ *      A = load 'mydata' as (name);
+ *      B = foreach A generate string.LENGTH(name);
+ *      dump B;
+ */
+public class LENGTH extends EvalFunc<Integer> {
+
+    @Override
+    public Integer exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0) {
+            return null;
+        }
+        try {
+            String str = (String) input.get(0);
+            return (str == null) ? null : str.length();
+        } catch (ExecException e) {
+            log.warn("Error reading input: " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.INTEGER));
+    }
+
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LcFirst.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LcFirst.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LcFirst.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/LcFirst.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,35 @@
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/** 
+ * lower-case the first character of a string 
+ */
+public class LcFirst extends EvalFunc<String> {
+    @Override
+    public String exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0) {
+            return null;
+        }
+        try {
+            String str = (String) input.get(0);
+            if (str == null) return null;
+            if (str.length() == 0) return str;
+            return Character.toLowerCase(str.charAt(0))+str.substring(1);
+        } catch (ExecException e) {
+            log.warn("Error reading input: " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/RegexExtractAll.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/RegexExtractAll.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/RegexExtractAll.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/RegexExtractAll.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.FuncSpec;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+ * <dl>
+ * <dt><b>Syntax:</b></dt>
+ * <dd><code>String RegexExtractAll(String expression, String 
regex)</code>.</dd>
+ * <dt><b>Input:</b></dt>
+ * <dd><code>expression</code>-<code>source string</code>.</dd>
+ * <dd><code>regex</code>-<code>regular expression</code>.</dd>
+ * <dt><b>Output:</b></dt>
+ * <dd><code>A tuple of matched strings</code>.</dd>
+ * </dl>
+ */
+
+public class RegexExtractAll extends EvalFunc<Tuple> {
+
+    private static TupleFactory tupleFactory = TupleFactory.getInstance();
+
+    @Override
+    public Tuple exec(Tuple input) throws IOException {
+        if (input.size()!=2) {
+            String msg = "RegexExtractAll : Only 2 parameters are allowed.";
+            throw new IOException(msg);
+        }
+
+        if (input.get(0)==null)
+            return null;
+        try {
+            if (!input.get(1).equals(mExpression)) {
+                try {
+                    mExpression = (String)input.get(1);
+                    mPattern = Pattern.compile(mExpression);
+                } catch (Exception e) {
+                    String msg = "RegexExtractAll : Mal-Formed Regular 
expression : "+input.get(1);
+                    throw new IOException(msg);
+                }
+            }
+        } catch (NullPointerException e) {
+            String msg = "RegexExtractAll : Regular expression is null";
+            throw new IOException(msg);
+        }
+
+        Matcher m = mPattern.matcher((String)input.get(0));
+        if (!m.matches()) {
+            return null;
+        }
+        Tuple result = tupleFactory.newTuple(m.groupCount());
+        for (int i = 0; i< m.groupCount(); i++) {
+            result.set(i, m.group(i+1));
+        }
+        return result;
+    }
+
+    String mExpression = null;
+    Pattern mPattern = null; 
+    @Override
+    public Schema outputSchema(Schema input) {
+        try {
+            return new Schema(new 
Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), 
input), 
+                    DataType.TUPLE));
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    @Override
+    public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
+        List<FuncSpec> funcList = new ArrayList<FuncSpec>();
+        Schema s = new Schema();
+        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        s.add(new Schema.FieldSchema(null, DataType.CHARARRAY));
+        funcList.add(new FuncSpec(this.getClass().getName(), s));
+        return funcList;
+    } 
+}
+

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Reverse.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Reverse.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Reverse.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Reverse.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,42 @@
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/*
+ * reverses a string.
+ */
+public class Reverse extends EvalFunc<String> {
+    @Override
+    public String exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0) {
+            return null;
+        }
+        try {
+            String str = (String) input.get(0);
+            if (str == null) return null;
+            if (str.length() == 0) return str;
+            char[] chars = str.toCharArray();
+            int lastIndex = chars.length-1;
+            for (int i=0; i<=lastIndex/2; i++) {
+                char c = chars[i];
+                chars[i] = chars[lastIndex-i];
+                chars[lastIndex-i] = c;
+            }
+            return new String(chars);
+        } catch (ExecException e) {
+            log.warn("Error reading input: " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Split.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Split.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Split.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Split.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,54 @@
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import java.util.Arrays;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+
+/**
+ * Wrapper around Java's String.split<br>
+ * input tuple: first column is assumed to have a string to split;<br>
+ * the optional second column is assumed to have the delimiter or regex to 
split on;<br>
+ * if not provided, it's assumed to be '\s' (space)<br>
+ * the optional third column may provide a limit to the number of results.<br>
+ * If limit is not provided, 0 is assumed, as per Java's split().
+ */
+
+public class Split extends EvalFunc<Tuple> {
+
+    private final static TupleFactory tupleFactory = 
TupleFactory.getInstance();
+
+    /**
+     * Wrapper around Java's String.split
+     * @param input tuple; first column is assumed to have a string to split;
+     * the optional second column is assumed to have the delimiter or regex to 
split on;<br>
+     * if not provided, it's assumed to be '\s' (space)
+     * the optional third column may provide a limit to the number of 
results.<br>
+     * If limit is not provided, 0 is assumed, as per Java's split().
+     * @exception java.io.IOException
+     */
+    public Tuple exec(Tuple input) throws IOException {
+        if (input == null || input.size() < 1)
+            return null;
+        try {
+            String source = (String) input.get(0);
+            String delim = (input.size() > 1 ) ? (String) input.get(1) : "\\s";
+            int length = (input.size() > 2) ? (Integer) input.get(2) : 0;
+            if (source == null || delim == null) {
+                return null;
+            }
+            String[] splits = source.split(delim, length); 
+            return tupleFactory.newTuple(Arrays.asList(splits));
+        } catch (ClassCastException e) {
+            log.warn("class cast exception at "+e.getStackTrace()[0]);
+        } catch (PatternSyntaxException e) {
+            log.warn(e.getMessage());
+        }
+        // this only happens if the try block did not complete normally
+        return null;
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Trim.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Trim.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Trim.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/Trim.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,35 @@
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/*
+ * @see String.trim
+ */
+public class Trim extends EvalFunc<String> {
+    @Override
+    public String exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0) {
+            return null;
+        }
+        try {
+            String str = (String) input.get(0);
+            if (str == null) return null;
+            if (str.length() == 0) return str;
+            return str.trim();
+        } catch (ExecException e) {
+            log.warn("Error reading input: " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UcFirst.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UcFirst.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UcFirst.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UcFirst.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,35 @@
+package org.apache.pig.piggybank.evaluation.string;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/** 
+ * upper-case the first character of a string 
+ */
+public class UcFirst extends EvalFunc<String> {
+    @Override
+    public String exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0) {
+            return null;
+        }
+        try {
+            String str = (String) input.get(0);
+            if (str == null) return null;
+            if (str.length() == 0) return str;
+            return Character.toUpperCase(str.charAt(0))+str.substring(1);
+        } catch (ExecException e) {
+            log.warn("Error reading input: " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestLength.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestLength.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestLength.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestLength.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,30 @@
+package org.apache.pig.piggybank.test.evaluation.string;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.string.LENGTH;
+import org.junit.Test;
+
+public class TestLength {
+
+    private static final EvalFunc<Integer> len_ = new LENGTH();
+    private static Tuple testTuple_ = TupleFactory.getInstance().newTuple(1);
+    
+    @Test
+    public void testLength() throws IOException {
+        testTuple_.set(0,"foo");
+        assertEquals("regular length should match", (Integer) 3, 
len_.exec(testTuple_));
+        
+        testTuple_.set(0, null);
+        assertNull("length of null is null", len_.exec(testTuple_));
+        
+        testTuple_.set(0, "");
+        assertEquals("empty string has 0 length", (Integer) 0, 
len_.exec(testTuple_));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestReverse.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestReverse.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestReverse.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestReverse.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,22 @@
+package org.apache.pig.piggybank.test.evaluation.string;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.string.Reverse;
+import org.junit.Test;
+
+public class TestReverse {
+    private static final EvalFunc<String> rev_ = new Reverse();
+    private static Tuple testTuple_ = TupleFactory.getInstance().newTuple(1);
+    
+    @Test
+    public void testLength() throws IOException {
+        testTuple_.set(0,"fos");
+        assertEquals("regular length should match", "sof", 
rev_.exec(testTuple_));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestSplit.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestSplit.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestSplit.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestSplit.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,59 @@
+package org.apache.pig.piggybank.test.evaluation.string;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.string.Split;
+import org.junit.Test;
+
+public class TestSplit {
+
+
+    private static final Split splitter_ = new Split();
+    private static Tuple test1_ = TupleFactory.getInstance().newTuple(1);
+    private static Tuple test2_ = TupleFactory.getInstance().newTuple(2);
+    private static Tuple test3_ = TupleFactory.getInstance().newTuple(3);
+    
+    @Test 
+    public void testSplit() throws IOException {
+       // test no delims
+        test2_.set(0, "foo");
+        test2_.set(1, ":");
+        Tuple splits = splitter_.exec(test2_);
+        assertEquals("no matches should return tuple with original string", 1, 
splits.size());
+        assertEquals("no matches should return tuple with original string", 
"foo", 
+                splits.get(0));
+        
+        // test default delimiter
+        test1_.set(0, "f ooo bar");
+        splits = splitter_.exec(test1_);
+        assertEquals("split on default value ", 3, splits.size());
+        assertEquals("f", splits.get(0));
+        assertEquals("ooo", splits.get(1));
+        assertEquals("bar", splits.get(2));
+        
+        // test trimming of whitespace
+        test1_.set(0, "foo bar  ");
+        splits = splitter_.exec(test1_);
+        assertEquals("whitespace trimmed if no length arg", 2, splits.size());
+        
+        // test forcing null matches with length param
+        test3_.set(0, "foo bar   ");
+        test3_.set(1, "\\s");
+        test3_.set(2, 10);
+        splits = splitter_.exec(test3_);
+        assertEquals("length forces empty string matches on end", 5, 
splits.size());
+        
+        // test limiting results with limit
+        test3_.set(0, "foo:bar:baz");
+        test3_.set(1, ":");
+        test3_.set(2, 2);
+        splits = splitter_.exec(test3_);
+        assertEquals(2, splits.size());
+        assertEquals("foo", splits.get(0));
+        assertEquals("bar:baz", splits.get(1));
+    }
+}

Added: 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestUcFirst.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestUcFirst.java?rev=921185&view=auto
==============================================================================
--- 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestUcFirst.java
 (added)
+++ 
hadoop/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/string/TestUcFirst.java
 Tue Mar  9 23:37:13 2010
@@ -0,0 +1,34 @@
+package org.apache.pig.piggybank.test.evaluation.string;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.piggybank.evaluation.string.UcFirst;
+import org.junit.Test;
+
+public class TestUcFirst {
+
+    private static final EvalFunc<String> ucf_ = new UcFirst();
+    private static Tuple testTuple_ = TupleFactory.getInstance().newTuple(1);
+    
+    @Test
+    public void testUcFirst() throws IOException {
+        testTuple_.set(0,null);
+        assertNull("null is null", ucf_.exec(testTuple_));
+        
+        testTuple_.set(0, "");
+        assertEquals("empty string", "", ucf_.exec(testTuple_));
+        
+        testTuple_.set(0, "foo");
+        assertEquals("lowercase string", "Foo", ucf_.exec(testTuple_));
+        
+        testTuple_.set(0, "Foo");
+        assertEquals("uppercase string", "Foo", ucf_.exec(testTuple_));
+    }
+
+}


Reply via email to