You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2008/08/06 20:27:43 UTC

svn commit: r683358 [1/4] - in /incubator/pig/branches/types: src/org/apache/pig/backend/hadoop/ src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/ src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/ src/org/apache/pig/backe...

Author: gates
Date: Wed Aug  6 11:27:41 2008
New Revision: 683358

URL: http://svn.apache.org/viewvc?rev=683358&view=rev
Log:
PIG-336 Pradeep's massive changes for null.


Added:
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/KeyTypeDiscoveryVisitor.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableBooleanWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableBytesWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableDoubleWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableFloatWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableIntWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableLongWritable.java
    incubator/pig/branches/types/src/org/apache/pig/impl/io/NullableText.java
Modified:
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/HDataType.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/LocalLauncher.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceOper.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigCombiner.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapBase.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapReduce.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/PhysicalOperator.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Add.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/EqualToExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GTOrEqualToExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GreaterThanExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LTOrEqualToExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LessThanExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Mod.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Multiply.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/NotEqualToExpr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POAnd.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POIsNull.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONegative.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONot.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POOr.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PORegexp.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POUserFunc.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Subtract.java
    incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POFilter.java
    incubator/pig/branches/types/src/org/apache/pig/builtin/Utf8StorageConverter.java
    incubator/pig/branches/types/src/org/apache/pig/data/DataReaderWriter.java
    incubator/pig/branches/types/src/org/apache/pig/data/DefaultTuple.java
    incubator/pig/branches/types/src/org/apache/pig/data/TargetedTuple.java
    incubator/pig/branches/types/src/org/apache/pig/data/Tuple.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestAdd.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestBoolean.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestConstExpr.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestConversions.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestDivide.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestEqualTo.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestFilter.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestFilterOpString.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestForEach.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestForEachNestedPlan.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestGTOrEqual.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestGreaterThan.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestInfixArithmetic.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestLTOrEqual.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestLessThan.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestMod.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestMultiply.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestNotEqualTo.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestNull.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPOBinCond.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPOCast.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPODistinct.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPONegative.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestRegexp.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestSubtract.java
    incubator/pig/branches/types/test/org/apache/pig/test/utils/GenRandomData.java

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/HDataType.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/HDataType.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/HDataType.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/HDataType.java Wed Aug  6 11:27:41 2008
@@ -33,51 +33,59 @@
 import org.apache.pig.data.DataBag;
 import org.apache.pig.data.DataType;
 import org.apache.pig.data.DataByteArray;
