pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject svn commit: r957100 [1/2] - in /hadoop/pig/trunk: ./ src/org/apache/pig/builtin/ test/org/apache/pig/test/
Date Wed, 23 Jun 2010 03:37:13 GMT
Author: daijy
Date: Wed Jun 23 03:37:11 2010
New Revision: 957100

URL: http://svn.apache.org/viewvc?rev=957100&view=rev
Log:
PIG-1405: Need to move many standard functions from piggybank into Pig

Added:
    hadoop/pig/trunk/src/org/apache/pig/builtin/ABS.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/ACOS.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/ASIN.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/ATAN.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/Base.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/CBRT.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/CEIL.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/COR.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/COS.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/COSH.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/COV.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleAbs.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleBase.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleRound.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/EXP.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/FLOOR.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/FloatAbs.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/FloatRound.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/INDEXOF.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/IntAbs.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LAST_INDEX_OF.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LCFIRST.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LOG.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LOG10.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LOWER.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/LongAbs.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT_ALL.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/REPLACE.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/ROUND.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/SIN.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/SINH.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/SPLIT.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/SQRT.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/SUBSTRING.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TAN.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TANH.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TOBAG.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TOP.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TOTUPLE.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/TRIM.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/UCFIRST.java
    hadoop/pig/trunk/src/org/apache/pig/builtin/UPPER.java
Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/test/org/apache/pig/test/TestBuiltin.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=957100&r1=957099&r2=957100&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Wed Jun 23 03:37:11 2010
@@ -24,6 +24,9 @@ INCOMPATIBLE CHANGES
 
 IMPROVEMENTS
 
