Repository: cassandra
Updated Branches:
  refs/heads/CASSANDRA-11146-trunk [created] 32aa5b458


Handle added UDT fields in SELECT JSON


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

Branch: refs/heads/CASSANDRA-11146-trunk
Commit: 0270eccb3ba878bbc32b6f1921222b4603a6918d
Parents: af6bd1b
Author: Tyler Hobbs <[email protected]>
Authored: Thu Feb 11 15:56:40 2016 -0600
Committer: Tyler Hobbs <[email protected]>
Committed: Thu Feb 11 15:56:40 2016 -0600

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


http://git-wip-us.apache.org/repos/asf/cassandra/blob/0270eccb/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/0270eccb/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

Reply via email to