+import org.apache.pig.data.DefaultTupleFactory;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.io.NullableBooleanWritable;
+import org.apache.pig.impl.io.NullableBytesWritable;
+import org.apache.pig.impl.io.NullableDoubleWritable;
+import org.apache.pig.impl.io.NullableFloatWritable;
+import org.apache.pig.impl.io.NullableIntWritable;
+import org.apache.pig.impl.io.NullableLongWritable;
+import org.apache.pig.impl.io.NullableText;
 
 /**
  * A class of helper methods for converting from pig data types to hadoop
  * data types, and vice versa.
  */
 public class HDataType {
-    static BooleanWritable boolWrit = new BooleanWritable();
-    static BytesWritable bytesWrit = new BytesWritable();
-    static Text stringWrit = new Text();
-    static FloatWritable floatWrit = new FloatWritable();
-    static DoubleWritable doubleWrit = new DoubleWritable();
-    static IntWritable intWrit = new IntWritable();
-    static LongWritable longWrit = new LongWritable();
+    static NullableBooleanWritable boolWrit = new NullableBooleanWritable();
+    static NullableBytesWritable bytesWrit = new NullableBytesWritable();
+    static NullableText stringWrit = new NullableText();
+    static NullableFloatWritable floatWrit = new NullableFloatWritable();
+    static NullableDoubleWritable doubleWrit = new NullableDoubleWritable();
+    static NullableIntWritable intWrit = new NullableIntWritable();
+    static NullableLongWritable longWrit = new NullableLongWritable();
     static DataBag defDB = BagFactory.getInstance().newDefaultBag();
     static Tuple defTup = TupleFactory.getInstance().newTuple();
     static Map<Byte, String> typeToName = null;
 
-    public static WritableComparable getWritableComparableTypes(Object o) throws ExecException{
+    public static WritableComparable getWritableComparableTypes(Object o, byte keyType) throws ExecException{
         byte type = DataType.findType(o);
         switch (type) {
         case DataType.BAG:
             return (DataBag)o;
 
         case DataType.BOOLEAN:
-            return new BooleanWritable((Boolean)o);
+            return new NullableBooleanWritable((Boolean)o);
 
         case DataType.BYTEARRAY:
-            return new BytesWritable(((DataByteArray)o).get());
+            return new NullableBytesWritable(((DataByteArray)o).get());
             
         case DataType.CHARARRAY:
-            return new Text((String)o);
+            return new NullableText((String)o);
             
         case DataType.DOUBLE:
-            return new DoubleWritable((Double)o);
+            return new NullableDoubleWritable((Double)o);
            
         case DataType.FLOAT:
-            return new FloatWritable((Float)o);
+            return new NullableFloatWritable((Float)o);
             
         case DataType.INTEGER:
-            return new IntWritable((Integer)o);
+            return new NullableIntWritable((Integer)o);
            
         case DataType.LONG:
-            return new LongWritable((Long)o);
+            return new NullableLongWritable((Long)o);
           
         case DataType.TUPLE:
             return (Tuple) o;
@@ -88,12 +96,59 @@
             // MapWritable
             // wcKey = new MapWritable();
 //            break;
+        case DataType.NULL:
+            switch (keyType) {
+            case DataType.BAG:
+                //TODO: create a null data bag
+                break;
+            case DataType.BOOLEAN:
+                NullableBooleanWritable nboolWrit = new NullableBooleanWritable();
+                nboolWrit.setNull(true);
+                return nboolWrit;
+            case DataType.BYTEARRAY:
+                NullableBytesWritable nBytesWrit = new NullableBytesWritable(); 
+                nBytesWrit.setNull(true);
+                return nBytesWrit;
+            case DataType.CHARARRAY:
+                NullableText nStringWrit = new NullableText();
+                nStringWrit.setNull(true);
+                return nStringWrit;
+            case DataType.DOUBLE:
+                NullableDoubleWritable nDoubleWrit = new NullableDoubleWritable();
+                nDoubleWrit.setNull(true);
+                return nDoubleWrit;
+            case DataType.FLOAT:
+                NullableFloatWritable nFloatWrit = new NullableFloatWritable();
+                nFloatWrit.setNull(true);
+                return nFloatWrit;
+            case DataType.INTEGER:
+                NullableIntWritable nIntWrit = new NullableIntWritable();
+                nIntWrit.setNull(true);
+                return nIntWrit;
+            case DataType.LONG:
+                NullableLongWritable nLongWrit = new NullableLongWritable();
+                nLongWrit.setNull(true);
+                return nLongWrit;
+            case DataType.TUPLE:
+                Tuple t = DefaultTupleFactory.getInstance().newTuple();
+                t.setNull(true);
+                return t;
+//            case DataType.MAP:
+                // Hmm, This is problematic
+                // Need a deep clone to convert a Map into
+                // MapWritable
+                // wcKey = new MapWritable();
+//                break;
+            }
+            break;
         default:
             if (typeToName == null) typeToName = DataType.genTypeToNameMap();
             throw new ExecException("The type "
                     + typeToName.get(type)
                     + " cannot be collected as a Key type");
         }
+        // should never come here
+        return null;
     }
     
     public static WritableComparable getWritableComparableTypes(byte type) throws ExecException{
@@ -142,24 +197,38 @@
     }
     
     public static Object convertToPigType(WritableComparable key) {
-        if ((key instanceof DataBag) || (key instanceof Tuple))
+        if ((key instanceof DataBag) )
             return key;
-        if (key instanceof BooleanWritable)
-            return ((BooleanWritable) key).get();
-        if (key instanceof BytesWritable) {
-            return new DataByteArray(((BytesWritable) key).get(), 0,
-                ((BytesWritable)key).getSize());
-        }
-        if (key instanceof Text)
-            return ((Text) key).toString();
-        if (key instanceof FloatWritable)
-            return ((FloatWritable) key).get();
-        if (key instanceof DoubleWritable)
-            return ((DoubleWritable) key).get();
-        if (key instanceof IntWritable)
-            return ((IntWritable) key).get();
-        if (key instanceof LongWritable)
-            return ((LongWritable) key).get();
+        if(key instanceof Tuple)
+           return ((Tuple)key).isNull() ? null : key;     
+        if (key instanceof NullableBooleanWritable) {
+            NullableBooleanWritable bWrit = (NullableBooleanWritable)key;   
+            return bWrit.isNull() ? null :bWrit.get();
+        }
+        if (key instanceof NullableBytesWritable) {
+            NullableBytesWritable byWrit = (NullableBytesWritable) key; 
+            return byWrit.isNull() ? null : new DataByteArray(byWrit.get(), 0, byWrit.getSize());
+        }
+        if (key instanceof NullableText) {
+            NullableText tWrit =  (NullableText) key;
+            return tWrit.isNull() ? null :tWrit.toString();
+        }
+        if (key instanceof NullableFloatWritable) {
+            NullableFloatWritable fWrit = (NullableFloatWritable) key;
+            return fWrit == null ? null : fWrit.get();
+        }
+        if (key instanceof NullableDoubleWritable) {
+            NullableDoubleWritable dWrit = (NullableDoubleWritable) key;
+            return dWrit.isNull() ? null : dWrit.get();
+        }
+        if (key instanceof NullableIntWritable) {
+            NullableIntWritable iWrit = (NullableIntWritable) key;
+            return iWrit.isNull() ? null : iWrit.get();
+        }
+        if (key instanceof NullableLongWritable) {
+            NullableLongWritable lWrit = (NullableLongWritable) key;
+            return lWrit.isNull() ? null : lWrit.get();
+        }
         return null;
     }
 }

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/JobControlCompiler.java Wed Aug  6 11:27:41 2008
@@ -248,6 +248,11 @@
             FileOutputFormat.setOutputPath(jobConf, new Path(outputPath));
             jobConf.set("pig.storeFunc", outputFuncSpec.toString());
             
+            // store map key type
+            // this is needed when the key is null to create
+            // an appropriate NullableXXXWritable object
+            jobConf.set("pig.map.keytype", ObjectSerializer.serialize(new byte[] { mro.mapKeyType }));
+            
             if(mro.reducePlan.isEmpty()){
                 //MapOnly Job
                 jobConf.setMapperClass(PigMapOnly.Map.class);

Added: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/KeyTypeDiscoveryVisitor.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/KeyTypeDiscoveryVisitor.java?rev=683358&view=auto
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/KeyTypeDiscoveryVisitor.java (added)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/KeyTypeDiscoveryVisitor.java Wed Aug  6 11:27:41 2008
@@ -0,0 +1,66 @@
+/**
+ * 
+ */
+package org.apache.pig.backend.hadoop.executionengine.mapReduceLayer;
+
+import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROpPlanVisitor;
+import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.plans.MROperPlan;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackage;
+import org.apache.pig.impl.plan.DepthFirstWalker;
+import org.apache.pig.impl.plan.PlanWalker;
+import org.apache.pig.impl.plan.VisitorException;
+
+/**
+ * A visitor to figure out the type of the key for the map plan
+ * this is needed when the key is null to create
+ * an appropriate NullableXXXWritable object
+ */
+public class KeyTypeDiscoveryVisitor extends MROpPlanVisitor {
+
+    
+    /* (non-Javadoc)
+     * @see org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor#visitLocalRearrange(org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange)
+     */
+    /**
+     * @param plan The MROperPlan to visit to discover keyType
+     */
+    public KeyTypeDiscoveryVisitor(MROperPlan plan) {
+        super(plan, new DepthFirstWalker<MapReduceOper, MROperPlan>(plan));
+    }
+    
+    @Override
+    public void visitMROp(MapReduceOper mr) throws VisitorException {
+        PhyPlanKeyTypeVisitor kvisitor = new PhyPlanKeyTypeVisitor(mr.mapPlan, mr);
+        kvisitor.visit();
+    }
+    
+    class PhyPlanKeyTypeVisitor extends PhyPlanVisitor {
+        
+        private MapReduceOper mro;
+        
+        public PhyPlanKeyTypeVisitor(PhysicalPlan plan, MapReduceOper mro) {
+            super(plan, new DepthFirstWalker<PhysicalOperator, PhysicalPlan>(plan));
+            this.mro = mro;
+        }
+        
+        /* (non-Javadoc)
+         * @see org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor#visitPackage(org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POPackage)
+         */
+        @Override
+        public void visitPackage(POPackage pkg) throws VisitorException {
+            this.mro.mapKeyType = pkg.getKeyType();        
+        }
+    
+    
+        @Override
+        public void visitLocalRearrange(POLocalRearrange lr)
+                throws VisitorException {
+            this.mro.mapKeyType = lr.getKeyType();        
+        }
+    }
+
+}

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/LocalLauncher.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/LocalLauncher.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/LocalLauncher.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/LocalLauncher.java Wed Aug  6 11:27:41 2008
@@ -111,6 +111,11 @@
             CombinerOptimizer co = new CombinerOptimizer(plan);
             co.visit();
         }
+        // figure out the type of the key for the map plan
+        // this is needed when the key is null to create
+        // an appropriate NullableXXXWritable object
+        KeyTypeDiscoveryVisitor kdv = new KeyTypeDiscoveryVisitor(plan);
+        kdv.visit();
         return plan;
     }
 

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceLauncher.java Wed Aug  6 11:27:41 2008
@@ -128,6 +128,11 @@
             CombinerOptimizer co = new CombinerOptimizer(plan);
             co.visit();
         }
