You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by bl...@apache.org on 2019/12/09 08:50:42 UTC
[cassandra] branch cassandra-2.2 updated: Fix SELECT JSON output
for empty blobs
This is an automated email from the ASF dual-hosted git repository.
blerer pushed a commit to branch cassandra-2.2
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-2.2 by this push:
new c3dc6eb Fix SELECT JSON output for empty blobs
c3dc6eb is described below
commit c3dc6eb57ef94ca1ff19ab766fc3cc5179242cac
Author: Ekaterina Dimitrova <ek...@datastax.com>
AuthorDate: Fri Dec 6 13:58:53 2019 +0100
Fix SELECT JSON output for empty blobs
patch by Ekaterina Dimitrova; reviewed by Benjamin Lerer for
CASSANDRA-15435
---
CHANGES.txt | 1 +
.../apache/cassandra/cql3/selection/Selection.java | 2 +-
.../cql3/validation/entities/JsonTest.java | 30 ++++++++++++++++++++++
3 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index d384643..e2504c4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.2.16
+ * Fix SELECT JSON output for empty blobs (CASSANDRA-15435)
* In-JVM DTest: Set correct internode message version for upgrade test (CASSANDRA-15371)
diff --git a/src/java/org/apache/cassandra/cql3/selection/Selection.java b/src/java/org/apache/cassandra/cql3/selection/Selection.java
index 5385fc6..72aec27 100644
--- a/src/java/org/apache/cassandra/cql3/selection/Selection.java
+++ b/src/java/org/apache/cassandra/cql3/selection/Selection.java
@@ -428,7 +428,7 @@ public abstract class Selection
sb.append('"');
sb.append(Json.quoteAsJsonString(columnName));
sb.append("\": ");
- if (buffer == null || !buffer.hasRemaining())
+ if (buffer == null)
sb.append("null");
else
sb.append(spec.type.toJSONString(buffer, protocolVersion));
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 b804c0e..9c6c96a 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@ -1287,6 +1287,36 @@ public class JsonTest extends CQLTester
}
@Test
+ public void testInsertAndSelectJsonSyntaxWithEmptyAndNullValues() throws Throwable
+ {
+ createTable("create table %s(id INT, name TEXT, name_asc ASCII, bytes BLOB, PRIMARY KEY(id));");
+
+ // Test with empty values
+
+ execute("INSERT INTO %s JSON ?", "{\"id\": 0, \"bytes\": \"0x\", \"name\": \"\", \"name_asc\": \"\"}");
+ assertRows(execute("SELECT * FROM %s WHERE id=0"), row(0, ByteBufferUtil.EMPTY_BYTE_BUFFER, "", ""));
+ assertRows(execute("SELECT JSON * FROM %s WHERE id = 0"),
+ row("{\"id\": 0, \"bytes\": \"0x\", \"name\": \"\", \"name_asc\": \"\"}"));
+
+ execute("INSERT INTO %s(id, name, name_asc, bytes) VALUES (1, ?, ?, ?);", "", "", ByteBufferUtil.EMPTY_BYTE_BUFFER);
+ assertRows(execute("SELECT * FROM %s WHERE id=1"), row(1, ByteBufferUtil.EMPTY_BYTE_BUFFER, "", ""));
+ assertRows(execute("SELECT JSON * FROM %s WHERE id = 1"),
+ row("{\"id\": 1, \"bytes\": \"0x\", \"name\": \"\", \"name_asc\": \"\"}"));
+
+ // Test with null values
+
+ execute("INSERT INTO %s JSON ?", "{\"id\": 2, \"bytes\": null, \"name\": null, \"name_asc\": null}");
+ assertRows(execute("SELECT * FROM %s WHERE id=2"), row(2, null, null, null));
+ assertRows(execute("SELECT JSON * FROM %s WHERE id = 2"),
+ row("{\"id\": 2, \"bytes\": null, \"name\": null, \"name_asc\": null}"));
+
+ execute("INSERT INTO %s(id, name, name_asc, bytes) VALUES (3, ?, ?, ?);", null, null, null);
+ assertRows(execute("SELECT * FROM %s WHERE id=3"), row(3, null, null, null));
+ assertRows(execute("SELECT JSON * FROM %s WHERE id = 3"),
+ row("{\"id\": 3, \"bytes\": null, \"name\": null, \"name_asc\": null}"));
+ }
+
+ @Test
public void testJsonWithNaNAndInfinity() throws Throwable
{
createTable("CREATE TABLE %s (pk int PRIMARY KEY, f1 float, f2 float, f3 float, d1 double, d2 double, d3 double)");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org