Author: olga Date: Thu Dec 11 18:18:08 2008 New Revision: 725889 URL: http://svn.apache.org/viewvc?rev=725889&view=rev Log: PIG-559: ARRITY and SIZE produce wrong values for tuples
Modified: hadoop/pig/branches/types/src/org/apache/pig/builtin/ARITY.java hadoop/pig/branches/types/src/org/apache/pig/builtin/TupleSize.java hadoop/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java Modified: hadoop/pig/branches/types/src/org/apache/pig/builtin/ARITY.java URL: http://svn.apache.org/viewvc/hadoop/pig/branches/types/src/org/apache/pig/builtin/ARITY.java?rev=725889&r1=725888&r2=725889&view=diff ============================================================================== --- hadoop/pig/branches/types/src/org/apache/pig/builtin/ARITY.java (original) +++ hadoop/pig/branches/types/src/org/apache/pig/builtin/ARITY.java Thu Dec 11 18:18:08 2008 @@ -23,12 +23,21 @@ import org.apache.pig.data.DataType; import org.apache.pig.data.Tuple; import org.apache.pig.impl.logicalLayer.schema.Schema; +import org.apache.pig.impl.util.WrappedIOException; public class ARITY extends EvalFunc<Integer> { @Override public Integer exec(Tuple input) throws IOException { - return new Integer(input.size()); + if (input.size() == 0) + return null; + try{ + Tuple t = (Tuple)input.get(0); + if (t == null) return null; + return new Integer(t.size()); + }catch(Exception e){ + throw WrappedIOException.wrap(e); + } } @Override Modified: hadoop/pig/branches/types/src/org/apache/pig/builtin/TupleSize.java URL: http://svn.apache.org/viewvc/hadoop/pig/branches/types/src/org/apache/pig/builtin/TupleSize.java?rev=725889&r1=725888&r2=725889&view=diff ============================================================================== --- hadoop/pig/branches/types/src/org/apache/pig/builtin/TupleSize.java (original) +++ hadoop/pig/branches/types/src/org/apache/pig/builtin/TupleSize.java Thu Dec 11 18:18:08 2008 @@ -23,7 +23,7 @@ import org.apache.pig.data.DataType; import org.apache.pig.data.Tuple; import org.apache.pig.impl.logicalLayer.schema.Schema; - +import org.apache.pig.impl.util.WrappedIOException; /** * Generates the size of the first field of a tuple. @@ -31,8 +31,16 @@ public class TupleSize extends EvalFunc<Long> { @Override - public Long exec(Tuple input) { - return input == null ? null : new Long(input.size()); + public Long exec(Tuple input) throws IOException { + if (input.size() == 0) + return null; + try{ + Tuple t = (Tuple)input.get(0); + if (t == null) return null; + return new Long(t.size()); + }catch(Exception e){ + throw WrappedIOException.wrap(e); + } } @Override Modified: hadoop/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java URL: http://svn.apache.org/viewvc/hadoop/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java?rev=725889&r1=725888&r2=725889&view=diff ============================================================================== --- hadoop/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java (original) +++ hadoop/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java Thu Dec 11 18:18:08 2008 @@ -714,11 +714,18 @@ // Tuple size + Tuple t5 = TupleFactory.getInstance().newTuple(); + t5.append(t1); expected = new Long(3); size = new TupleSize(); msg = "[Testing TupleSize on input type: Tuple]"; - assertTrue(msg, expected.equals(size.exec(t1))); + assertTrue(msg, expected.equals(size.exec(t5))); + // Test for ARITY function. + // It is depricated but we still need to make sure it works + ARITY arrity = new ARITY(); + msg = "[Testing ARRITY on input type: Tuple]"; + //assertTrue(msg, expected.equals(arrity.exec(t5))); } // Builtin APPLY Functions