cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adelap...@apache.org
Subject [2/8] cassandra git commit: Fix ColumnMetadata.cellValueType() return type and change sstabledump tool to use type.toJsonString()
Date Tue, 08 Aug 2017 14:27:38 GMT
Fix ColumnMetadata.cellValueType() return type and change sstabledump tool to use type.toJsonString()

patch by Zhao Yang, reviewed by Andres de la Peña for CASSANDRA-13573


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

Branch: refs/heads/cassandra-3.11
Commit: 3960260472fcd4e0243f62cc813992f1365197c6
Parents: 9186679
Author: Zhao Yang <zhaoyangsingapore@gmail.com>
Authored: Wed Aug 2 11:58:38 2017 +0800
Committer: Andrés de la Peña <a.penya.garcia@gmail.com>
Committed: Tue Aug 8 14:31:23 2017 +0100

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/config/ColumnDefinition.java      | 19 ++++++++---
 .../org/apache/cassandra/db/rows/BTreeRow.java  |  2 +-
 .../apache/cassandra/db/rows/BufferCell.java    |  2 +-
 .../apache/cassandra/tools/JsonTransformer.java |  6 ++--
 .../org/apache/cassandra/cql3/ViewTest.java     | 33 ++++++++++++++++++++
 6 files changed, 55 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 905a436..1525289 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.15
+ * Fix ColumnDefinition.cellValueType() for non-frozen collection and change SSTabledump
to use type.toJSONString() (CASSANDRA-13573)
  * Skip materialized view addition if the base table doesn't exist (CASSANDRA-13737)
  * Drop table should remove corresponding entries in dropped_columns table (CASSANDRA-13730)
  * Log warn message until legacy auth tables have been migrated (CASSANDRA-13371)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/src/java/org/apache/cassandra/config/ColumnDefinition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/ColumnDefinition.java b/src/java/org/apache/cassandra/config/ColumnDefinition.java