+        // figure out the type of the key for the map plan
+        // this is needed when the key is null to create
+        // an appropriate NullableXXXWritable object
+        KeyTypeDiscoveryVisitor kdv = new KeyTypeDiscoveryVisitor(plan);
+        kdv.visit();     
         return plan;
     }
  

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceOper.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceOper.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceOper.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/MapReduceOper.java Wed Aug  6 11:27:41 2008
@@ -53,6 +53,11 @@
     //by the optimizer.
     public PhysicalPlan combinePlan;
     
+    // key for the map plan
+    // this is needed when the key is null to create
+    // an appropriate NullableXXXWritable object
+    public byte mapKeyType;
+    
     //Indicates that the map plan creation
     //is complete
     boolean mapDone = false;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigCombiner.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigCombiner.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigCombiner.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigCombiner.java Wed Aug  6 11:27:41 2008
@@ -45,7 +45,9 @@
 import org.apache.pig.data.IndexedTuple;
 import org.apache.pig.data.TargetedTuple;
 import org.apache.pig.data.Tuple;
+import org.apache.pig.impl.plan.VisitorException;
 import org.apache.pig.impl.util.ObjectSerializer;
+import org.apache.pig.impl.util.WrappedIOException;
 
 /**
  * This class is the static Mapper &amp; Reducer classes that
@@ -74,6 +76,8 @@
             implements
             Reducer<WritableComparable, IndexedTuple, WritableComparable, Writable> {
         private final Log log = LogFactory.getLog(getClass());
+
+        private byte keyType;
         
         //The reduce plan
         private PhysicalPlan cp;
@@ -107,6 +111,8 @@
                     cp.explain(baos);
                     log.debug(baos.toString());
                 }
+                
+                keyType = ((byte[])ObjectSerializer.deserialize(jConf.get("pig.map.keytype")))[0];
                 // till here
                 
                 long sleepTime = jConf.getLong("pig.reporter.sleep.time", 10000);
@@ -148,7 +154,7 @@
                     cp.attachInput(packRes);
 
                     List<PhysicalOperator> leaves = cp.getLeaves();
-                    
+
                     PhysicalOperator leaf = leaves.get(0);
                     while(true){
                         Result redRes = leaf.getNext(t);
@@ -157,7 +163,7 @@
                             Tuple tuple = (Tuple)redRes.result;
                             Object combKey = tuple.get(0);
                             IndexedTuple it = (IndexedTuple)tuple.get(1);
-                            WritableComparable wcKey = HDataType.getWritableComparableTypes(combKey);
+                            WritableComparable wcKey = HDataType.getWritableComparableTypes(combKey, this.keyType);
                             oc.collect(wcKey, it);
                             continue;
                         }
@@ -204,6 +210,20 @@
                 runnableReporter.setDone(true);*/
             PhysicalOperator.setReporter(null);
         }
