Author: olga
Date: Wed Nov 12 18:20:31 2008
New Revision: 713615

URL: http://svn.apache.org/viewvc?rev=713615&view=rev
Log:
PIG-525: make sure that cast for udf parameters works

Modified:
    hadoop/pig/branches/types/CHANGES.txt
    
hadoop/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
    hadoop/pig/branches/types/test/org/apache/pig/test/TestBestFitCast.java

Modified: hadoop/pig/branches/types/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/branches/types/CHANGES.txt?rev=713615&r1=713614&r2=713615&view=diff
==============================================================================
--- hadoop/pig/branches/types/CHANGES.txt (original)
+++ hadoop/pig/branches/types/CHANGES.txt Wed Nov 12 18:20:31 2008
@@ -310,3 +310,5 @@
 
     PIG-517: load functiin with parameters does not work with cast (pradeepk
     via olgan)
+
+    PIG-525: make sure cast for udf parameters works (olgan)

Modified: 
hadoop/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java?rev=713615&r1=713614&r2=713615&view=diff
==============================================================================
--- 
hadoop/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
 (original)
+++ 
hadoop/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
 Wed Nov 12 18:20:31 2008
@@ -1422,11 +1422,17 @@
             try {
                 currentPlan.connect(input, cast);
                 currentPlan.connect(cast, udf);
+                this.visit(cast);
             } catch (PlanException ioe) {
                 AssertionError err = new AssertionError(
                         "Explicit casting insertion");
                 err.initCause(ioe);
                 throw err;
+            } catch (VisitorException ve) {
+                AssertionError err = new AssertionError(
+                        "Explicit casting insertion");
+                err.initCause(ve);
+                throw err;
             }
         }
         udf.setMArgs(newArgs);

Modified: 
hadoop/pig/branches/types/test/org/apache/pig/test/TestBestFitCast.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/branches/types/test/org/apache/pig/test/TestBestFitCast.java?rev=713615&r1=713614&r2=713615&view=diff
==============================================================================
--- hadoop/pig/branches/types/test/org/apache/pig/test/TestBestFitCast.java 
(original)
+++ hadoop/pig/branches/types/test/org/apache/pig/test/TestBestFitCast.java Wed 
Nov 12 18:20:31 2008
@@ -86,6 +86,34 @@
 
     }
     
+    public static class UDF2 extends EvalFunc<String>{
+        /**
+         * java level API
+         * @param input expects a single numeric DataAtom value
+         * @param output returns a single numeric DataAtom value, cosine value 
of the argument
+         */
+        @Override
+        public String exec(Tuple input) throws IOException {
+            try{
+                String str = (String)input.get(0);
+                return str.toUpperCase();
+            }catch (Exception e){
+                return null;
+            }
+        }
+
+        /* (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;
+        }    
+
+    }
+    
     @Test
     public void test1() throws Exception{
         //Passing (long, int)
@@ -173,4 +201,17 @@
         }
         
     }
+
+    @Test
+    public void test6() throws Exception{
+        // test UDF with single mapping function 
+        // where bytearray is passed in as input parameter
+        File input = Util.createInputFile("tmp", "", new String[] {"abc"});
+        pigServer.registerQuery("A = LOAD '" + 
Util.generateURI(input.toString()) +"';");
+        pigServer.registerQuery("B = FOREACH A GENERATE " + 
UDF2.class.getName() + "($0);");
+        Iterator<Tuple> iter = pigServer.openIterator("B");
+        if(!iter.hasNext()) fail("No Output received");
+        Tuple t = iter.next();
+        assertEquals("ABC", t.get(0));
+    }
 }


Reply via email to