cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tylerho...@apache.org
Subject cassandra git commit: Handling adding UDT fields in SELECT JSON and toJson()
Date Thu, 18 Feb 2016 17:10:19 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.2 c00395155 -> c11620716


Handling adding UDT fields in SELECT JSON and toJson()

Patch by Tyler Hobbs; reviewed by Benjamin Lerer for CASSANDRA-11146


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

Branch: refs/heads/cassandra-2.2
Commit: c116207160400c94a3db7f08001f889017222b11
Parents: c003951
Author: Tyler Hobbs <tylerlhobbs@gmail.com>
Authored: Thu Feb 18 11:09:06 2016 -0600
Committer: Tyler Hobbs <tylerlhobbs@gmail.com>
Committed: Thu Feb 18 11:09:06 2016 -0600

----------------------------------------------------------------------
 CHANGES.txt                                      |  1 +
 .../apache/cassandra/db/marshal/UserType.java    |  2 +-
 .../cql3/validation/entities/JsonTest.java       | 19 +++++++++++++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c1162071/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7cbfea7..c85fc45 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.2.6
+ * Handle adding fields to a UDT in SELECT JSON and toJson() (CASSANDRA-11146)
  * Better error message for cleanup (CASSANDRA-10991)
  * cqlsh pg-style-strings broken if line ends with ';' (CASSANDRA-11123)
  * Use cloned TokenMetadata in size estimates to avoid race against membership check

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c1162071/src/java/org/apache/cassandra/db/marshal/UserType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/marshal/UserType.java b/src/java/org/apache/cassandra/db/marshal/UserType.java
index 40a35b5..6102d26 100644
--- a/src/java/org/apache/cassandra/db/marshal/UserType.java
+++ b/src/java/org/apache/cassandra/db/marshal/UserType.java
@@ -209,7 +209,7 @@ public class UserType extends TupleType
             sb.append(Json.quoteAsJsonString(name));
             sb.append("\": ");
 
-            ByteBuffer valueBuffer = buffers[i];
+            ByteBuffer valueBuffer = (i >= buffers.length) ? null : buffers[i];
             if (valueBuffer == null)
                 sb.append("null");
             else

http://git-wip-us.apache.org/repos/asf/cassandra/blob/c1162071/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
index 57df1e6..2c234cb 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@ -958,6 +958,25 @@ public class JsonTest extends CQLTester
         assertRows(execute("SELECT k, a.a, a.b, a.c, b FROM %s"), row(0, 0, set(1, 2, 3),
null, null));
     }
 
+    // done for CASSANDRA-11146
+    @Test
+    public void testAlterUDT() throws Throwable
+    {
+        String typeName = createType("CREATE TYPE %s (a int)");
+        createTable("CREATE TABLE %s (" +
+                "k int PRIMARY KEY, " +
+                "a frozen<" + typeName + ">)");
+
+        execute("INSERT INTO %s JSON ?", "{\"k\": 0, \"a\": {\"a\": 0}}");
+        assertRows(execute("SELECT JSON * FROM %s"), row("{\"k\": 0, \"a\": {\"a\": 0}}"));
+
+        schemaChange("ALTER TYPE " + KEYSPACE + "." + typeName + " ADD b boolean");
+        assertRows(execute("SELECT JSON * FROM %s"), row("{\"k\": 0, \"a\": {\"a\": 0, \"b\":
null}}"));
+
+        execute("INSERT INTO %s JSON ?", "{\"k\": 0, \"a\": {\"a\": 0, \"b\": true}}");
+        assertRows(execute("SELECT JSON * FROM %s"), row("{\"k\": 0, \"a\": {\"a\": 0, \"b\":
true}}"));
+    }
+
     // done for CASSANDRA-11048
     @Test
     public void testJsonTreadSafety() throws Throwable


Mime
View raw message