index 34840e3..6a0f530 100644
--- a/src/java/org/apache/cassandra/config/ColumnDefinition.java
+++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java
@@ -391,13 +391,24 @@ public class ColumnDefinition extends ColumnSpecification implements
Comparable<
     /**
      * The type of the cell values for cell belonging to this column.
      *
-     * This is the same than the column type, except for collections where it's the 'valueComparator'
+     * This is the same than the column type, except for non-frozen collections where it's
the 'valueComparator'
      * of the collection.
+     * 
+     * This method should not be used to get value type of non-frozon UDT.
      */
     public AbstractType<?> cellValueType()
     {
-        return type instanceof CollectionType
-             ? ((CollectionType)type).valueComparator()
-             : type;
+        assert !(type instanceof UserType && type.isMultiCell());
+        return type instanceof CollectionType && type.isMultiCell()
+                ? ((CollectionType)type).valueComparator()
+                : type;
+    }
+
+
+    public boolean isCounterColumn()
+    {
+        if (type instanceof CollectionType) // for thrift
+            return ((CollectionType) type).valueComparator().isCounter();
+        return type.isCounter();
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/src/java/org/apache/cassandra/db/rows/BTreeRow.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/rows/BTreeRow.java b/src/java/org/apache/cassandra/db/rows/BTreeRow.java
index fda33d6..41dad0a 100644
--- a/src/java/org/apache/cassandra/db/rows/BTreeRow.java
+++ b/src/java/org/apache/cassandra/db/rows/BTreeRow.java
@@ -294,7 +294,7 @@ public class BTreeRow extends AbstractRow
 
     public Row markCounterLocalToBeCleared()
     {
-        return transformAndFilter(primaryKeyLivenessInfo, deletion, (cd) -> cd.column().cellValueType().isCounter()
+        return transformAndFilter(primaryKeyLivenessInfo, deletion, (cd) -> cd.column().isCounterColumn()
                                                                             ? cd.markCounterLocalToBeCleared()
                                                                             : cd);
     }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/src/java/org/apache/cassandra/db/rows/BufferCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/rows/BufferCell.java b/src/java/org/apache/cassandra/db/rows/BufferCell.java
index e4ad7e6..82ae02c 100644
--- a/src/java/org/apache/cassandra/db/rows/BufferCell.java
+++ b/src/java/org/apache/cassandra/db/rows/BufferCell.java
@@ -89,7 +89,7 @@ public class BufferCell extends AbstractCell
 
     public boolean isCounterCell()
     {
-        return !isTombstone() && column.cellValueType().isCounter();
+        return !isTombstone() && column.isCounterColumn();
     }
 
     public boolean isLive(int nowInSec)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/src/java/org/apache/cassandra/tools/JsonTransformer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/JsonTransformer.java b/src/java/org/apache/cassandra/tools/JsonTransformer.java
index 0a72583..5c32035 100644
--- a/src/java/org/apache/cassandra/tools/JsonTransformer.java
+++ b/src/java/org/apache/cassandra/tools/JsonTransformer.java
@@ -39,6 +39,7 @@ import org.apache.cassandra.db.RangeTombstone;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.CollectionType;
 import org.apache.cassandra.db.marshal.CompositeType;
+import org.apache.cassandra.db.marshal.UserType;
 import org.apache.cassandra.db.rows.Cell;
 import org.apache.cassandra.db.rows.ColumnData;
 import org.apache.cassandra.db.rows.ComplexColumnData;
@@ -49,6 +50,7 @@ import org.apache.cassandra.db.rows.Row;
 import org.apache.cassandra.db.rows.Unfiltered;
 import org.apache.cassandra.db.rows.UnfilteredRowIterator;
 import org.apache.cassandra.io.sstable.ISSTableScanner;
+import org.apache.cassandra.transport.Server;
 import org.apache.cassandra.utils.ByteBufferUtil;
 import org.codehaus.jackson.JsonFactory;
 import org.codehaus.jackson.JsonGenerator;
@@ -411,7 +413,7 @@ public final class JsonTransformer
             AbstractType<?> type = cell.column().type;
             json.writeString(cell.column().name.toCQLString());
 
-            if (cell.path() != null && cell.path().size() > 0)
+            if (type.isCollection() && type.isMultiCell()) // non-frozen collection
             {
                 CollectionType ct = (CollectionType) type;
                 json.writeFieldName("path");
@@ -437,7 +439,7 @@ public final class JsonTransformer
             else
             {
                 json.writeFieldName("value");
-                json.writeString(cell.column().cellValueType().getString(cell.value()));
+                json.writeRawValue(cell.column().cellValueType().toJSONString(cell.value(),
Server.CURRENT_VERSION));
             }
             if (liveInfo.isEmpty() || cell.timestamp() != liveInfo.timestamp())
             {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/39602604/test/unit/org/apache/cassandra/cql3/ViewTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ViewTest.java b/test/unit/org/apache/cassandra/cql3/ViewTest.java
index e595ebd..f8f8c9f 100644
--- a/test/unit/org/apache/cassandra/cql3/ViewTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ViewTest.java
@@ -1262,4 +1262,37 @@ public class ViewTest extends CQLTester
 
         assertRows(execute("SELECT count(*) FROM mv_test"), row(1024L));
     }
+
+    @Test
+    public void testFrozenCollectionsWithComplicatedInnerType() throws Throwable
+    {
+        createTable("CREATE TABLE %s (k int, intval int,  listval frozen<list<tuple<text,text>>>,
PRIMARY KEY (k))");
+
+        execute("USE " + keyspace());
+        executeNet(protocolVersion, "USE " + keyspace());
+
+        createView("mv",
+                   "CREATE MATERIALIZED VIEW %s AS SELECT * FROM %%s WHERE k IS NOT NULL
AND listval IS NOT NULL PRIMARY KEY (k, listval)");
+
+        updateView("INSERT INTO %s (k, intval, listval) VALUES (?, ?, fromJson(?))",
+                   0,
+                   0,
+                   "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]");
+
+        // verify input
+        assertRows(execute("SELECT k, toJson(listval) FROM %s WHERE k = ?", 0),
+                   row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
+        assertRows(execute("SELECT k, toJson(listval) from mv"),
+                   row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
+
+        // update listval with the same value and it will be compared in view generator
+        updateView("INSERT INTO %s (k, listval) VALUES (?, fromJson(?))",
+                   0,
+                   "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]");
+        // verify result
+        assertRows(execute("SELECT k, toJson(listval) FROM %s WHERE k = ?", 0),
+                   row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
+        assertRows(execute("SELECT k, toJson(listval) from mv"),
+                   row(0, "[[\"a\", \"1\"], [\"b\", \"2\"], [\"c\", \"3\"]]"));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message