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:43:18 UTC
svn commit: r1097665 - in /pig/trunk: 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:43:17 2011
New Revision: 1097665
URL: http://svn.apache.org/viewvc?rev=1097665&view=rev
Log:
PIG-1989: complex type casting should return null on casting failure
Modified:
pig/trunk/CHANGES.txt
pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
pig/trunk/test/org/apache/pig/test/TestPOCast.java
Modified: pig/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/pig/trunk/CHANGES.txt?rev=1097665&r1=1097664&r2=1097665&view=diff
==============================================================================
--- pig/trunk/CHANGES.txt (original)
+++ pig/trunk/CHANGES.txt Fri Apr 29 00:43:17 2011
@@ -188,6 +188,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/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java?rev=1097665&r1=1097664&r2=1097665&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java (original)
+++ pig/trunk/src/org/apache/pig/backend/hadoop/executionengine/physicalLayer/expressionOperators/POCast.java Fri Apr 29 00:43:17 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/trunk/test/org/apache/pig/test/TestPOCast.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPOCast.java?rev=1097665&r1=1097664&r2=1097665&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPOCast.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPOCast.java Fri Apr 29 00:43:17 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