+
+        /**
+         * @return the keyType
+         */
+        public byte getKeyType() {
+            return keyType;
+        }
+
+        /**
+         * @param keyType the keyType to set
+         */
+        public void setKeyType(byte keyType) {
+            this.keyType = keyType;
+        }
     }
     
 }

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapBase.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapBase.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapBase.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapBase.java Wed Aug  6 11:27:41 2008
@@ -17,17 +17,22 @@
 import org.apache.pig.data.TargetedTuple;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.impl.plan.OperatorKey;
+import org.apache.pig.impl.plan.VisitorException;
 import org.apache.pig.backend.hadoop.datastorage.ConfigurationUtil;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhysicalPlan;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.relationalOperators.POLocalRearrange;
 import org.apache.pig.impl.util.ObjectSerializer;
 import org.apache.pig.impl.util.SpillableMemoryManager;
+import org.apache.pig.impl.util.WrappedIOException;
 
 public abstract class PigMapBase extends MapReduceBase{
     private final Log log = LogFactory.getLog(getClass());
+
+    protected byte keyType;
     
     //Map Plan
     protected PhysicalPlan mp;
@@ -68,6 +73,7 @@
                 mp.explain(baos);
                 log.debug(baos.toString());
             }
+            keyType = ((byte[])ObjectSerializer.deserialize(job.get("pig.map.keytype")))[0];
             // till here
             
             long sleepTime = job.getLong("pig.reporter.sleep.time", 10000);
@@ -115,8 +121,9 @@
         List<PhysicalOperator> leaves = mp.getLeaves();
         
         PhysicalOperator leaf = leaves.get(0);