+PIG-1405: Need to move many standard functions from piggybank into Pig
+(aniket486 via daijy)
+
 PIG-1427: Monitor and kill runaway UDFs (dvryaboy)
 
 PIG-1428: Make a StatusReporter singleton available for incrementing counters (dvryaboy)

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/ABS.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/ABS.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/ABS.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/ABS.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,80 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.FuncSpec;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+
+/**
+ * ABS implements a binding to the Java function
+ * {@link java.lang.Math#abs(double) Math.abs(double)} for computing the
+ * absolute value of the argument. The returned value will be a double which is 
+ * absolute value of the input.
+ */
+public class ABS extends EvalFunc<Double>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, absolute value of the argument
+	 */
+	public Double exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        Double d;
+        try{
+            d = DataType.toDouble(input.get(0));
+        } catch (NumberFormatException nfe){
+            System.err.println("Failed to process input; error - " + nfe.getMessage());
+            return null;
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+
+		return Math.abs(d);
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.DOUBLE));
+	}
+
+    /* (non-Javadoc)
+     * @see org.apache.pig.EvalFunc#getArgToFuncMapping()
+     */
+    @Override
+    public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
+        List<FuncSpec> funcList = new ArrayList<FuncSpec>();
+        funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.BYTEARRAY))));
+        funcList.add(new FuncSpec(DoubleAbs.class.getName(),  new Schema(new Schema.FieldSchema(null, DataType.DOUBLE))));
+        funcList.add(new FuncSpec(FloatAbs.class.getName(),   new Schema(new Schema.FieldSchema(null, DataType.FLOAT))));
+        funcList.add(new FuncSpec(IntAbs.class.getName(),  new Schema(new Schema.FieldSchema(null, DataType.INTEGER))));
+        funcList.add(new FuncSpec(LongAbs.class.getName(),  new Schema(new Schema.FieldSchema(null, DataType.LONG))));
+        return funcList;
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/ACOS.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/ACOS.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/ACOS.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/ACOS.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,34 @@
+/*
+ * 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.builtin;
+
+/**
+ * ACOS implements a binding to the Java function
+ * {@link java.lang.Math#acos(double) Math.acos(double)} for computing the
+ * arc cosine of value of the argument. The returned value will be a double which is 
+ * the arc cosine of the value of  input.
+ * 
+ */
+public class ACOS extends DoubleBase{
+	
+	Double compute(Double input){
+		return Math.acos(input);
+		
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/ASIN.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/ASIN.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/ASIN.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/ASIN.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * ASIN implements a binding to the Java function
+ * {@link java.lang.Math#asin(double) Math.asin(double)} for computing the
+ * arc sine of value of the argument. The returned value will be a double which is 
+ * the arc sine of the value of  input.
+ *
+ */
+public class ASIN extends DoubleBase{
+	Double compute(Double input){
+		return Math.asin(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/ATAN.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/ATAN.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/ATAN.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/ATAN.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * ATAN implements a binding to the Java function
+ * {@link java.lang.Math#atan(double) Math.atan(double)} for computing the
+ * arc tangent of value of the argument. The returned value will be a double which is 
+ * the arc tangent of the value of  input.
+ * 
+ */
+public class ATAN extends DoubleBase{
+	Double compute(Double input){
+		return Math.atan(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/Base.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/Base.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/Base.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/Base.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.builtin;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+/**
+ * base class for math udfs
+ */
+public abstract class Base extends EvalFunc<Double>{
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.DOUBLE));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/CBRT.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/CBRT.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/CBRT.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/CBRT.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * CBRT implements a binding to the Java function
+ * {@link java.lang.Math#cbrt(double) Math.cbrt(double)} for computing the
+ * cube root of the argument. The returned value will be a double which is 
+ * cube root value of the input.
+ */
+public class CBRT extends DoubleBase{
+	Double compute(Double input){
+		return Math.cbrt(input);
+		
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/CEIL.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/CEIL.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/CEIL.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/CEIL.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * CEIL implements a binding to the Java function
+ * {@link java.lang.Math#ceil(double) Math.ceil(double)}. Given a single 
+ * data atom it  Returns the smallest (closest to negative infinity) 
+ * double value that is greater than or equal  to the argument and is equal 
+ * to a mathematical integer.
+ */
+public class CEIL extends DoubleBase{
+	Double compute(Double input){
+		return Math.ceil(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/COR.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/COR.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/COR.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/COR.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,347 @@
+/*
+ * 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.builtin;
+
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.apache.pig.Algebraic;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.DefaultBagFactory;
+import org.apache.pig.data.DefaultTupleFactory;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+* Computes the correlation between sets of data.  The returned value 
+* will be a bag which will contain a tuple for each combination of input 
+* schema and inside tuple we will have two schema name and correlation between 
+* those  two schemas. 
+* 
+* A = load 'input.xml' using PigStorage(':');<br/>
+* B = group A all;<br/>
+* D = foreach B generate group,COR(A.$0,A.$1,A.$2);<br/>
+*/
+
+public class COR extends EvalFunc<DataBag> implements Algebraic {
+    //name of the schemas. Initialize when user use define
+    protected Vector<String>schemaName = new Vector<String>();
+    //flag to indicate if define is called or not. 
+    private boolean flag = false;
+    
+    public COR(){}
+    
+    public COR(String... schemaName){
+        for(int i=0;i<schemaName.length;i++){
+            this.schemaName.add(schemaName[i]);
+            flag = true;
+        }
+    }
+    
+    /**
+     * Function to compute correlation between data sets.
+     * @param input input tuple which contains data sets.
+     * @return output output dataBag which contain correlation between each pair of data sets. 
+     */
+    @Override
+    public DataBag exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
+        for(int i=0;i<input.size();i++){
+            for(int j=i+1;j<input.size();j++){
+                Tuple temp = DefaultTupleFactory.getInstance().newTuple(3);
+                try{
+                    if(flag){
+                        temp.set(0, schemaName.elementAt(i));
+                        temp.set(1, schemaName.elementAt(j));
+                    }
+                    else{
+                        temp.set(0, "var"+i);
+                        temp.set(1, "var"+j);
+                    }
+                
+                    Tuple tempResult = computeAll((DataBag)input.get(i),(DataBag)input.get(j));
+                    double size = ((DataBag)input.get(i)).size();
+                    double sum_x_y = (Double)tempResult.get(0);
+                    double sum_x = (Double)tempResult.get(1);
+                    double sum_y = (Double)tempResult.get(2);
+                    double sum_x_square = (Double)tempResult.get(3);
+                    double sum_y_square = (Double)tempResult.get(4);
+                    double result = (size*sum_x_y - sum_x*sum_y)/Math.sqrt((size*sum_x_square-sum_x*sum_x)*(size*sum_y_square-sum_y*sum_y));
+                    temp.set(2, result);
+                }catch (Exception e){
+                    System.err.println("Failed to process input record; error - " + e.getMessage());
+                    return null;
+                }
+                output.add(temp);
+            }
+        }
+
+        return output;
+    }
+    
+   //used to pass schema name to Final class constructor 
+    /**
+     * Function to return argument of constructor as string. It append ( and ) at starting and end or argument respectively. 
+     * If default constructor is called is returns empty string.
+     * @return argument of constructor
+     */
+    @Override
+    public String toString() {
+        if(flag){
+            StringBuilder sb = new StringBuilder();
+            sb.append('(');
+            if(schemaName!=null){
+                for (String sch : schemaName) {
+                    sb.append('\'' + sch + '\'' + ",");
+                }
+                sb.deleteCharAt(sb.length()-1);
+            }
+            sb.append(')');
+            return sb.toString();
+        }
+        else return "";
+    }
+    
+    public String getInitial() {
+        return Initial.class.getName();
+    }
+
+    public String getIntermed() {
+        return Intermed.class.getName();
+    }
+
+    public String getFinal() {
+        return Final.class.getName() + toString();
+    }
+
+    static public class Initial extends EvalFunc<Tuple> {
+        @Override
+        public Tuple exec(Tuple input) throws IOException {
+            if (input == null || input.size() == 0)
+                return null;
+            Tuple output = DefaultTupleFactory.getInstance().newTuple(input.size() * 2); 
+            try {
+                int k = -1;
+                for(int i=0;i<input.size();i++){
+                    for(int j=i+1;j<input.size();j++){
+                        DataBag first = (DataBag)input.get(i);
+                        DataBag second = (DataBag)input.get(j);
+                        output.set(k++, computeAll(first, second));
+                        output.set(k++, (Long)first.size());
+                    }
+                }
+            } catch(Exception t) {
+                System.err.println("Failed to process input record; error - " + t.getMessage());
+                return null;
+            }
+            return output;    
+        }
+    } 
+
+    static public class Intermed extends EvalFunc<Tuple> {
+        
+        @Override
+        public Tuple exec(Tuple input) throws IOException {
+            if (input == null || input.size() == 0)
+                return null;
+            try{
+                return combine((DataBag)input.get(0));
+            }catch(Exception e){
+                throw new IOException("Caught exception in COR.Intermed", e);
+            }
+        }
+    }
+
+    public static class Final extends EvalFunc<DataBag> {
+        protected Vector<String>schemaName = new Vector<String>();
+        boolean flag = false;
+        public Final(){}
+        public Final(String... schemaName){
+            for(int i=0;i<schemaName.length;i++){
+                this.schemaName.add(schemaName[i]);
+                flag = true;
+            }
+        }
+
+        @Override
+        public DataBag exec(Tuple input) throws IOException {
+            if (input == null || input.size() == 0)
+                return null;
+
+            Tuple combined;    
+            try{
+                combined = combine((DataBag)input.get(0));    
+            }catch(Exception e){
+                throw new IOException("Caught exception in COR.Final", e);
+            }
+            int count = 0;
+            //for each pair of input schema combined contain 2 member. first member
+            //is tuple containing sum_x,sum_y,sum_x_y, sum_x_square, sum_y_square
+            //and second is number of tuples from which it is calculated . 
+            //So if arity of combined is n then total number of schemas would be 
+            //root of x*x - x - n =0 
+            int totalSchemas=2;
+            while(totalSchemas*(totalSchemas-1)<combined.size()){
+                totalSchemas++;
+            } 
+                
+            DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
+            for(int i=0;i<totalSchemas;i++){
+                for(int j=i+1;j<totalSchemas;j++){
+                    Tuple result = DefaultTupleFactory.getInstance().newTuple(3);
+                    try{
+                        if(flag){
+                            result.set(0, schemaName.elementAt(i));
+                            result.set(1, schemaName.elementAt(j));
+                        } 
+                        else{
+                            result.set(0, "var"+i);
+                            result.set(1, "var"+j);
+                        }
+                        Tuple tup = (Tuple)combined.get(count);
+                        double tempCount = (Double)combined.get(count+1);
+                        double sum_x_y = (Double)tup.get(0);
+                        double sum_x = (Double)tup.get(1);
+                        double sum_y = (Double)tup.get(2);
+                        double sum_x_square = (Double)tup.get(3);
+                        double sum_y_square = (Double)tup.get(4);
+                        double correl = (tempCount*sum_x_y - sum_x*sum_y)/Math.sqrt((tempCount*sum_x_square-sum_x*sum_x)*(tempCount*sum_y_square-sum_y*sum_y));
+                        result.set(2, correl);
+                    }catch(Exception e){
+                        System.err.println("Failed to process input record; error - " + e.getMessage());
+                        return null;
+                    } 
+                    output.add(result);
+                    count+=2;
+                }
+            }
+
+            return output;
+        }
+    }
+
+    /**
+     * combine results of different data chunk 
+     * @param values DataBag containing partial results computed on different data chunks
+     * @return output Tuple containing combined data
+     * @throws IOException
+     */
+    static protected Tuple combine(DataBag values) throws IOException {
+        Tuple output = DefaultTupleFactory.getInstance().newTuple();
+        Tuple tuple; // copy of DataBag values 
+        tuple =  DefaultTupleFactory.getInstance().newTuple(values.size());
+        int ct=0;
+
+        try{
+            for (Iterator<Tuple> it = values.iterator(); it.hasNext();ct++) {
+                Tuple t = it.next();
+                tuple.set(ct, t);
+            }
+        }catch(Exception e){}
+
+        try{
+            int size = ((Tuple)tuple.get(0)).size();
+            for(int i=0;i<size;i=i+2){
+                double count = 0;
+                double sum_x_y = 0.0;
+                double sum_x = 0.0;
+                double sum_y = 0.0;
+                double sum_x_square = 0.0;
+                double sum_y_square = 0.0;
+                for(int j=0;j<tuple.size();j++){
+                    Tuple temp = (Tuple)tuple.get(j);
+                    Tuple tem = (Tuple)temp.get(i);
+                    count += (Double)temp.get(i+1);
+                    sum_x_y += (Double)tem.get(0);
+                    sum_x += (Double)tem.get(1);
+                    sum_y += (Double)tem.get(2);
+                    sum_x_square += (Double)tem.get(3);
+                    sum_y_square += (Double)tem.get(4);
+                }
+                Tuple result = DefaultTupleFactory.getInstance().newTuple(5);
+                result.set(0, sum_x_y);
+                result.set(1, sum_x);
+                result.set(2, sum_y);
+                result.set(3, sum_x_square);
+                result.set(4, sum_y_square);
+                output.append(result);
+                output.append(count);
+            }
+        }catch(Exception e){
+            throw new IOException("Caught exception in COR.combine", e);
+        }
+
+        return output;
+    }
+
+    /**
+     * compute sum(XY), sum(X), sum(Y), sum(XX), sum(YY) from given data sets
+     * @param first DataBag containing first data set
+     * @param second DataBag containing second data set
+     * @return tuple containing sum(XY), sum(X), sum(Y), sum(XX), sum(YY)
+     */
+    protected static Tuple computeAll(DataBag first, DataBag second) throws IOException {
+        double sum_x_y = 0.0;
+        double sum_x = 0.0;
+        double sum_y = 0.0;
+        double sum_x_square = 0.0;
+        double sum_y_square = 0.0;
+        Iterator<Tuple> iterator_x = first.iterator();
+        Iterator<Tuple> iterator_y = second.iterator();
+        try{
+            while(iterator_x.hasNext()){
+                double x = (Double)iterator_x.next().get(0);
+                double y = (Double)iterator_y.next().get(0);
+                sum_x_y+=x*y;
+                sum_x+=x;
+                sum_y+=y;
+                sum_x_square+=x*x;
+                sum_y_square+=y*y;
+            }
+        }catch(Exception e){
+            throw new IOException("Caught exception processing input", e);
+        }
+        
+        Tuple result = DefaultTupleFactory.getInstance().newTuple(5);
+        try{
+            result.set(0, sum_x_y);
+            result.set(1, sum_x);
+            result.set(2, sum_y);
+            result.set(3, sum_x_square);
+            result.set(4, sum_y_square);
+        }catch(Exception e){
+            throw new IOException("Caught exception processing result", e);
+        }
+        return result;
+        
+    } 
+    
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.BAG));
+    } 
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/COS.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/COS.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/COS.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/COS.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.builtin;
+
+/**
+ * COS implements a binding to the Java function
+ * {@link java.lang.Math#cos(double) Math.cos(double)}. Given a single 
+ * data atom it  Returns the cosine value of the input
+ *
+ */
+public class COS extends DoubleBase{
+	Double compute(Double input){
+		return Math.cos(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/COSH.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/COSH.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/COSH.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/COSH.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * COSH implements a binding to the Java function
+ * {@link java.lang.Math#cosh(double) Math.cosh(double)}. Given a single 
+ * data atom it  Returns the hyperbolic cosine value of the input
+ *
+ */
+public class COSH extends DoubleBase{
+	Double compute(Double input){
+		return Math.cosh(input);
+		
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/COV.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/COV.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/COV.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/COV.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,326 @@
+/*
+ * 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.builtin;
+
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.apache.pig.Algebraic;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.DefaultBagFactory;
+import org.apache.pig.data.DefaultTupleFactory;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+* Computes the covariance between sets of data.  The returned value 
+* will be a bag which will contain a tuple for each combination of input 
+* schema and inside tuple we will have two schema name and covariance between 
+* those  two schemas. 
+* 
+* A = load 'input.xml' using PigStorage(':');<br/>
+* B = group A all;<br/>
+* D = foreach B generate group,COV(A.$0,A.$1,A.$2);<br/>
+*/
+public class COV extends EvalFunc<DataBag> implements Algebraic {
+    //name of the schemas. Initialize when user use define
+    protected Vector<String>schemaName = new Vector<String>();
+    //flag to indicate if define is called or not. 
+    private boolean flag = false;
+    
+    public COV(){}
+    
+    
+    public COV(String... schemaName){
+        for(int i=0;i<schemaName.length;i++){
+            this.schemaName.add(schemaName[i]);
+            flag = true;
+        }
+    }
+    
+    
+    /**
+     * Function to compute covariance between data sets.
+     * @param input input tuple which contains data sets.
+     * @return output output dataBag which contain covariance between each pair of data sets. 
+     */
+    @Override
+    public DataBag exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+        DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
+
+        try{
+            for(int i=0;i<input.size();i++){
+                for(int j=i+1;j<input.size();j++){
+                    Tuple temp = DefaultTupleFactory.getInstance().newTuple(3);
+                    if(flag){
+                        temp.set(0, schemaName.elementAt(i));
+                        temp.set(1, schemaName.elementAt(j));
+                    }
+                    else{
+                        temp.set(0, "var"+i);
+                        temp.set(1, "var"+j);
+                    }
+                
+                    Tuple tempResult = computeAll((DataBag)input.get(i), (DataBag)input.get(j));
+                    double size = ((DataBag)input.get(i)).size();
+                    double sum_x_y = (Double)tempResult.get(0);
+                    double sum_x = (Double)tempResult.get(1);
+                    double sum_y = (Double)tempResult.get(2);
+                    double result = (size*sum_x_y - sum_x*sum_y)/(size*size);
+                    temp.set(2, result);
+                    output.add(temp);
+                }
+            }
+        }catch(Exception e){
+            System.err.println("Failed to process input; error - " + e.getMessage());
+            return null;
+        }
+
+        return output;
+    }
+    
+
+    //used to pass schema name to Final class constructor 
+    /**
+     * Function to return argument of constructor as string. It append ( and ) at starting and end or argument respectively.
+     * If default constructor is called is returns empty string.
+     * @return argument of constructor
+     */
+    @Override
+    public String toString() {
+        if(flag){
+            StringBuilder sb = new StringBuilder();
+            sb.append('(');
+            if(schemaName!=null){
+                for (String sch : schemaName) {
+                    sb.append('\'' + sch + '\'' + ",");
+                }
+                sb.deleteCharAt(sb.length()-1);
+            }
+            sb.append(')');
+            return sb.toString();
+        }
+        else return "";
+    }
+    public String getInitial() {
+        return Initial.class.getName();
+    }
+
+    public String getIntermed() {
+        return Intermed.class.getName();
+    }
+
+    public String getFinal() {
+        //return Final.class.getName();
+        return Final.class.getName() + toString();
+    }
+
+    static public class Initial extends EvalFunc<Tuple> {
+        @Override
+        public Tuple exec(Tuple input) throws IOException {
+            if (input == null || input.size() == 0)
+                return null;
+
+            Tuple output = DefaultTupleFactory.getInstance().newTuple();
+            try {
+                for(int i=0;i<input.size();i++){
+                    for(int j=i+1;j<input.size();j++){
+                        DataBag first = (DataBag)input.get(i);
+                        DataBag second = (DataBag)input.get(j);
+                        output.append(computeAll(first, second));
+                        output.append(first.size());
+                    }
+                }
+            } catch(Exception t) {
+                System.err.println("Failed to process input; error - " + t.getMessage());
+                return null;
+            }
+
+            return output;
+        }
+    }
+
+    static public class Intermed extends EvalFunc<Tuple> {
+        
+        @Override
+        public Tuple exec(Tuple input) throws IOException {
+            try{
+                return combine((DataBag)input.get(0));
+            }catch(Exception e){
+                throw new IOException("Caught exception in COV.Intermed", e);
+            }
+        }
+    }
+
+    public static class Final extends EvalFunc<DataBag> {
+        protected Vector<String>schemaName = new Vector<String>();
+        boolean flag = false;
+        
+        public Final(){}
+        
+        public Final(String... schemaName){
+            for(int i=0;i<schemaName.length;i++){
+                this.schemaName.add(schemaName[i]);
+                flag = true;
+            }
+        }
+        
+        @Override
+        public DataBag exec(Tuple input) throws IOException {
+            if (input == null || input.size() == 0)
+                return null;
+            
+            DataBag output = DefaultBagFactory.getInstance().newDefaultBag();
+            int count = 0;
+            
+            //for each pair of input schema combined contain 2 member. first member
+            //is tuple containing sum_x,sum_y,sum_x_y and second is number of tuples 
+            //from which it is calculated . So if arity of combined is n then total 
+            //number of schemas would be root of x*x - x - n =0 
+            
+            try{
+                Tuple combined = combine((DataBag)input.get(0));    
+                int totalSchemas=2;
+                while(totalSchemas*(totalSchemas-1)<combined.size()){
+                    totalSchemas++;
+                }
+                for(int i=0;i<totalSchemas;i++){
+                    for(int j=i+1;j<totalSchemas;j++){
+                        Tuple result = DefaultTupleFactory.getInstance().newTuple(3);
+                        if(flag){
+                            result.set(0, schemaName.elementAt(i));
+                            result.set(1, schemaName.elementAt(j));
+                        }
+                        else{
+                            result.set(0, "var"+i);
+                            result.set(1, "var"+j);
+                        }
+                        Tuple tup = (Tuple)combined.get(count);
+                        double tempCount = (Double)combined.get(count+1);
+                        double sum_x_y = (Double)tup.get(0);
+                        double sum_x = (Double)tup.get(1);
+                        double sum_y = (Double)tup.get(2);
+                        double covar = (tempCount*sum_x_y - sum_x*sum_y)/(tempCount*tempCount);
+                        result.set(2, covar);
+                        output.add(result);
+                        count+=2;
+                    }
+                }
+            }catch(Exception e){
+                throw new IOException("Caught exception in COV.Intermed", e);
+            }
+
+            return output;
+        }
+    }
+
+    /**
+     * combine results of different data chunk 
+     * @param values DataBag containing partial results computed on different data chunks
+     * @return output Tuple containing combined data
+     * @throws IOException
+     */
+    static protected Tuple combine(DataBag values) throws IOException {
+        Tuple tuple = DefaultTupleFactory.getInstance().newTuple(Double.valueOf(values.size()).intValue());
+        Tuple output = DefaultTupleFactory.getInstance().newTuple();
+
+        int ct=0;
+        for (Iterator<Tuple> it = values.iterator(); it.hasNext();ct++) {
+            Tuple t = it.next();
+            try{ tuple.set(ct, t);}catch(Exception e){}
+        }
+        
+        try{
+            Tuple temp = (Tuple)tuple.get(0);
+            int size = temp.size();
+            for(int i=0;i<size;i=i+2){
+                double count = 0;
+                double sum_x_y = 0.0;
+                double sum_x = 0.0;
+                double sum_y = 0.0;
+                for(int j=0;j<tuple.size();j++){
+                    Tuple t = (Tuple)tuple.get(j);
+                    Tuple tem = (Tuple)t.get(i);
+                    count += (Double)t.get(i+1);
+                    sum_x_y+=(Double)tem.get(0);
+                    sum_x+=(Double)tem.get(1);
+                    sum_y+=(Double)tem.get(2);
+                }
+                Tuple result = DefaultTupleFactory.getInstance().newTuple(3);
+                result.set(0, sum_x_y);
+                result.set(1, sum_x);
+                result.set(2, sum_y);
+                output.append(result);
+                output.append(count);
+            }
+        }catch(Exception e){
+            throw new IOException("Caught exception processing input", e);
+        }
+      
+        return output;
+    }
+
+    /**
+     * compute sum(XY), sum(X), sum(Y) from given data sets
+     * @param first DataBag containing first data set
+     * @param second DataBag containing second data set
+     * @return tuple containing sum(XY), sum(X), sum(Y)
+     */
+    protected static Tuple computeAll(DataBag first, DataBag second) throws IOException {
+        double sum_x_y = 0.0;
+        double sum_x = 0.0;
+        double sum_y = 0.0;
+        Iterator<Tuple> iterator_x = first.iterator();
+        Iterator<Tuple> iterator_y = second.iterator();
+        try{
+            while(iterator_x.hasNext()){
+                double x = (Double)iterator_x.next().get(0);
+                double y = (Double)iterator_y.next().get(0);
+                sum_x_y+=x*y;
+                sum_x+=x;
+                sum_y+=y;
+            }
+        }catch (Exception e){
+            throw new IOException("Caught exception processing input", e);
+        }
+        
+        Tuple result = DefaultTupleFactory.getInstance().newTuple(3);
+        try{
+            result.set(0, sum_x_y);
+            result.set(1, sum_x);
+            result.set(2, sum_y);
+        }catch(Exception e) {
+            throw new IOException("Caught exception processing result", e);
+        }
+        return result;
+        
+    }
+    
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.BAG));
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleAbs.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleAbs.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleAbs.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleAbs.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+public class DoubleAbs extends EvalFunc<Double>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, absolute value of the argument
+	 */
+	public Double exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        Double d;
+        try{
+            d = (Double)input.get(0);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+
+		return Math.abs(d);
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.DOUBLE));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleBase.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleBase.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleBase.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleBase.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,66 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.FuncSpec;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+/**
+* base class for math udfs that return Double value
+*/
+public abstract class DoubleBase extends Base{
+    // each derived class provides the computation here
+    abstract Double compute(Double input);
+
+	/**
+	 * java level API
+	 * @param input expects a tuple with a single Double value
+	 * @return output returns a Double value
+     */
+	public Double exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        try {
+            Double val = (Double)input.get(0);
+            return (val == null ? null : compute(val));
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input of " + this.getClass().getName(), e);
+        }
+	}
+
+    /* (non-Javadoc)
+     * @see org.apache.pig.EvalFunc#getArgToFuncMapping()
+     */
+    @Override
+    public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
+        List<FuncSpec> funcList = new ArrayList<FuncSpec>();
+        funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.DOUBLE))));
+
+        return funcList;
+    }
+
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleRound.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleRound.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleRound.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/DoubleRound.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,55 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+/**
+ * Given a single data atom it Returns the closest long to the argument.
+ */
+public class DoubleRound extends EvalFunc<Long>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, 
+	 * the closest long to the argument
+	 */
+	@Override
+	public Long exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        try{
+            Double d =  (Double)input.get(0);
+		    return Math.round(d);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/EXP.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/EXP.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/EXP.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/EXP.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,28 @@
+/*
+ * 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.builtin;
+
+/**
+ * Given a single data atom it returns the Euler's number e raised to the power of input
+ */
+public class EXP extends DoubleBase {
+	Double compute(Double input){
+		return Math.exp(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/FLOOR.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/FLOOR.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/FLOOR.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/FLOOR.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,32 @@
+/*
+ * 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.builtin;
+
+/**
+ * FLOOR implements a binding to the Java function
+ * {@link java.lang.Math#floor(double) Math.floor(double)}. Given a single 
+ * data atom it returns the largest (closest to positive infinity) double 
+ * value that is less than or equal to the argument and is equal to a 
+ * mathematical integer.
+ */
+public class FLOOR extends DoubleBase{
+	Double compute(Double input){
+		return Math.floor(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/FloatAbs.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/FloatAbs.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/FloatAbs.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/FloatAbs.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+public class FloatAbs extends EvalFunc<Float>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return returns a single numeric value, absolute value of the argument
+	 */
+	public Float exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        Float d;
+        try{
+            d = (Float)input.get(0);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+
+		return Math.abs(d);
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.FLOAT));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/FloatRound.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/FloatRound.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/FloatRound.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/FloatRound.java Wed Jun 23 03:37:11 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+/**
+ * ROUND implements a binding to the Java function
+ * {@link java.lang.Math#round(float) Math.round(float)}. 
+ * Given a single data atom it Returns the closest long to the argument.
+ */
+public class FloatRound extends EvalFunc<Integer>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, 
+	 * the closest long to the argument
+	 */
+	@Override
+	public Integer exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        try{
+            Float d =  (Float)input.get(0);
+		    return Math.round(d);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.INTEGER));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/INDEXOF.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/INDEXOF.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/INDEXOF.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/INDEXOF.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,73 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+
+/**
+ * INDEXOF implements eval function to search for a string
+ * Example:
+ *      A = load 'mydata' as (name);
+ *      B = foreach A generate INDEXOF(name, ",");
+ */
+public class INDEXOF extends EvalFunc<Integer> {
+    
+    private static final Log log = LogFactory.getLog(INDEXOF.class);
+
+    /**
+     * Method invoked on every tuple during foreach evaluation
+     * @param input tuple; first column is assumed to have the column to convert
+     *                     the second column is the string we search for
+     *                     the third is an optional column from where to start the search
+     * @exception java.io.IOException
+     * @return index of first occurrence, or null in case of processing error
+     */
+    public Integer exec(Tuple input) throws IOException {
+        if (input == null || input.size() < 2) {
+            log.warn("invalid input tuple: "+input);
+            return null;
+        }
+        try {
+            String str = (String)input.get(0);
+            String search = (String)input.get(1);
+            int fromIndex = 0;
+            if (input.size() >=3)
+                fromIndex = (Integer)input.get(2);
+            return str.indexOf(search, fromIndex);
+        } catch(Exception e){
+            log.warn("Failed to process input; error - " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.INTEGER));
+    }
+
+}
\ No newline at end of file

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/IntAbs.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/IntAbs.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/IntAbs.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/IntAbs.java Wed Jun 23 03:37:11 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+/**
+  * ABS implements a binding to the Java function
+ * {@link java.lang.Math#abs(double) Math.abs(int)} for computing the
+ * absolute value of the argument. The returned value will be an int which is 
+ * absolute value of the input.
+ */
+public class IntAbs extends EvalFunc<Integer>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, absolute value of the argument
+	 */
+	public Integer exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        Integer d;
+        try{
+            d = (Integer)input.get(0);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+
+		return Math.abs(d);
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.INTEGER));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/LAST_INDEX_OF.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LAST_INDEX_OF.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LAST_INDEX_OF.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LAST_INDEX_OF.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+ * string.INSTR implements eval function to search for the last occurrence of a string
+ * Returns null on error
+ * Example:
+ * <code>
+ *      A = load 'mydata' as (name);
+ *      B = foreach A generate LASTINDEXOF(name, ",");
+ * </code>
+ */
+public class LAST_INDEX_OF extends EvalFunc<Integer> {
+    private static final Log log = LogFactory.getLog(LAST_INDEX_OF.class);
+
+    /**
+     * Finds the last location of a substring in a given string.
+     * @param input tuple:<ol>
+     * <li>the string to process
+     * <li>the substring to find
+     * </ol>
+     * @exception java.io.IOException
+     * @return last location of substring, or null in case of processing errors.
+     */
+    public Integer exec(Tuple input) throws IOException {
+        if (input == null || input.size() < 2)
+            return null;
+
+        try {
+            String str = (String)input.get(0);
+            String search = (String)input.get(1);
+            return str.lastIndexOf(search);
+        } catch(Exception e) {
+            log.warn("Failed to process input; error - " + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(null, DataType.INTEGER));
+    }
+
+}
\ No newline at end of file

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/LCFIRST.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LCFIRST.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LCFIRST.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LCFIRST.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.builtin;
+
+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/src/org/apache/pig/builtin/LOG.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LOG.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LOG.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LOG.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,31 @@
+/*
+ * 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.builtin;
+
+/**
+ * LOG implements a binding to the Java function
+ * {@link java.lang.Math#log(double) Math.log(double)}. 
+ * Given a single data atom it returns the natural 
+ * logarithm (base e)  of a double
+ */
+public class LOG extends DoubleBase{
+	Double compute(Double input){
+		return Math.log(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/LOG10.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LOG10.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LOG10.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LOG10.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.builtin;
+
+/**
+ * LOG10 implements a binding to the Java function
+ * {@link java.lang.Math#log10(double) Math.log10(double)}. 
+ * Given a single data atom it returns the base 10 logarithm of a double
+ */
+public class LOG10 extends DoubleBase{
+	Double compute(Double input){
+		return Math.log10(input);
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/LOWER.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LOWER.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LOWER.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LOWER.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,78 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.DataType;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.FuncSpec;
+
+/**
+ * LOWER implements eval function to convert a string to lower case
+ * Example:
+ *      A = load 'mydata' as (name);
+ *      B = foreach A generate LOWER(name);
+ */
+public class LOWER extends EvalFunc<String> {
+
+    /**
+     * Method invoked on every tuple during foreach evaluation
+     * @param input tuple; first column is assumed to have the column to convert
+     * @exception java.io.IOException
+     */
+    public String exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        try {
+            String str = (String)input.get(0);
+            return str.toLowerCase();
+        } catch(Exception e){
+            log.warn("Failed to process input; error - " + e.getMessage());
+            return null;
+        }
+    }
+
+    /**
+     * This method gives a name to the column.
+     * @param input - schema of the input data
+     * @return schema of the input data
+     */
+    @Override
+    public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.CHARARRAY));
+    }
+
+     /* (non-Javadoc)
+      * @see org.apache.pig.EvalFunc#getArgToFuncMapping()
+      */
+     @Override
+     public List<FuncSpec> getArgToFuncMapping() throws FrontendException {
+        List<FuncSpec> funcList = new ArrayList<FuncSpec>();
+        funcList.add(new FuncSpec(this.getClass().getName(), new Schema(new Schema.FieldSchema(null, DataType.CHARARRAY))));
+
+        return funcList;
+     }
+
+}
\ No newline at end of file

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/LongAbs.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/LongAbs.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/LongAbs.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/LongAbs.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.builtin;
+
+import java.io.IOException;
+
+import org.apache.pig.EvalFunc;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.data.DataType;
+
+public class LongAbs extends EvalFunc<Long>{
+	/**
+	 * java level API
+	 * @param input expects a single numeric value
+	 * @return output returns a single numeric value, absolute value of the argument
+	 */
+	public Long exec(Tuple input) throws IOException {
+        if (input == null || input.size() == 0)
+            return null;
+
+        Long d;
+        try{
+            d = (Long)input.get(0);
+        } catch (Exception e){
+            throw new IOException("Caught exception processing input row ", e);
+        }
+
+		return Math.abs(d);
+	}
+	
+	@Override
+	public Schema outputSchema(Schema input) {
+        return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), DataType.LONG));
+	}
+}

Added: hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT.java
URL: http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT.java?rev=957100&view=auto
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT.java (added)
+++ hadoop/pig/trunk/src/org/apache/pig/builtin/REGEX_EXTRACT.java Wed Jun 23 03:37:11 2010
@@ -0,0 +1,104 @@
+/*
+ * 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.builtin;
+
+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.PigWarning;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.FrontendException;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+
+/**
+* <dl>
+* <dt><b>Syntax:</b></dt>
+* <dd><code>String RegexExtract(String expression, String regex, int match_index)</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>
+* <dd><code>match_index</code>-<code>index of the group to extract</code>.</dd>
+* <dt><b>Output:</b></dt>
+* <dd><code>extracted group, if fail, return null</code>.</dd>
+* </dl>
+*/
+
+public class REGEX_EXTRACT extends EvalFunc<String> {
+    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.CHARARRAY));
+      } catch (Exception e) {
+        return null;
+      }
+    }
+
+    public String exec(Tuple input) throws IOException {
+        if (input.size()!=3) {
+            String msg = "RegexExtract : Only 3 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 = "RegexExtract : Mal-Formed Regular expression : "+input.get(1);
+                    throw new IOException(msg);
+                }
+            }
+        } catch (NullPointerException e) {
+            String msg = "RegexExtract : Regular expression is null";
+            throw new IOException(msg);
+        }
+        int mIndex = (Integer)input.get(2);
+        
+        Matcher m = mPattern.matcher((String)input.get(0));
+        if (m.find()&&m.groupCount()>=mIndex)
+        {
+            return m.group(mIndex);
+        }
+        warn("RegexExtract : Cannot extract group for input "+input.get(0), PigWarning.UDF_WARNING_1);
+        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));
+        s.add(new Schema.FieldSchema(null, DataType.INTEGER));
+        funcList.add(new FuncSpec(this.getClass().getName(), s));
+        return funcList;
+    } 
+}



Mime
View raw message