cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] git commit: Fix CQLSSTableWriter.addRow(Map<String, Object>)
Date Thu, 06 Mar 2014 09:15:26 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 5d67e852e -> 872eef3dc


Fix CQLSSTableWriter.addRow(Map<String, Object>)

patch by slebresne; reviewed by thobbs for CASSANDRA-6526


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ba95ca0d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ba95ca0d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ba95ca0d

Branch: refs/heads/cassandra-2.1
Commit: ba95ca0db52567b875e5be0d10f8523b706385c5
Parents: 773fade
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Thu Mar 6 10:07:51 2014 +0100
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu Mar 6 10:07:51 2014 +0100

----------------------------------------------------------------------
 CHANGES.txt                                               |  1 +
 .../org/apache/cassandra/io/sstable/CQLSSTableWriter.java | 10 ++++++++--
 .../apache/cassandra/io/sstable/CQLSSTableWriterTest.java |  9 ++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ba95ca0d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index d697e3f..6ef9025 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -34,6 +34,7 @@
  * Fix IllegalArgumentException when updating from 1.2 with SuperColumns
    (CASSANDRA-6733)
  * FBUtilities.singleton() should use the CF comparator (CASSANDRA-6778)
+ * Fix CQLSStableWriter.addRow(Map<String, Object>) (CASSANDRA-6526)
 Merged from 1.2:
  * Add CMSClassUnloadingEnabled JVM option (CASSANDRA-6541)
  * Catch memtable flush exceptions during shutdown (CASSANDRA-6735)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ba95ca0d/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java b/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
index 86348aa..a7ece70 100644
--- a/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
+++ b/src/java/org/apache/cassandra/io/sstable/CQLSSTableWriter.java
@@ -141,6 +141,11 @@ public class CQLSSTableWriter
      * keys are the names of the columns to add instead of taking a list of the
      * values in the order of the insert statement used during construction of
      * this write.
+     * <p>
+     * Please note that the column names in the map keys must be in lowercase unless
+     * the declared column name is a
+     * <a href="http://cassandra.apache.org/doc/cql3/CQL.html#identifiers">case-sensitive
quoted identifier</a>
+     * (in which case the map key must use the exact case of the column).
      *
      * @param values a map of colum name to column values representing the new
      * row to add. Note that if a column is not part of the map, it's value will
@@ -152,11 +157,12 @@ public class CQLSSTableWriter
     public CQLSSTableWriter addRow(Map<String, Object> values)
     throws InvalidRequestException, IOException
     {
-        int size = Math.min(values.size(), boundNames.size());
+        int size = boundNames.size();
         List<ByteBuffer> rawValues = new ArrayList<>(size);
         for (int i = 0; i < size; i++) {
             ColumnSpecification spec = boundNames.get(i);
-            rawValues.add(((AbstractType)spec.type).decompose(values.get(spec.name.toString())));
+            Object value = values.get(spec.name.toString());
+            rawValues.add(value == null ? null : ((AbstractType)spec.type).decompose(value));
         }
         return rawAddRow(rawValues);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ba95ca0d/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
index 0e38e16..bdc4b94 100644
--- a/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
+++ b/test/unit/org/apache/cassandra/io/sstable/CQLSSTableWriterTest.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.io.sstable;
 import java.io.File;
 import java.util.Iterator;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Files;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -72,6 +73,7 @@ public class CQLSSTableWriterTest
         writer.addRow(0, "test1", 24);
         writer.addRow(1, "test2", null);
         writer.addRow(2, "test3", 42);
+        writer.addRow(ImmutableMap.<String, Object>of("k", 3, "v2", 12));
         writer.close();
 
         SSTableLoader loader = new SSTableLoader(dataDir, new SSTableLoader.Client()
@@ -92,7 +94,7 @@ public class CQLSSTableWriterTest
         loader.stream().get();
 
         UntypedResultSet rs = QueryProcessor.processInternal("SELECT * FROM cql_keyspace.table1;");
-        assertEquals(3, rs.size());
+        assertEquals(4, rs.size());
 
         Iterator<UntypedResultSet.Row> iter = rs.iterator();
         UntypedResultSet.Row row;
@@ -111,5 +113,10 @@ public class CQLSSTableWriterTest
         assertEquals(2, row.getInt("k"));
         assertEquals("test3", row.getString("v1"));
         assertEquals(42, row.getInt("v2"));
+
+        row = iter.next();
+        assertEquals(3, row.getInt("k"));
+        assertEquals(null, row.getBytes("v1")); // Using getBytes because we know it won't
NPE
+        assertEquals(12, row.getInt("v2"));
     }
 }


Mime
View raw message