Author: olga
Date: Thu Aug 21 12:26:30 2008
New Revision: 687835

URL: http://svn.apache.org/viewvc?rev=687835&view=rev
Log:
PIG-381 and PIG-382: problems with bincond

Modified:
    incubator/pig/branches/types/CHANGES.txt
    
incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POBinCond.java
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/parser/QueryParser.jjt
    
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java

Modified: incubator/pig/branches/types/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/CHANGES.txt?rev=687835&r1=687834&r2=687835&view=diff
==============================================================================
--- incubator/pig/branches/types/CHANGES.txt (original)
+++ incubator/pig/branches/types/CHANGES.txt Thu Aug 21 12:26:30 2008
@@ -161,3 +161,7 @@
     PIG-378: fix for GENERATE + LIMIT
 
     PIG-362: don't push limit above generate with flatten
+
+    PIG-381: bincond does not handle null data
+
+    PIG-382: bincond throws typecast exception

Modified: 
incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POBinCond.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POBinCond.java?rev=687835&r1=687834&r2=687835&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POBinCond.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POBinCond.java
 Thu Aug 21 12:26:30 2008
@@ -54,7 +54,7 @@
     @Override
     public Result getNext(Boolean b) throws ExecException {
         Result res = cond.getNext(b);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(b) : rhs.getNext(b);
         
     }
@@ -62,63 +62,63 @@
     @Override
     public Result getNext(DataBag db) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(db) : 
rhs.getNext(db);
     }
 
     @Override
     public Result getNext(DataByteArray ba) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(ba) : 
rhs.getNext(ba);
     }
 
     @Override
     public Result getNext(Double d) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(d) : rhs.getNext(d);
     }
 
     @Override
     public Result getNext(Float f) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(f) : rhs.getNext(f);
     }
 
     @Override
     public Result getNext(Integer i) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(i) : rhs.getNext(i);
     }
 
     @Override
     public Result getNext(Long l) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(l) : rhs.getNext(l);
     }
 
     @Override
     public Result getNext(Map m) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(m) : rhs.getNext(m);
     }
 
     @Override
     public Result getNext(String s) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(s) : rhs.getNext(s);
     }
 
     @Override
     public Result getNext(Tuple t) throws ExecException {
         Result res = cond.getNext(dummyBool);
-        if (res.returnStatus != POStatus.STATUS_OK) return res;
+        if (res.result==null || res.returnStatus != POStatus.STATUS_OK) return 
res;
         return ((Boolean)res.result) == true ? lhs.getNext(t) : rhs.getNext(t);
     }
 

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=687835&r1=687834&r2=687835&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
 Thu Aug 21 12:26:30 2008
@@ -1038,6 +1038,7 @@
                (lhs=InfixExpr(over,specs,lp,input) <MATCHES> t1=<QUOTEDSTRING> 
                        {
                 LOConst rconst = new LOConst(lp, new OperatorKey(scope, 
getNextId()), unquote(t1.image));
+                rconst.setType(DataType.CHARARRAY);
                                cond = new LORegexp(lp, new OperatorKey(scope, 
getNextId()), lhs, rconst); 
                                lp.add(rconst); 
                                lp.add(cond); 

Modified: 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
URL: 
http://svn.apache.org/viewvc/incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java?rev=687835&r1=687834&r2=687835&view=diff
==============================================================================
--- 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
 (original)
+++ 
incubator/pig/branches/types/src/org/apache/pig/impl/logicalLayer/validators/TypeCheckingVisitor.java
 Thu Aug 21 12:26:30 2008
@@ -1431,13 +1431,20 @@
                 insertRightCastForBinCond(binCond, biggerType) ;
             }
             binCond.setType(biggerType) ;
-        }        
-        else if (lhsType != rhsType) {
-            String msg = "Two inputs of BinCond do not have compatible types" ;
-            msgCollector.collect(msg, MessageType.Error);
-            throw new VisitorException(msg) ;
+        } 
+        else if ((lhsType == DataType.BYTEARRAY)
+                && ((rhsType == DataType.CHARARRAY) || (DataType
+                        .isNumberType(rhsType)))) {
+            // Cast byte array to the type on rhs
+            insertLeftCastForBinCond(binCond, rhsType);
+            binCond.setType(DataType.mergeType(lhsType, rhsType));
+        } else if ((rhsType == DataType.BYTEARRAY)
+                && ((lhsType == DataType.CHARARRAY) || (DataType
+                        .isNumberType(lhsType)))) {
+            // Cast byte array to the type on lhs
+            insertRightCastForBinCond(binCond, lhsType);
+            binCond.setType(DataType.mergeType(lhsType, rhsType));
         }
-        
         // Matching schemas if we're working with tuples
         else if (lhsType == DataType.TUPLE) {            
             try {
@@ -1469,11 +1476,9 @@
             }
             binCond.setType(DataType.TUPLE) ;
         }
-        else if (lhsType == DataType.BYTEARRAY) {   
-            binCond.setType(DataType.BYTEARRAY) ;
-        }
-        else if (lhsType == DataType.CHARARRAY) {   
-            binCond.setType(DataType.CHARARRAY) ;
+        
+        else if (lhsType == rhsType) {
+            binCond.setType(lhsType);
         }
         else {
             String msg = "Unsupported input type for BinCond" ;


Reply via email to