Author: olga
Date: Wed Jun 11 16:45:21 2008
New Revision: 666904

URL: http://svn.apache.org/viewvc?rev=666904&view=rev
Log:
added UDF repository called piggybank

Added:
    incubator/pig/trunk/contrib/
    incubator/pig/trunk/contrib/piggybank/
    incubator/pig/trunk/contrib/piggybank/java/
    incubator/pig/trunk/contrib/piggybank/java/build.xml   (with props)
    incubator/pig/trunk/contrib/piggybank/java/lib/
    incubator/pig/trunk/contrib/piggybank/java/src/
    incubator/pig/trunk/contrib/piggybank/java/src/main/
    incubator/pig/trunk/contrib/piggybank/java/src/main/java/
    incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/
    incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/
    incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/comparison/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/math/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/stats/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/util/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/filtering/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/grouping/
    
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/
    incubator/pig/trunk/contrib/piggybank/java/src/test/
    incubator/pig/trunk/contrib/piggybank/java/src/test/java/
    incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/
    incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/
    incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/comparison/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/filtering/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/grouping/
    
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/storage/

Added: incubator/pig/trunk/contrib/piggybank/java/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/contrib/piggybank/java/build.xml?rev=666904&view=auto
==============================================================================
--- incubator/pig/trunk/contrib/piggybank/java/build.xml (added)
+++ incubator/pig/trunk/contrib/piggybank/java/build.xml Wed Jun 11 16:45:21 
2008
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project basedir="." default="jar" name="pigudf">
+    <!-- javac properties -->
+    <property name="javac.debug" value="on" />
+    <property name="javac.level" value="source,lines,vars"/>
+    <property name="javac.optimize" value="on" />
+    <property name="javac.deprecation" value="off" />
+    <property name="javac.version" value="1.5" />
+    <property name="javac.args" value="" />
+    <!-- TODO we should use warning...   <property name="javac.args.warnings" 
value="-Xlint:unchecked" /> -->
+    <property name="javac.args.warnings" value="" />
+
+    <!-- build properties -->
+    <property name="build.dir" value="${basedir}/build" />
+    <property name="build.classes" value="${build.dir}/classes" />
+    <property name="build.docs" value="${build.dir}/docs" />
+    <property name="build.javadoc" value="${build.docs}/api" />
+    <property name="pigjar" value="../../../pig.jar" />
+    <property name="udfjar" value="piggybank.jar" />
+    <property name="src.dir" value="src/main/java/org/apache/pig/piggybank" />
+
+    <!-- jar properties -->
+    <property name=".javadoc" value="${build.docs}/api" />
+    
+    <!-- test properties -->
+    <property name="test.build.dir" value="${build.dir}/test" />
+    <property name="test.classes" value="${test.build.dir}/classes" />
+    <property name="test.logs" value="${test.build.dir}/logs" />
+    <property name="test.timeout" value="900000" />
+    <property name="test.junit.output.format" value="plain" />
+    <property name="test.src.dir" value="src/test/java" />
+
+    <path id="pigudf.classpath">
+        <pathelement location="${build.classes}"/>
+        <pathelement location="${pigjar}"/>
+    </path>
+
+    <path id="test.classpath">
+        <pathelement location="${build.classes}"/>
+        <pathelement location="${test.classes}"/>
+        <pathelement location="${pigjar}"/>
+    </path>
+
+    <target name="init">
+        <mkdir dir="${build.dir}"/>
+        <mkdir dir="${build.classes}"/>
+        <mkdir dir="${test.build.dir}"/>
+        <mkdir dir="${test.classes}"/>
+        <mkdir dir="${build.javadoc}"/>
+    </target>
+    <target name="clean">
+        <delete dir="build"/>
+    </target>
+    <target depends="init" name="compile" description="compile all of the 
class files">
+        <echo> *** Compiling Pig UDFs ***</echo>
+        <javac srcdir="${src.dir}" debug="${javac.debug}" 
debuglevel="${javac.level}" destdir="${build.classes}" source="${javac.version}"
+        target="${javac.version}" optimize="${javac.optimize}" 
deprecation="${javac.deprecation}">
+            <compilerarg line="${javac.args} ${javac.args.warnings}" />
+            <classpath refid="pigudf.classpath"/>
+        </javac>
+    </target>
+    <target depends="init,compile" name="jar" description="create the jar 
files">
+        <echo> *** Creating pigudf.jar ***</echo>
+      <jar destfile="${udfjar}">
+        <fileset dir="build/classes"/>
+      </jar>
+    </target>
+    <target depends="compile" name="compile-test">
+        <echo> *** Compiling UDF tests ***</echo>
+        <javac srcdir="${test.src.dir}" debug="true" 
debuglevel="${debuglevel}" destdir="${test.classes}" source="${javac.version}" 
target="${javac.version}">
+            <classpath refid="pigudf.classpath"/>
+        </javac>
+    </target>
+    <target depends="compile-test,jar" name="test">
+        <echo> *** Running UDF tests ***</echo>
+        <delete dir="${test.logs}"/>
+        <mkdir dir="${test.logs}"/>
+        <junit printsummary="yes" haltonfailure="no" fork="yes" 
maxmemory="256m" dir="${basedir}" timeout="${test.timeout}" 
errorProperty="tests.failed" failureProperty="tests.failed">        
+            <classpath refid="test.classpath"/>
+            <formatter type="${test.junit.output.format}" />
+            <batchtest fork="yes" todir="${test.logs}" unless="testcase">
+                <fileset dir="${test.src.dir}">
+                    <include name="**/*Test*.java" />
+                </fileset>
+            </batchtest>
+            <batchtest fork="yes" todir="${test.logs}" if="testcase">
+                <fileset dir="${test.src.dir}" includes="**/${testcase}.java"/>
+            </batchtest>
+        </junit>
+        <fail if="tests.failed">Tests failed!</fail>
+    </target>
+    <target depends="init" name="javadoc"
+            description="build javadoc for all of the packages">
+        <echo> *** Creating Javadocs ***</echo>
+      <javadoc destdir="build/javadoc"
+               author="true">
+        <fileset dir="${src.dir}/evaluation" includes="**/*.java"/>
+        <fileset dir="${src.dir}/storage" includes="**/*.java"/>
+        <fileset dir="${src.dir}/filtering" includes="**/*.java"/>
+        <fileset dir="${src.dir}/grouping" includes="**/*.java"/>
+        <fileset dir="${src.dir}/comparison" includes="**/*.java"/>
+        <classpath refid="pigudf.classpath"/>
+      </javadoc>
+    </target>
+</project>

