You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by da...@apache.org on 2011/04/29 02:42:31 UTC

svn commit: r1097664 - in /pig/branches/branch-0.9: CHANGES.txt src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java test/org/apache/pig/test/TestPOCast.java

Author: daijy
Date: Fri Apr 29 00:42:31 2011
New Revision: 1097664

URL: http://svn.apache.org/viewvc?rev=1097664&view=rev
Log:
PIG-1989: complex type casting should return null on casting failure

Modified:
    pig/branches/branch-0.9/CHANGES.txt
    pig/branches/branch-0.9/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
    pig/branches/branch-0.9/test/org/apache/pig/test/TestPOCast.java

Modified: pig/branches/branch-0.9/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/CHANGES.txt?rev=1097664&r1=1097663&r2=1097664&view=diff
==============================================================================
--- pig/branches/branch-0.9/CHANGES.txt (original)
+++ pig/branches/branch-0.9/CHANGES.txt Fri Apr 29 00:42:31 2011
@@ -174,6 +174,8 @@ PIG-1696: Performance: Use System.arrayc
 
 BUG FIXES
 
+PIG-1989: complex type casting should return null on casting failure (daijy)
+
 PIG-1826: Unexpected data type -1 found in stream error (daijy)
 
 PIG-2004: Incorrect input types passed on to eval function (thejas)

Modified: pig/branches/branch-0.9/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java?rev=1097664&r1=1097663&r2=1097664&view=diff
==============================================================================
--- pig/branches/branch-0.9/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java (original)
+++ pig/branches/branch-0.9/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java Fri Apr 29 00:42:31 2011
@@ -745,6 +745,7 @@ public class POCast extends ExpressionOp
                             "converted to type tuple, caught ParseException <" +
                             e.getMessage() + "> field discarded", 
                             PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, log);
+                    res.result = null;
                 }
             }
             return res;
@@ -866,6 +867,10 @@ public class POCast extends ExpressionOp
                 try {
                     Tuple t = (Tuple)obj;
                     ResourceSchema innerSchema = fs.getSchema();
+                    if (innerSchema==null)
+                        return t;
+                    if (innerSchema.getFields().length!=t.size())
+                        return null;
                     int i=0;
                     for (ResourceFieldSchema fieldSchema : innerSchema.getFields()) {
                         Object field = convertWithSchema(t.get(i), fieldSchema);
@@ -1123,6 +1128,7 @@ public class POCast extends ExpressionOp
                             "converted to type bag, caught ParseException <" +
                             e.getMessage() + "> field discarded", 
                             PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, log);
+                    res.result = null;
                 }
             }
             return res;
@@ -1222,6 +1228,7 @@ public class POCast extends ExpressionOp
                             "converted to type map, caught ParseException <" +
                             e.getMessage() + "> field discarded", 
                             PigWarning.FIELD_DISCARDED_TYPE_CONVERSION_FAILED, log);
+                    res.result = null;
                 }
             }
             return res;

Modified: pig/branches/branch-0.9/test/org/apache/pig/test/TestPOCast.java
URL: http://svn.apache.org/viewvc/pig/branches/branch-0.9/test/org/apache/pig/test/TestPOCast.java?rev=1097664&r1=1097663&r2=1097664&view=diff
==============================================================================
--- pig/branches/branch-0.9/test/org/apache/pig/test/TestPOCast.java (original)
+++ pig/branches/branch-0.9/test/org/apache/pig/test/TestPOCast.java Fri Apr 29 00:42:31 2011
@@ -1343,7 +1343,7 @@ public class TestPOCast extends TestCase
 	}
 	
 	@Test
-	public void testTupleToOther() throws IOException {
+	public void testTupleToOther() throws IOException, ParseException {
 		POCast op = new POCast(new OperatorKey("", r.nextLong()), -1);
 		op.setFuncSpec(new FuncSpec(PigStorage.class.getName()));
 		POProject prj = new POProject(new OperatorKey("", r.nextLong()), -1, 0);
@@ -1468,6 +1468,21 @@ public class TestPOCast extends TestCase
 			res = op.getNext(i);
 			assertEquals(POStatus.STATUS_ERR, res.returnStatus);
 		}
+		
+        {
+            Tuple t = tf.newTuple();
+            Tuple wrappedTuple = tf.newTuple();
+            wrappedTuple.append(GenRandomData.genRandString(r));
+            wrappedTuple.append(GenRandomData.genRandString(r));
+            t.append(wrappedTuple);
+            Schema s = Utils.getSchemaFromString("t:tuple(a:chararray)}");
+            op.setFieldSchema(new ResourceSchema.ResourceFieldSchema(s.getField(0)));
+            plan.attachInput(t);
+            Tuple tup = null;
+            Result res = op.getNext(tup);
+            
+            assertTrue(res.result==null);
+        }
 	}
 	
 	@Test