Author: gates
Date: Wed May 28 07:38:12 2008
New Revision: 660963

URL: http://svn.apache.org/viewvc?rev=660963&view=rev
Log:
PIG-158 Santhosh's is_null patch.  Adds is null operator.


Added:
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOIsNull.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/expressionOperators/POIsNull.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java
    
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld
    
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld
Modified:
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOVisitor.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogToPhyTranslationVisitor.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    
incubator/pig/branches/types/test/org/apache/pig/test/TestLogToPhyCompiler.java
    
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
    incubator/pig/branches/types/test/org/apache/pig/test/utils/GenPhyOp.java

Added: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOIsNull.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOIsNull.java?rev=660963&view=auto
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOIsNull.java 
(added)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOIsNull.java 
Wed May 28 07:38:12 2008
@@ -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.impl.logicalLayer;
+
+import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.impl.plan.PlanVisitor;
+import org.apache.pig.impl.plan.OperatorKey;
+import org.apache.pig.impl.logicalLayer.schema.Schema;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class LOIsNull extends UnaryExpressionOperator {
+
+    private static final long serialVersionUID = 2L;
+    private static Log log = LogFactory.getLog(LOIsNull.class);
+
+    /**
+     * 
+     * @param plan
+     *            Logical plan this operator is a part of.
+     * @param k
+     *            Operator key to assign to this node.
+     * @param operand
+     *            the only operand for a unary operator
+     */
+    public LOIsNull(LogicalPlan plan, OperatorKey k,
+            ExpressionOperator operand) {
+        super(plan, k, operand);
+    }
+    
+    @Override
+    public Schema getSchema() {
+        return mSchema;
+    }
+
+    @Override
+    public Schema.FieldSchema getFieldSchema() {
+        return mFieldSchema;
+    }
+
+    @Override
+    public void visit(LOVisitor v) throws VisitorException {
+        v.visit(this);
+    }
+
+    @Override
+    public String name() {
+        return "IsNull " + mKey.scope + "-" + mKey.id;
+    }
+}

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOVisitor.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOVisitor.java?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOVisitor.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LOVisitor.java
 Wed May 28 07:38:12 2008
@@ -382,4 +382,7 @@
                return;
        }
 
+       public void visit(LOIsNull uniOp) throws VisitorException {
+               return;
+       }
 }

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogToPhyTranslationVisitor.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogToPhyTranslationVisitor.java?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogToPhyTranslationVisitor.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/LogToPhyTranslationVisitor.java
 Wed May 28 07:38:12 2008
@@ -761,6 +761,23 @@
        }
        
        @Override
+       public void visit(LOIsNull op) throws VisitorException {
+               String scope = op.getKey().scope;
+               ExpressionOperator physOp = new POIsNull(new OperatorKey(scope, 
nodeGen.getNextNodeId(scope)), op.getRequestedParallelism(), null);
+               currentPlan.add(physOp);
+               
+               LogToPhyMap.put(op, physOp);
+               ExpressionOperator from = (ExpressionOperator) 
LogToPhyMap.get(op.getPlan().getPredecessors(op).get(0));
+               ((POIsNull)physOp).setInput(from);
+               try {
+                       currentPlan.connect(from, physOp);
+               } catch (PlanException e) {
+                       log.error("Invalid physical operator in the plan" + 
e.getMessage());
+               }
+               
+       }
+       
+       @Override
        public void visit(LOMapLookup op) throws VisitorException {
                String scope = ((OperatorKey)op.getKey()).scope;
                ExpressionOperator physOp = new POMapLookUp(new 
OperatorKey(scope, nodeGen.getNextNodeId(scope)), op.getRequestedParallelism(), 
op.getLookUpKey());

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
 Wed May 28 07:38:12 2008
@@ -439,6 +439,8 @@
 TOKEN : { <TUPLE : "tuple"> }
 TOKEN : { <MAP : "map"> }
 TOKEN : { <DEFINE : "define"> }
+TOKEN : { <IS : "is"> }
+TOKEN : { <NULL : "null"> }
 
 TOKEN:
 {
@@ -923,6 +925,7 @@
                                }
                        }
                )
+|      cond = PNullCond(over,specs,lp,input)
 |      cond = PNotCond(over,specs,lp,input)
 
        )
@@ -947,6 +950,34 @@
        }
 }
 