+        
         try {
-            while(true){
+            while(true){                
                 Result res = leaf.getNext(inpTuple);
                 if(res.returnStatus==POStatus.STATUS_OK){
                     collect(oc,(Tuple)res.result);
@@ -143,5 +150,19 @@
     }
 
     abstract public void collect(OutputCollector<WritableComparable, Writable> oc, Tuple tuple) throws ExecException, IOException;
+
+    /**
+     * @return the keyType
+     */
+    public byte getKeyType() {
+        return keyType;
+    }
+
+    /**
+     * @param keyType the keyType to set
+     */
+    public void setKeyType(byte keyType) {
+        this.keyType = keyType;
+    }
     
 }

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapReduce.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapReduce.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapReduce.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/PigMapReduce.java Wed Aug  6 11:27:41 2008
@@ -79,7 +79,7 @@
         public void collect(OutputCollector<WritableComparable, Writable> oc, Tuple tuple) throws ExecException, IOException {
             Object key = tuple.get(0);
             IndexedTuple it = (IndexedTuple)tuple.get(1);
-            WritableComparable wcKey = HDataType.getWritableComparableTypes(key);
+            WritableComparable wcKey = HDataType.getWritableComparableTypes(key, keyType);
             oc.collect(wcKey, it);
         }
     }
@@ -167,7 +167,6 @@
                     PhysicalOperator leaf = leaves.get(0);
                     while(true){
                         Result redRes = leaf.getNext(t);
-                        
                         if(redRes.returnStatus==POStatus.STATUS_OK){
                             oc.collect(null, (Tuple)redRes.result);
                             continue;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/LogToPhyTranslationVisitor.java Wed Aug  6 11:27:41 2008
@@ -37,6 +37,7 @@
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.*;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.ExpressionOperator;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.BinaryExpressionOperator;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.expressionOperators.UnaryExpressionOperator;
 import org.apache.pig.impl.logicalLayer.*;
 import org.apache.pig.impl.plan.DependencyOrderWalker;
 import org.apache.pig.impl.plan.DependencyOrderWalkerWOSeenChk;
@@ -935,8 +936,9 @@
     @Override
     public void visit(LOIsNull op) throws VisitorException {
         String scope = op.getOperatorKey().scope;
-        ExpressionOperator physOp = new POIsNull(new OperatorKey(scope, nodeGen
+        UnaryComparisonOperator physOp = new POIsNull(new OperatorKey(scope, nodeGen
                 .getNextNodeId(scope)), op.getRequestedParallelism(), null);
+        physOp.setOperandType(op.getOperand().getType());
         currentPlan.add(physOp);
 
         LogToPhyMap.put(op, physOp);

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/PhysicalOperator.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/PhysicalOperator.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/PhysicalOperator.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/PhysicalOperator.java Wed Aug  6 11:27:41 2008
@@ -216,7 +216,7 @@
             return inputs.get(0).getNext(inpValue);
         } else {
             res.result = input;
-            res.returnStatus = POStatus.STATUS_OK;
+            res.returnStatus = (res.result == null ? POStatus.STATUS_NULL: POStatus.STATUS_OK);
             detachInput();
             return res;
         }

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Add.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Add.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Add.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Add.java Wed Aug  6 11:27:41 2008
@@ -58,14 +58,14 @@
         Double left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Double) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Double) res.result;
@@ -81,14 +81,14 @@
         Float left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Float) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Float) res.result;
@@ -104,14 +104,14 @@
         Integer left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Integer) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Integer) res.result;
@@ -127,14 +127,14 @@
         Long left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Long) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Long) res.result;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Divide.java Wed Aug  6 11:27:41 2008
@@ -58,14 +58,14 @@
         Double left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Double) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Double) res.result;
@@ -81,14 +81,14 @@
         Float left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Float) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Float) res.result;
@@ -104,14 +104,14 @@
         Integer left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Integer) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Integer) res.result;
@@ -127,14 +127,14 @@
         Long left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Long) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Long) res.result;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/EqualToExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/EqualToExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/EqualToExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/EqualToExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) == 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GTOrEqualToExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GTOrEqualToExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GTOrEqualToExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GTOrEqualToExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) >= 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GreaterThanExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GreaterThanExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GreaterThanExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/GreaterThanExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) > 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LTOrEqualToExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LTOrEqualToExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LTOrEqualToExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LTOrEqualToExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) <= 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LessThanExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LessThanExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LessThanExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/LessThanExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) < 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Mod.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Mod.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Mod.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Mod.java Wed Aug  6 11:27:41 2008
@@ -58,14 +58,14 @@
         Integer left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Integer) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Integer) res.result;
@@ -81,14 +81,14 @@
         Long left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Long) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Long) res.result;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Multiply.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Multiply.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Multiply.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Multiply.java Wed Aug  6 11:27:41 2008
@@ -58,14 +58,14 @@
         Double left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Double) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Double) res.result;
@@ -81,14 +81,14 @@
         Float left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Float) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Float) res.result;
@@ -104,14 +104,14 @@
         Integer left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Integer) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Integer) res.result;
@@ -127,14 +127,14 @@
         Long left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Long) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Long) res.result;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/NotEqualToExpr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/NotEqualToExpr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/NotEqualToExpr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/NotEqualToExpr.java Wed Aug  6 11:27:41 2008
@@ -110,6 +110,13 @@
         if (trueRef == null) initializeRefs();
         if (left.returnStatus != POStatus.STATUS_OK) return left;
         if (right.returnStatus != POStatus.STATUS_OK) return right;
