diff --git a/CHANGES.txt b/CHANGES.txt index 619e41591e..24e9163d3e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,8 @@ 1.2.6 * Write row markers when serializing schema (CASSANDRA-5572) * Check only SSTables for the requested range when streaming (CASSANDRA-5569) +Merged from 1.1 + * Fix NPE in Pig's widerow mode (CASSANDRA-5488) 1.2.5 diff --git a/examples/pig/test/test_storage.pig b/examples/pig/test/test_storage.pig index 026cb025a9..93dd91f2db 100644 --- a/examples/pig/test/test_storage.pig +++ b/examples/pig/test/test_storage.pig @@ -1,4 +1,4 @@ -rows = LOAD 'cassandra://PigTest/SomeApp' USING CassandraStorage(); +rows = LOAD 'cassandra://PigTest/SomeApp?widerows=true' USING CassandraStorage(); -- full copy STORE rows INTO 'cassandra://PigTest/CopyOfSomeApp' USING CassandraStorage(); -- single tuple diff --git a/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java b/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java index 110f61d9c5..76feb5a3f0 100644 --- a/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java +++ b/src/java/org/apache/cassandra/hadoop/pig/CassandraStorage.java @@ -147,7 +147,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo if (tuple.size() == 0) // lastRow is a new one { key = (ByteBuffer)reader.getCurrentKey(); - addKeyToTuple(tuple, key, cfDef, parseType(cfDef.getKey_validation_class())); + tuple = addKeyToTuple(tuple, key, cfDef, parseType(cfDef.getKey_validation_class())); } for (Map.Entry entry : lastRow.entrySet()) { @@ -183,7 +183,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo key = (ByteBuffer)reader.getCurrentKey(); if (lastKey != null && !(key.equals(lastKey))) // last key only had one value { - addKeyToTuple(tuple, lastKey, cfDef, parseType(cfDef.getKey_validation_class())); + tuple = addKeyToTuple(tuple, lastKey, cfDef, parseType(cfDef.getKey_validation_class())); for (Map.Entry entry : lastRow.entrySet()) { bag.add(columnToTuple(entry.getValue(), cfDef, parseType(cfDef.getComparator_type()))); @@ -193,7 +193,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo lastRow = (SortedMap)reader.getCurrentValue(); return tuple; } - addKeyToTuple(tuple, lastKey, cfDef, parseType(cfDef.getKey_validation_class())); + tuple = addKeyToTuple(tuple, lastKey, cfDef, parseType(cfDef.getKey_validation_class())); } SortedMap row = (SortedMap)reader.getCurrentValue(); if (lastRow != null) // prepend what was read last time @@ -236,7 +236,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo // output tuple, will hold the key, each indexed column in a tuple, then a bag of the rest // NOTE: we're setting the tuple size here only for the key so we can use setTupleValue on it - Tuple tuple = keyToTuple(key, cfDef, parseType(cfDef.getKey_validation_class())); + Tuple tuple = addKeyToTuple(null, key, cfDef, parseType(cfDef.getKey_validation_class())); DefaultDataBag bag = new DefaultDataBag(); // we must add all the indexed columns first to match the schema @@ -295,15 +295,12 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo return t; } - private Tuple keyToTuple(ByteBuffer key, CfDef cfDef, AbstractType comparator) throws IOException - { - Tuple tuple = TupleFactory.getInstance().newTuple(1); - addKeyToTuple(tuple, key, cfDef, comparator); - return tuple; - } - - private void addKeyToTuple(Tuple tuple, ByteBuffer key, CfDef cfDef, AbstractType comparator) throws IOException + private Tuple addKeyToTuple(Tuple tuple, ByteBuffer key, CfDef cfDef, AbstractType comparator) throws IOException { + if( tuple == null ) + { + tuple = TupleFactory.getInstance().newTuple(1); + } if( comparator instanceof AbstractCompositeType ) { setTupleValue(tuple, 0, composeComposite((AbstractCompositeType)comparator,key)); @@ -312,7 +309,7 @@ public class CassandraStorage extends LoadFunc implements StoreFuncInterface, Lo { setTupleValue(tuple, 0, getDefaultMarshallers(cfDef).get(MarshallerType.KEY_VALIDATOR).compose(key)); } - + return tuple; } private Tuple columnToTuple(IColumn col, CfDef cfDef, AbstractType comparator) throws IOException