Propchange: incubator/pig/trunk/contrib/piggybank/java/build.xml
------------------------------------------------------------------------------
    svn:executable = *

Added: 
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java?rev=666904&view=auto
==============================================================================
--- 
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
 (added)
+++ 
incubator/pig/trunk/contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/evaluation/string/UPPER.java
 Wed Jun 11 16:45:21 2008
@@ -0,0 +1,60 @@
+/*
+ * 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.data.DataAtom;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.logicalLayer.schema.AtomSchema;
+
+/**
+ * string.UPPER implements eval function to convert a string to upper case
+ * Example:
+ *      register pigudfs.jar;
+ *      A = load 'mydata' as (name);
+ *      B = foreach A generate string.UPPER(name);
+ *      dump B;
+ */
+public class UPPER extends EvalFunc<DataAtom>
+{
+    /** 
+        * Method invoked on every tuple during foreach evaluation
+        * @param input tuple; first column is assumed to have the column to 
convert
+        * @param output - resulting value
+        * @exception IOException
+                                                           */
+    //@Override
+    public void exec(Tuple input, DataAtom output) throws IOException {
+        String str = input.getAtomField(0).strval();
+        output.setValue(str.toUpperCase());
+    }
+
+    //@Override
+    /**
+     * This method gives a name to the column. 
+     * @param input - schema of the input data
+     * @return schema of the input data
+     */
+    public Schema outputSchema(Schema input) {
+        return new AtomSchema("upper_" + input.schemaFor(0).toString()); 
+    }
+}

Added: 
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java?rev=666904&view=auto
==============================================================================
--- 
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
 (added)
+++ 
incubator/pig/trunk/contrib/piggybank/java/src/test/java/org/apache/pig/piggybank/test/evaluation/TestEvalString.java
 Wed Jun 11 16:45:21 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.test.evaluation;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.junit.Test;
+
+import org.apache.pig.FilterFunc;
+import org.apache.pig.LoadFunc;
+import org.apache.pig.PigServer;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.StoreFunc;
+import org.apache.pig.builtin.*;
+import org.apache.pig.data.BagFactory;
+import org.apache.pig.data.DataAtom;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataMap;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.pig.impl.logicalLayer.schema.AtomSchema;
+import org.apache.pig.impl.logicalLayer.schema.TupleSchema;
+import org.apache.pig.impl.builtin.ShellBagEvalFunc;
+import org.apache.pig.impl.io.BufferedPositionedInputStream;
+import static org.apache.pig.PigServer.ExecType.LOCAL;
+
+import org.apache.pig.piggybank.evaluation.string.UPPER;
+
+// This class tests all string eval functions.
+
+public class TestEvalString extends TestCase {
+       
+    @Test
+    public void testUPPER() throws Exception {
+        UPPER func = new UPPER();
+
+        // test excution
+        String data = "Hello World!";
+        String expected = "HELLO WORLD!";
+
+        DataAtom field = new DataAtom(data);
+        Tuple input = new Tuple(field);
+        DataAtom output = new DataAtom();
+
+        func.exec(input, output);
+        assertTrue(output.strval().equals(expected));
+
+        // test schema creation
+        String fieldName = "field1";
+        AtomSchema fieldSchema = new AtomSchema(fieldName);
+        TupleSchema tupleSchema = new TupleSchema();
+        tupleSchema.add(fieldSchema, false);
+        Schema outSchema = func.outputSchema(tupleSchema);
+        assertTrue(outSchema.toString().equals("upper_" + fieldName));
+
+    }
+}


Reply via email to