+        // if either operand is null, the result should be
+        // null
+        if(left.result == null || right.result == null) {
+            left.result = null;
+            left.returnStatus = POStatus.STATUS_NULL;
+            return left;
+        }
         assert(left instanceof Comparable);
         assert(right instanceof Comparable);
         if (((Comparable)left.result).compareTo((Comparable)right.result) != 0) {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POAnd.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POAnd.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POAnd.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POAnd.java Wed Aug  6 11:27:41 2008
@@ -60,15 +60,22 @@
     public Result getNext(Boolean b) throws ExecException {
         Result left;
         left = lhs.getNext(dummyBool);
-        if(left.returnStatus != POStatus.STATUS_OK) {
+        if(left.returnStatus != POStatus.STATUS_OK || left.result == null) {
             return left;
         }
-        // Short circuit.
+        
+        // Cannot short circuit since rhs could be null and then we should
+        // be returning null.
+        Result right = rhs.getNext(dummyBool);
+        if(right.returnStatus != POStatus.STATUS_OK || right.result == null) {
+        	return right;
+        }
+        
         if (!(((Boolean)left.result).booleanValue())) return left;
         
         // No matter what, what we get from the right side is what we'll
         // return, error, null, true, or false.
-        return rhs.getNext(dummyBool);
+        return right;
     }
 
     @Override

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java Wed Aug  6 11:27:41 2008
@@ -107,7 +107,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new Integer(Integer.valueOf((((DataByteArray)res.result).toString())));
         		dba = (DataByteArray) res.result;
         		try {
@@ -128,7 +128,7 @@
         case DataType.BOOLEAN : {
         	Boolean b = null;
         	Result res = in.getNext(b);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		if (((Boolean)res.result) == true) res.result = new Integer(1);
                 else res.result = new Integer(0);
         	}
@@ -143,7 +143,7 @@
         case DataType.DOUBLE : {
         	Double d = null;
         	Result res = in.getNext(d);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = DataType.toInteger(res.result);
         		res.result = new Integer(((Double)res.result).intValue());
         	}
@@ -153,7 +153,7 @@
         case DataType.LONG : {
         	Long l = null;
         	Result res = in.getNext(l);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Integer(((Long)res.result).intValue());
         	}
         	return res;
@@ -162,7 +162,7 @@
         case DataType.FLOAT : {
         	Float f = null;
         	Result res = in.getNext(f);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Integer(((Float)res.result).intValue());
         	}
         	return res;
@@ -171,7 +171,7 @@
         case DataType.CHARARRAY : {
         	String str = null;
         	Result res = in.getNext(str);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Integer(Integer.valueOf((String)res.result));
         	}
         	return res;
@@ -210,7 +210,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new Long(Long.valueOf((((DataByteArray)res.result).toString())));
         		dba = (DataByteArray) res.result;
         		try {
@@ -225,7 +225,7 @@
         case DataType.BOOLEAN : {
         	Boolean b = null;
         	Result res = in.getNext(b);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		if (((Boolean)res.result) == true) res.result = new Long(1);
                 else res.result = new Long(0);
         	}
@@ -234,7 +234,7 @@
         case DataType.INTEGER : {
         	Integer dummyI = null;
         	Result res = in.getNext(dummyI);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Long(((Integer)res.result).longValue());
         	}
         	return res;
@@ -243,7 +243,7 @@
         case DataType.DOUBLE : {
         	Double d = null;
         	Result res = in.getNext(d);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = DataType.toInteger(res.result);
         		res.result = new Long(((Double)res.result).longValue());
         	}
@@ -260,7 +260,7 @@
         case DataType.FLOAT : {
         	Float f = null;
         	Result res = in.getNext(f);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Long(((Float)res.result).longValue());
         	}
         	return res;
@@ -269,7 +269,7 @@
         case DataType.CHARARRAY : {
         	String str = null;
         	Result res = in.getNext(str);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Long(Long.valueOf((String)res.result));
         	}
         	return res;
@@ -308,7 +308,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new Double(Double.valueOf((((DataByteArray)res.result).toString())));
         		dba = (DataByteArray) res.result;
         		try {
@@ -323,7 +323,7 @@
         case DataType.BOOLEAN : {
         	Boolean b = null;
         	Result res = in.getNext(b);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		if (((Boolean)res.result) == true) res.result = new Double(1);
                 else res.result = new Double(0);
         	}
@@ -332,7 +332,7 @@
         case DataType.INTEGER : {
         	Integer dummyI = null;
         	Result res = in.getNext(dummyI);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Double(((Integer)res.result).doubleValue());
         	}
         	return res;
@@ -348,7 +348,7 @@
         case DataType.LONG : {
         	Long l = null;
         	Result res = in.getNext(l);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Double(((Long)res.result).doubleValue());
         	}
         	return res;
@@ -357,7 +357,7 @@
         case DataType.FLOAT : {
         	Float f = null;
         	Result res = in.getNext(f);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Double(((Float)res.result).doubleValue());
         	}
         	return res;
@@ -366,7 +366,7 @@
         case DataType.CHARARRAY : {
         	String str = null;
         	Result res = in.getNext(str);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Double(Double.valueOf((String)res.result));
         	}
         	return res;
@@ -405,7 +405,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new Float(Float.valueOf((((DataByteArray)res.result).toString())));
         		dba = (DataByteArray) res.result;
         		try {
@@ -420,7 +420,7 @@
         case DataType.BOOLEAN : {
         	Boolean b = null;
         	Result res = in.getNext(b);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		if (((Boolean)res.result) == true) res.result = new Float(1);
                 else res.result = new Float(0);
         	}
@@ -429,7 +429,7 @@
         case DataType.INTEGER : {
         	Integer dummyI = null;
         	Result res = in.getNext(dummyI);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Float(((Integer)res.result).floatValue());
         	}
         	return res;
@@ -438,7 +438,7 @@
         case DataType.DOUBLE : {
         	Double d = null;
         	Result res = in.getNext(d);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = DataType.toInteger(res.result);
         		res.result = new Float(((Double)res.result).floatValue());
         	}
@@ -449,7 +449,7 @@
         	
         	Long l = null;
         	Result res = in.getNext(l);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Float(((Long)res.result).floatValue());
         	}
         	return res;
@@ -465,7 +465,7 @@
         case DataType.CHARARRAY : {
         	String str = null;
         	Result res = in.getNext(str);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new Float(Float.valueOf((String)res.result));
         	}
         	return res;
@@ -504,7 +504,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new String(((DataByteArray)res.result).toString());
         		dba = (DataByteArray) res.result;
         		try {
@@ -519,7 +519,7 @@
         case DataType.BOOLEAN : {
         	Boolean b = null;
         	Result res = in.getNext(b);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		if (((Boolean)res.result) == true) res.result = new String("1");
                 else res.result = new String("1");
         	}
@@ -528,7 +528,7 @@
         case DataType.INTEGER : {
         	Integer dummyI = null;
         	Result res = in.getNext(dummyI);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new String(((Integer)res.result).toString());
         	}
         	return res;
@@ -537,7 +537,7 @@
         case DataType.DOUBLE : {
         	Double d = null;
         	Result res = in.getNext(d);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = DataType.toInteger(res.result);
         		res.result = new String(((Double)res.result).toString());
         	}
@@ -548,7 +548,7 @@
         	
         	Long l = null;
         	Result res = in.getNext(l);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new String(((Long)res.result).toString());
         	}
         	return res;
@@ -557,7 +557,7 @@
         case DataType.FLOAT : {
         	Float f = null;
         	Result res = in.getNext(f);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		res.result = new String(((Float)res.result).toString());
         	}
         	return res;
@@ -591,7 +591,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new String(((DataByteArray)res.result).toString());
         		dba = (DataByteArray) res.result;
         		try {
@@ -645,7 +645,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new String(((DataByteArray)res.result).toString());
         		dba = (DataByteArray) res.result;
         		try {
@@ -699,7 +699,7 @@
         case DataType.BYTEARRAY : {
         	DataByteArray dba = null;
         	Result res = in.getNext(dba);
-        	if(res.returnStatus == POStatus.STATUS_OK) {
+        	if(res.returnStatus == POStatus.STATUS_OK && res.result != null) {
         		//res.result = new String(((DataByteArray)res.result).toString());
         		dba = (DataByteArray) res.result;
         		try {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POIsNull.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POIsNull.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POIsNull.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POIsNull.java Wed Aug  6 11:27:41 2008
@@ -21,6 +21,7 @@
 
 import org.apache.pig.backend.executionengine.ExecException;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.POStatus;
+import org.apache.pig.backend.hadoop.executionengine.physicalLayer.PhysicalOperator;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.Result;
 import org.apache.pig.backend.hadoop.executionengine.physicalLayer.plans.PhyPlanVisitor;
 import org.apache.pig.data.DataBag;
@@ -60,133 +61,114 @@
     }
 
     @Override
-    public Result getNext(Double d) throws ExecException {
-        Result res = expr.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 = expr.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 = expr.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 = expr.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 = expr.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 = expr.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 = expr.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 = expr.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 = expr.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 = expr.getNext(m);
-        if(res.returnStatus == POStatus.STATUS_OK) {
-            if ((Map)res.result == null) {
-                res.result = true;
-            } else {
-                res.result = false;
-            }
+        
+        Result res = null;
+        switch(operandType) {
+        case DataType.BYTEARRAY:
+            res = expr.getNext(dummyDBA);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.DOUBLE:
+            res = expr.getNext(dummyDouble);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.INTEGER:
+            res = expr.getNext(dummyInt);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.CHARARRAY:
+            res = expr.getNext(dummyString);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.BOOLEAN:
+            res = expr.getNext(dummyBool);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.LONG:
+            res = expr.getNext(dummyLong);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.FLOAT:
+            res = expr.getNext(dummyFloat);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.MAP:
+            res = expr.getNext(dummyMap);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.TUPLE:
+            res = expr.getNext(dummyTuple);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;
+        case DataType.BAG:
+            res = expr.getNext(dummyBag);
+            if(res.returnStatus == POStatus.STATUS_OK) {
+                if (res.result == null) {
+                    res.result = true;
+                } else {
+                    res.result = false;
+                }
+            }
+            return res;        
+        default:
+            throw new RuntimeException("'is null' to doesn't know how to " +
+                "handle type " + DataType.findTypeName(operandType));
         }
-        return res;
     }
 
     @Override

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONegative.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONegative.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONegative.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONegative.java Wed Aug  6 11:27:41 2008
@@ -57,16 +57,18 @@
     @Override
     public Result getNext(Double d) throws ExecException {
         Result res = expr.getNext(d);
-        if(res.returnStatus == POStatus.STATUS_OK) {
-            res.result = -1*((Double)res.result);
-        }
+        if(res.returnStatus == POStatus.STATUS_OK && res.result!=null) {
+         		res.result = -1*((Double)res.result);
+
+       }
+       
         return res;
     }
 
     @Override
     public Result getNext(Float f) throws ExecException {
         Result res = expr.getNext(f);
-        if(res.returnStatus == POStatus.STATUS_OK) {
+        if(res.returnStatus == POStatus.STATUS_OK && res.result!=null ) {
             res.result = -1*((Float)res.result);
         }
         return res;
@@ -75,7 +77,7 @@
     @Override
     public Result getNext(Integer i) throws ExecException {
         Result res = expr.getNext(i);
-        if(res.returnStatus == POStatus.STATUS_OK) {
+        if(res.returnStatus == POStatus.STATUS_OK && res.result!=null ) {
             res.result = -1*((Integer)res.result);
         }
         return res;
@@ -84,7 +86,7 @@
     @Override
     public Result getNext(Long l) throws ExecException {
         Result res = expr.getNext(l);
-        if(res.returnStatus == POStatus.STATUS_OK) {
+        if(res.returnStatus == POStatus.STATUS_OK && res.result!=null) {
             res.result = -1*((Long)res.result);
         }
         return res;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONot.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONot.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONot.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PONot.java Wed Aug  6 11:27:41 2008
@@ -69,7 +69,7 @@
             falseRes.result = new Boolean(false);
         }
         res = expr.getNext(dummyBool);
-        if(res.returnStatus != POStatus.STATUS_OK) {
+        if(res.returnStatus != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         if (((Boolean)res.result).booleanValue()) return falseRes;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POOr.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POOr.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POOr.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POOr.java Wed Aug  6 11:27:41 2008
@@ -60,15 +60,22 @@
     public Result getNext(Boolean b) throws ExecException {
         Result left;
         left = lhs.getNext(dummyBool);
-        if(left.returnStatus != POStatus.STATUS_OK) {
+        if(left.returnStatus != POStatus.STATUS_OK || left.result == null) {
             return left;
         }
-        // Short circuit.
+        
+        // Cannot short circuit since rhs could be null and then we should
+        // be returning null.
+        Result right = rhs.getNext(dummyBool);
+        if(right.returnStatus != POStatus.STATUS_OK || right.result == null) {
+        	return right;
+        }
+        
         if (((Boolean)left.result).booleanValue()) return left;
         
         // No matter what, what we get from the right side is what we'll
         // return, error, null, true, or false.
-        return rhs.getNext(dummyBool);
+        return right;
     }
 
     @Override

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PORegexp.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PORegexp.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PORegexp.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/PORegexp.java Wed Aug  6 11:27:41 2008
@@ -63,8 +63,8 @@
         right = rhs.getNext(dummyString);
 
         if (trueRef == null) initializeRefs();
-        if (left.returnStatus != POStatus.STATUS_OK) return left;
-        if (right.returnStatus != POStatus.STATUS_OK) return right;
+        if (left.returnStatus != POStatus.STATUS_OK || left.result == null) return left;
+        if (right.returnStatus != POStatus.STATUS_OK || right.result == null) return right;
         if (((String)left.result).matches((String)right.result)) {
             left.result = trueRef;
         } else {

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POUserFunc.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POUserFunc.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POUserFunc.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POUserFunc.java Wed Aug  6 11:27:41 2008
@@ -171,7 +171,7 @@
 			if(result.returnStatus == POStatus.STATUS_OK) {
 				result.result = func.exec((Tuple) result.result);
                 if(resultType == DataType.BYTEARRAY) {
-                    if(DataType.findType(result.result) != DataType.BYTEARRAY) {
+                    if(res.result != null && DataType.findType(result.result) != DataType.BYTEARRAY) {
                         result.result = new DataByteArray(result.result.toString().getBytes());
                     }
                 }

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Subtract.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Subtract.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Subtract.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/Subtract.java Wed Aug  6 11:27:41 2008
@@ -58,14 +58,14 @@
         Double left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Double) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Double) res.result;
@@ -81,14 +81,14 @@
         Float left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Float) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Float) res.result;
@@ -104,14 +104,14 @@
         Integer left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Integer) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Integer) res.result;
@@ -127,14 +127,14 @@
         Long left = null, right = null;
         res = lhs.getNext(left);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         left = (Long) res.result;
         
         res = rhs.getNext(right);
         status = res.returnStatus;
-        if(status != POStatus.STATUS_OK) {
+        if(status != POStatus.STATUS_OK || res.result == null) {
             return res;
         }
         right = (Long) res.result;

Modified: incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POFilter.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POFilter.java?rev=683358&r1=683357&r2=683358&view=diff
==============================================================================
--- incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POFilter.java (original)
+++ incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/relationalOperators/POFilter.java Wed Aug  6 11:27:41 2008
@@ -143,9 +143,11 @@
             }
             */
             res = comOp.getNext(dummyBool);
-            if (res.returnStatus != POStatus.STATUS_OK) return res;
+            if (res.returnStatus != POStatus.STATUS_OK 
+                    && res.returnStatus != POStatus.STATUS_NULL) 
+                return res;
 
-            if ((Boolean) res.result == true) {
+            if (res.result != null && (Boolean) res.result == true) {
                 return inp;
             }
         }