Author: olga
Date: Wed Jun 18 15:41:43 2008
New Revision: 669321

URL: http://svn.apache.org/viewvc?rev=669321&view=rev
Log:
PIG-255: make non-default constructor work with algebraic functions

Added:
    incubator/pig/trunk/test/org/apache/pig/test/TestUDF.java
Modified:
    incubator/pig/trunk/CHANGES.txt
    incubator/pig/trunk/src/org/apache/pig/impl/PigContext.java

Modified: incubator/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/CHANGES.txt?rev=669321&r1=669320&r2=669321&view=diff
==============================================================================
--- incubator/pig/trunk/CHANGES.txt (original)
+++ incubator/pig/trunk/CHANGES.txt Wed Jun 18 15:41:43 2008
@@ -320,3 +320,6 @@
     PIG-266: fix warnings caused by HOD (olgan)
 
     PIG-245: added math functions to the piggybank (ajaygarg via olgan)
+
+    PIG-255: make non-default constructors work for algebraic functions
+    (ajaygarg via olgan)

Modified: incubator/pig/trunk/src/org/apache/pig/impl/PigContext.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/src/org/apache/pig/impl/PigContext.java?rev=669321&r1=669320&r2=669321&view=diff
==============================================================================
--- incubator/pig/trunk/src/org/apache/pig/impl/PigContext.java (original)
+++ incubator/pig/trunk/src/org/apache/pig/impl/PigContext.java Wed Jun 18 
15:41:43 2008
@@ -515,7 +515,7 @@
         if (funcSpec != null) {
             className = getClassNameFromSpec(funcSpec);
         }else{
-            className = alias;
+            className = getClassNameFromSpec(alias);
         }
         return resolveClassName(className);
     }

Added: incubator/pig/trunk/test/org/apache/pig/test/TestUDF.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/trunk/test/org/apache/pig/test/TestUDF.java?rev=669321&view=auto
==============================================================================
--- incubator/pig/trunk/test/org/apache/pig/test/TestUDF.java (added)
+++ incubator/pig/trunk/test/org/apache/pig/test/TestUDF.java Wed Jun 18 
15:41:43 2008
@@ -0,0 +1,105 @@
+package org.apache.pig.test;
+
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Iterator;
+
+import junit.framework.TestCase;
+
+import org.apache.pig.Algebraic;
+import org.apache.pig.EvalFunc;
+import org.apache.pig.PigServer;
+import org.apache.pig.PigServer.ExecType;
+import org.apache.pig.builtin.PigStorage;
+import org.apache.pig.data.DataAtom;
+import org.apache.pig.data.Tuple;
+
+public class TestUDF extends TestCase{
+       
+       
+       public void test() throws Exception{
+        int LOOP_COUNT = 4*10;
+               MiniCluster cluster=MiniCluster.buildCluster();
+               PigServer server = new 
PigServer(ExecType.MAPREDUCE,cluster.getProperties());
+        File tmpFile = File.createTempFile("test", "txt");
+        PrintStream ps = new PrintStream(new FileOutputStream(tmpFile));
+        for(int i = 0; i < LOOP_COUNT; i++) {
+            ps.println(i);
+        }
+        ps.close();
+               server.registerQuery("A = load 'file:" + 
Util.encodeEscape(tmpFile.toString()) + "' USING "+ PigStorage.class.getName() 
+ "(':');");
+//             server.registerQuery("define c Test('a');");
+        server.registerFunction("c", Test.class.getName() + "('a')" );
+        server.registerQuery("C = group A by $0;");
+               server.registerQuery("B = foreach C generate group, c($0);");
+               Iterator<Tuple> result = server.openIterator("B");
+               while (result.hasNext()) {
+                          Tuple t = (Tuple) result.next();
+                          System.out.println(t);
+                       }
+       }
+       
+
+    static public class Test extends EvalFunc<DataAtom> implements Algebraic{
+        protected String schemaName;
+        
+        public Test(){}
+        
+        
+        public Test(String  schemaName){
+                this.schemaName=schemaName;
+        }
+    
+    
+        @Override
+        public void exec(Tuple input, DataAtom output) throws IOException {
+            output.setValue(schemaName);
+        }
+    
+        public String toString() {
+                return "('"+schemaName+"')";
+        }
+    
+        public String getFinal() {
+            // TODO Auto-generated method stub
+            System.out.println("Final Called 
************************************");
+            return Final.class.getName() + toString();
+        }
+    
+    
+        public String getInitial() {
+            // TODO Auto-generated method stub
+            return Initial.class.getName();
+        }
+    
+    
+        public String getIntermed() {
+            // TODO Auto-generated method stub
+            return Initial.class.getName();
+        }
+        
+        static public class Initial extends EvalFunc<Tuple> {
+            @Override
+            public void exec(Tuple input, Tuple output) throws IOException {
+            }
+        }
+        static public class Final extends EvalFunc<DataAtom> {
+            String schemaName;
+            public Final(){}
+            
+            public Final(String schemaName){
+                this.schemaName = schemaName;
+            }
+            
+            @Override
+            public void exec(Tuple input, DataAtom output) throws IOException {
+                output.setValue(schemaName);
+            }
+        }
+        
+        
+    }
+}


Reply via email to