From de333791e81ae5364e2454af1e2fbf674bacb761 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 4 Jan 2012 10:33:57 -0600 Subject: [PATCH] Fix flawed addToMutationMap in word count example. Patch by Dave Brosius, reviewed by Brandon Williams for CASSANDRA-3669 --- .../hadoop_word_count/src/WordCountSetup.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/hadoop_word_count/src/WordCountSetup.java b/examples/hadoop_word_count/src/WordCountSetup.java index 4e9fddccd7..7857f023d4 100644 --- a/examples/hadoop_word_count/src/WordCountSetup.java +++ b/examples/hadoop_word_count/src/WordCountSetup.java @@ -106,16 +106,24 @@ public class WordCountSetup private static void addToMutationMap(Map>> mutationMap, ByteBuffer key, String cf, Column c) { - Map> cfMutation = new HashMap>(); - List mList = new ArrayList(); + Map> cfMutation = mutationMap.get(key); + if (cfMutation == null) { + cfMutation = new HashMap>(); + mutationMap.put(key, cfMutation); + } + + List mutationList = cfMutation.get(cf); + if (mutationList == null) { + mutationList = new ArrayList(); + cfMutation.put(cf, mutationList); + } + ColumnOrSuperColumn cc = new ColumnOrSuperColumn(); Mutation m = new Mutation(); cc.setColumn(c); m.setColumn_or_supercolumn(cc); - mList.add(m); - cfMutation.put(cf, mList); - mutationMap.put(key, cfMutation); + mutationList.add(m); } private static void setupKeyspace(Cassandra.Iface client) throws TException, InvalidRequestException, SchemaDisagreementException {