+ExpressionOperator PNullCond(Schema over, Map<String, LogicalOperator> 
specs,LogicalPlan lp,LogicalOperator input) : 
+{
+       ExpressionOperator c1;
+    boolean not = false;
+       log.trace("Entering PNullCond");
+}
+{
+       c1=InfixExpr(over,specs,lp,input) <IS> [<NOT> {not = true;}] <NULL>
+       {
+               ExpressionOperator eOp = new LOIsNull(lp, new 
OperatorKey(scope, getNextId()), c1);
+               lp.add(eOp);
+               log.debug("PNullCond: Added operator " + 
eOp.getClass().getName() + " " + eOp + " to logical plan " + lp);
+               lp.connect(c1, eOp);
+               log.debug("PNullCond: Connected operator " + 
eOp.getClass().getName() + " " + eOp + " to " + c1 + " logical plan " + lp);
+        ExpressionOperator notNull = null;
+        if (not) {
+            notNull = new LONot(lp, new OperatorKey(scope, getNextId()), eOp); 
+            lp.add(notNull);
+                   log.debug("PNullCond: Added operator " + 
notNull.getClass().getName() + " " + notNull + " to logical plan " + lp);
+            lp.connect(eOp, notNull);
+                   log.debug("PNullCond: Connected operator " + 
notNull.getClass().getName() + " " + notNull + " to " + eOp + " logical plan " 
+ lp);
+            eOp = notNull;
+        }
+               log.trace("Exiting PNullCond");
+               return eOp;
+       }
+}
+
 LogicalOperator CogroupClause(LogicalPlan lp) : 
 {
        CogroupInput gi; 

Added: 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/expressionOperators/POIsNull.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/expressionOperators/POIsNull.java?rev=660963&view=auto
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/expressionOperators/POIsNull.java
 (added)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/physicalLayer/expressionOperators/POIsNull.java
 Wed May 28 07:38:12 2008
@@ -0,0 +1,199 @@
+/*
+ * 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.impl.physicalLayer.expressionOperators;
+
+import java.util.Map;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.impl.plan.OperatorKey;
+import org.apache.pig.impl.physicalLayer.POStatus;
+import org.apache.pig.impl.physicalLayer.Result;
+import org.apache.pig.impl.physicalLayer.plans.ExprPlanVisitor;
+import org.apache.pig.impl.plan.VisitorException;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+
+public class POIsNull extends ComparisonOperator {
+
+    public POIsNull(OperatorKey k, int rp) {
+        super(k, rp);
+        
+    }
+
+    public POIsNull(OperatorKey k) {
+        super(k);
+        
+    }
+    
+    public POIsNull(OperatorKey k, int rp, ExpressionOperator in) {
+        super(k, rp);
+        this.lhs = in;
+        this.rhs = null;
+    }
+
+    @Override
+    public void visit(ExprPlanVisitor v) throws VisitorException {
+        //v.visitIsNull(this);
+    }
+
+    @Override
+    public String name() {
+        // TODO Auto-generated method stub
+        return "POIsNull - " + mKey.toString();
+    }
+
+    @Override
+    public Result getNext(Double d) throws ExecException {
+        Result res = lhs.getNext(d);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Double)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+
+    @Override
+    public Result getNext(Float f) throws ExecException {
+        Result res = lhs.getNext(f);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Float)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+
+    @Override
+    public Result getNext(Integer i) throws ExecException {
+        Result res = lhs.getNext(i);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Integer)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+
+    @Override
+    public Result getNext(Long l) throws ExecException {
+        Result res = lhs.getNext(l);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Long)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(DataByteArray dba) throws ExecException {
+        Result res = lhs.getNext(dba);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((DataByteArray)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(String s) throws ExecException {
+        Result res = lhs.getNext(s);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((String)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(Boolean b) throws ExecException {
+        Result res = lhs.getNext(b);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Boolean)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(Tuple t) throws ExecException {
+        Result res = lhs.getNext(t);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Tuple)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(DataBag b) throws ExecException {
+        Result res = lhs.getNext(b);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((DataBag)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    @Override
+    public Result getNext(Map m) throws ExecException {
+        Result res = lhs.getNext(m);
+        if(res.returnStatus == POStatus.STATUS_OK) {
+            if ((Map)res.result == null) {
+                res.result = true;
+            } else {
+                res.result = false;
+            }
+        }
+        return res;
+    }
+    
+    public void setInput(ExpressionOperator in) {
+        this.lhs = in;
+        this.rhs = null;
+    }
+    
+    
+
+}

Modified: 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogToPhyCompiler.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestLogToPhyCompiler.java?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogToPhyCompiler.java 
(original)
+++ 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogToPhyCompiler.java 
Wed May 28 07:38:12 2008
@@ -344,6 +344,45 @@
        
     }
     
+    @Test
+    public void testIsNull() throws VisitorException, IOException {
+        //TODO
+        //PONot is not implemented. The query below translates to POIsNull 
istead
+        //of PONOt(POIsNull)
+       String query = "split (load 'a') into x if $0 IS NULL, y if $0 IS NOT 
NULL;";
+       LogicalPlan plan = buildPlan(query);
+       
+       PhysicalPlan pp = buildPhysicalPlan(plan);
+       
+       int MAX_SIZE = 100000;
+       ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        pp.explain(baos);
+        String compiledPlan = baos.toString();
+        compiledPlan += "\n"; //for the string compare, the files contain an 
additional \n
+       FileInputStream fis1 = new 
FileInputStream("test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld");
+       FileInputStream fis2 = new 
FileInputStream("test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld");
+        byte[] b1 = new byte[MAX_SIZE];
+        byte[] b2 = new byte[MAX_SIZE];
+        int len = fis1.read(b1);
+        int test = fis2.read(b2);
+        //System.out.println("Length of first plan = " + len + " of second = " 
+ test + " Length of compiled plan = " + compiledPlan.length());
+        String goldenPlan1 = new String(b1, 0, len);
+        String goldenPlan2 = new String(b2, 0, len);
+
+
+        System.out.println();
+        System.out.println(compiledPlan);
+        System.out.println("-------------");
+        boolean flag = false;
+        //System.out.println("GoldenPlan1\n" + goldenPlan1 + "\nGoldenPlan2\n" 
+ goldenPlan2);
+        if(compiledPlan.compareTo(goldenPlan1) == 0 || 
compiledPlan.compareTo(goldenPlan2) == 0)
+               flag = true;
+        
+        //assertEquals(true, compiledPlan.compareTo(goldenPlan) == 0);
+        assertEquals(true, flag);
+       
+    }
+
     /[EMAIL PROTECTED]
     public void testUserFunc() throws VisitorException {
        String query = "foreach (group (load 'file:ABCD') all) generate " + 
COUNT.class.getName() + "($1) ;";

Modified: 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
 (original)
+++ 
incubator/pig/branches/types/test/org/apache/pig/test/TestLogicalPlanBuilder.java
 Wed May 28 07:38:12 2008
@@ -228,20 +228,10 @@
         LogicalPlan lp = buildPlan(query);
         LogicalOperator root = lp.getRoots().get(0);   
         
-        //System.err.println("testQuery18: root: " + 
root.getClass().getName());
-        //TODO
-        //Here I am looking out for LOLoad explicitly as the nested plan
-        //is not in place. This is a hack for now
-        if (!(root instanceof LOLoad)) root = lp.getRoots().get(1);
-        //System.err.println("testQuery18: root: " + 
root.getClass().getName());
-        
         List<LogicalOperator> listOp = lp.getSuccessors(root);
-        //listOp = lp.getSuccessors(listOp.get(0));
         
         LogicalOperator lo = listOp.get(0);
         
-        //System.err.println("testQuery18: lo: " + lo.getClass().getName());
-        
         if (lo instanceof LOCogroup) {
             assertTrue(((LOCogroup) lo).getRequestedParallelism() == 16);
         } else {
@@ -882,6 +872,15 @@
         buildPlan("b = foreach a {generate $0;} parallel 10;");
     }
     
+    @Test
+    public void testQuery76() {
+        buildPlan("split (load 'a') into x if $0 > '7', y if $0 < '7';");
+        buildPlan("b = filter x by $0 IS NULL;");
+        buildPlan("c = filter y by $0 IS NOT NULL;");
+        buildPlan("d = foreach b generate $0, ($1 IS NULL ? 0 : $1 - 7);");
+        buildPlan("e = foreach c generate $0, ($1 IS NOT NULL ? $1 - 5 : 0);");
+    }
+
     // Helper Functions
     
     // Helper Functions

Added: incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java?rev=660963&view=auto
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java (added)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java Wed May 
28 07:38:12 2008
@@ -0,0 +1,196 @@
+/*
+ * 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.test;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+import java.util.Random;
+
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.physicalLayer.Result;
+import 
org.apache.pig.impl.physicalLayer.expressionOperators.ConstantExpression;
+import org.apache.pig.impl.physicalLayer.expressionOperators.POIsNull;
+import org.apache.pig.test.utils.GenPhyOp;
+import org.apache.pig.test.utils.GenRandomData;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestNull extends junit.framework.TestCase {
+
+    @Before
+    public void setUp() throws Exception {
+    }
+
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    public static boolean test(byte type) throws ExecException {
+        Random r = new Random();
+        ConstantExpression lt = (ConstantExpression) GenPhyOp.exprConst();
+        lt.setResultType(type);
+        POIsNull isNullExpr = (POIsNull) GenPhyOp.compIsNullExpr();
+        isNullExpr.setInput(lt);
+
+        Object inp1;
+        Result res;
+        Boolean ret;
+        switch (type) {
+        case DataType.BAG:
+            inp1 = GenRandomData.genRandSmallTupDataBag(r, 10, 100);
+            res = isNullExpr.getNext((DataBag) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((DataBag) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.BOOLEAN:
+            inp1 = r.nextBoolean();
+            res = isNullExpr.getNext((Boolean) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Boolean) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.BYTEARRAY:
+            inp1 = GenRandomData.genRandDBA(r);
+            res = isNullExpr.getNext((DataByteArray) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((DataByteArray) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.CHARARRAY:
+            inp1 = GenRandomData.genRandString(r);
+            res = isNullExpr.getNext((String) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((String) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.DOUBLE:
+            inp1 = r.nextDouble();
+            res = isNullExpr.getNext((Double) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Double) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.FLOAT:
+            inp1 = r.nextFloat();
+            res = isNullExpr.getNext((Float) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Float) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.INTEGER:
+            inp1 = r.nextInt();
+            res = isNullExpr.getNext((Integer) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Integer) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.LONG:
+            inp1 = r.nextLong();
+            res = isNullExpr.getNext((Long) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Long) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.MAP:
+            inp1 = GenRandomData.genRandMap(r, 10);
+            res = isNullExpr.getNext((Map) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Map) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        case DataType.TUPLE:
+            inp1 = GenRandomData.genRandSmallBagTuple(r, 10, 100);
+            res = isNullExpr.getNext((Tuple) inp1);
+            if ((Boolean) res.result != true)
+                return false;
+            lt.setValue(inp1);
+            res = isNullExpr.getNext((Tuple) inp1);
+            ret = (DataType.compare(inp1, null) != 1);
+            if (res.result.equals(ret))
+                return true;
+            return false;
+        }
+        return true;
+    }
+
+    @Test
+    public void testOperator() throws ExecException {
+        int TRIALS = 10;
+        byte[] types = DataType.genAllTypes();
+        Map<Byte, String> map = DataType.genTypeToNameMap();
+        // System.out.println("Testing Not Equal To Expression:");
+
+        long t1 = System.currentTimeMillis();
+
+        for (byte b : types) {
+            boolean succ = true;
+            // System.out.print("\t With " + map.get(b) + ": ");
+            for (int i = 0; i < TRIALS; i++) {
+                succ &= test(b);
+            }
+            assertEquals(true, succ);
+            /*
+             * if (succ) System.out.println("Success!!"); else
+             * System.out.println("Failure");
+             */
+        }
+    }
+}

