You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ma...@apache.org on 2019/11/28 07:58:32 UTC

[cassandra] branch cassandra-3.11 updated: Fix SELECT JSON formatting for the "duration" type

This is an automated email from the ASF dual-hosted git repository.

marcuse pushed a commit to branch cassandra-3.11
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-3.11 by this push:
     new 5d930cc  Fix SELECT JSON formatting for the "duration" type
5d930cc is described below

commit 5d930cc9db6cdb29c2f7f1dec5a03c5b30ab66a7
Author: Pekka Enberg <pe...@iki.fi>
AuthorDate: Wed Apr 3 15:20:26 2019 +0300

    Fix SELECT JSON formatting for the "duration" type
    
    Patch by Pekka Enberg; reviewed by marcuse for CASSANDRA-15075
---
 CHANGES.txt                                        |  1 +
 .../apache/cassandra/db/marshal/DurationType.java  |  6 ------
 .../cql3/validation/entities/JsonTest.java         | 22 ++++++++++++++++++++--
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 8c52f34..918eb1b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.11.6
+ * Fix SELECT JSON formatting for the "duration" type (CASSANDRA-15075)
  * Fix LegacyLayout to have same behavior as 2.x when handling unknown column names (CASSANDRA-15081)
 Merged from 3.0:
  * Minimize clustering values in metadata collector (CASSANDRA-15400)
diff --git a/src/java/org/apache/cassandra/db/marshal/DurationType.java b/src/java/org/apache/cassandra/db/marshal/DurationType.java
index b6f2062..134a6f8 100644
--- a/src/java/org/apache/cassandra/db/marshal/DurationType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DurationType.java
@@ -71,12 +71,6 @@ public class DurationType extends AbstractType<Duration>
     }
 
     @Override
-    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
-    {
-        return getSerializer().deserialize(buffer).toString();
-    }
-
-    @Override
     public TypeSerializer<Duration> getSerializer()
     {
         return DurationSerializer.instance;
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 ab0124e..61c152a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@ -20,6 +20,7 @@ package org.apache.cassandra.cql3.validation.entities;
 import org.apache.cassandra.cql3.Json;
 import org.apache.cassandra.cql3.CQLTester;
 import org.apache.cassandra.cql3.Duration;
+import org.apache.cassandra.cql3.UntypedResultSet;
 import org.apache.cassandra.dht.ByteOrderedPartitioner;
 
 import org.apache.cassandra.serializers.SimpleDateSerializer;
@@ -37,6 +38,8 @@ import java.net.InetAddress;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.*;
+
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 public class JsonTest extends CQLTester
@@ -935,10 +938,10 @@ public class JsonTest extends CQLTester
 
         // ================ duration ================
         execute("INSERT INTO %s (k, durationval) VALUES (?, 12µs)", 0);
-        assertRows(execute("SELECT k, toJson(durationval) FROM %s WHERE k = ?", 0), row(0, "12us"));
+        assertRows(execute("SELECT k, toJson(durationval) FROM %s WHERE k = ?", 0), row(0, "\"12us\""));
 
         execute("INSERT INTO %s (k, durationval) VALUES (?, P1Y1M2DT10H5M)", 0);
-        assertRows(execute("SELECT k, toJson(durationval) FROM %s WHERE k = ?", 0), row(0, "1y1mo2d10h5m"));
+        assertRows(execute("SELECT k, toJson(durationval) FROM %s WHERE k = ?", 0), row(0, "\"1y1mo2d10h5m\""));
     }
 
     @Test
@@ -1419,4 +1422,19 @@ public class JsonTest extends CQLTester
         // JSON does not support NaN, Infinity and -Infinity values. Most of the parser convert them into null.
         assertRows(execute("SELECT JSON * FROM %s"), row("{\"pk\": 1, \"d1\": null, \"d2\": null, \"d3\": null, \"f1\": null, \"f2\": null, \"f3\": null}"));
     }
+
+    @Test
+    public void testDurationJsonRoundtrip() throws Throwable
+    {
+        createTable("CREATE TABLE %s (pk int PRIMARY KEY, d duration)");
+        execute("INSERT INTO %s (pk, d) VALUES (1, 6h40m)");
+        UntypedResultSet res = execute("SELECT JSON * FROM %s WHERE pk = 1");
+        UntypedResultSet.Row r = res.one();
+        String json = r.getString("[json]");
+        execute("DELETE FROM %s WHERE pk = 1");
+        execute("INSERT INTO %s JSON '"+json+"'");
+        res = execute("SELECT JSON * FROM %s WHERE pk = 1");
+        assertEquals(json, res.one().getString("[json]"));
+
+    }
 }


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