Added: 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld?rev=660963&view=auto
==============================================================================
--- 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld
 (added)
+++ 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull1.gld
 Wed May 28 07:38:12 2008
@@ -0,0 +1,19 @@
+Filter - Test-Plan-Builder-218
+|   |
+|   POIsNull - Test-Plan-Builder-220
+|   |
+|   |---Project(0) - Test-Plan-Builder-219
+|
+|---Split - Test-Plan-Builder-217
+    |
+    |---Load(a:org.apache.pig.builtin.PigStorage()) - Test-Plan-Builder-216
+
+Filter - Test-Plan-Builder-221
+|   |
+|   POIsNull - Test-Plan-Builder-223
+|   |
+|   |---Project(0) - Test-Plan-Builder-222
+|
+|---Split - Test-Plan-Builder-217
+    |
+    |---Load(a:org.apache.pig.builtin.PigStorage()) - Test-Plan-Builder-216

Added: 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld?rev=660963&view=auto
==============================================================================
--- 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld
 (added)
+++ 
incubator/pig/branches/types/test/org/apache/pig/test/data/GoldenFiles/IsNull2.gld
 Wed May 28 07:38:12 2008
@@ -0,0 +1,19 @@
+Filter - Test-Plan-Builder-221
+|   |
+|   POIsNull - Test-Plan-Builder-223
+|   |
+|   |---Project(0) - Test-Plan-Builder-222
+|
+|---Split - Test-Plan-Builder-217
+    |
+    |---Load(a:org.apache.pig.builtin.PigStorage()) - Test-Plan-Builder-216
+
+Filter - Test-Plan-Builder-218
+|   |
+|   POIsNull - Test-Plan-Builder-220
+|   |
+|   |---Project(0) - Test-Plan-Builder-219
+|
+|---Split - Test-Plan-Builder-217
+    |
+    |---Load(a:org.apache.pig.builtin.PigStorage()) - Test-Plan-Builder-216

Modified: 
incubator/pig/branches/types/test/org/apache/pig/test/utils/GenPhyOp.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/utils/GenPhyOp.java?rev=660963&r1=660962&r2=660963&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/utils/GenPhyOp.java 
(original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/utils/GenPhyOp.java 
Wed May 28 07:38:12 2008
@@ -88,6 +88,12 @@
         return ret;
     }
 
+    public static POIsNull compIsNullExpr() {
+        POIsNull ret = new POIsNull(new OperatorKey("", r
+                .nextLong()));
+        return ret;
+    }
+
     public static LessThanExpr compLessThanExpr() {
         LessThanExpr ret = new LessThanExpr(new OperatorKey("", r.nextLong()));
         return ret;


Reply via email to