cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ble...@apache.org
Subject [7/9] cassandra git commit: Merge branch 'cassandra-3.0' into cassandra-3.11
Date Thu, 02 Aug 2018 09:34:38 GMT
Merge branch 'cassandra-3.0' into cassandra-3.11


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

Branch: refs/heads/cassandra-3.11
Commit: 975e1d3eb9765e5f16a21fe47c40f6a149866045
Parents: 559d61a 3acb7d4
Author: Benjamin Lerer <b.lerer@gmail.com>
Authored: Thu Aug 2 11:32:03 2018 +0200
Committer: Benjamin Lerer <b.lerer@gmail.com>
Committed: Thu Aug 2 11:32:03 2018 +0200

----------------------------------------------------------------------
 CHANGES.txt                                              |  1 +
 src/java/org/apache/cassandra/db/marshal/DoubleType.java |  6 +++++-
 src/java/org/apache/cassandra/db/marshal/FloatType.java  |  6 +++++-
 .../cassandra/cql3/validation/entities/JsonTest.java     | 11 +++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/975e1d3e/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/975e1d3e/src/java/org/apache/cassandra/db/marshal/DoubleType.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/marshal/DoubleType.java
index d2309ee,d39059b..4b997dd
--- a/src/java/org/apache/cassandra/db/marshal/DoubleType.java
+++ b/src/java/org/apache/cassandra/db/marshal/DoubleType.java
@@@ -84,9 -83,13 +84,13 @@@ public class DoubleType extends Abstrac
      }
  
      @Override
 -    public String toJSONString(ByteBuffer buffer, int protocolVersion)
 +    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
      {
-         return getSerializer().deserialize(buffer).toString();
+         Double value = getSerializer().deserialize(buffer);
+         // JSON does not support NaN, Infinity and -Infinity values. Most of the parser
convert them into null.
+         if (value.isNaN() || value.isInfinite())
+             return "null";
+         return value.toString();
      }
  
      public CQL3Type asCQL3Type()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/975e1d3e/src/java/org/apache/cassandra/db/marshal/FloatType.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/db/marshal/FloatType.java
index 5445bbc,58f5702..ad71416
--- a/src/java/org/apache/cassandra/db/marshal/FloatType.java
+++ b/src/java/org/apache/cassandra/db/marshal/FloatType.java
@@@ -83,9 -82,13 +83,13 @@@ public class FloatType extends Abstract
      }
  
      @Override
 -    public String toJSONString(ByteBuffer buffer, int protocolVersion)
 +    public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion)
      {
-         return getSerializer().deserialize(buffer).toString();
+         Float value = getSerializer().deserialize(buffer);
+         // JSON does not support NaN, Infinity and -Infinity values. Most of the parser
convert them into null.
+         if (value.isNaN() || value.isInfinite())
+             return "null";
+         return value.toString();
      }
  
      public CQL3Type asCQL3Type()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/975e1d3e/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
index 16df6e1,ee96d83..ab0124e
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/JsonTest.java
@@@ -1389,23 -1286,16 +1389,34 @@@ public class JsonTest extends CQLTeste
          assertRows(execute("SELECT JSON a FROM %s WHERE a IN (20, 100) ORDER BY b DESC"),
                     row("{\"a\": 100}"),
                     row("{\"a\": 20}"));
 +
 +        // Check ordering with alias 
 +        assertRows(execute("SELECT JSON a, b as c FROM %s WHERE a IN (20, 100) ORDER BY
b"),
 +                   row("{\"a\": 20, \"c\": 30}"),
 +                   row("{\"a\": 100, \"c\": 200}"));
 +
 +        assertRows(execute("SELECT JSON a, b as c FROM %s WHERE a IN (20, 100) ORDER BY
b DESC"),
 +                   row("{\"a\": 100, \"c\": 200}"),
 +                   row("{\"a\": 20, \"c\": 30}"));
 +
 +        // Check ordering with CAST 
 +        assertRows(execute("SELECT JSON a, CAST(b AS FLOAT) FROM %s WHERE a IN (20, 100)
ORDER BY b"),
 +                   row("{\"a\": 20, \"cast(b as float)\": 30.0}"),
 +                   row("{\"a\": 100, \"cast(b as float)\": 200.0}"));
 +
 +        assertRows(execute("SELECT JSON a, CAST(b AS FLOAT) FROM %s WHERE a IN (20, 100)
ORDER BY b DESC"),
 +                   row("{\"a\": 100, \"cast(b as float)\": 200.0}"),
 +                   row("{\"a\": 20, \"cast(b as float)\": 30.0}"));
      }
+ 
+     @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)");
+         execute("INSERT INTO %s (pk, f1, f2, f3, d1, d2, d3) VALUES (?, ?, ?, ?, ?, ?, ?)",
+                 1, Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Double.NaN,
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY);
+ 
+         // 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}"));
+     }
  }


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


Mime
View raw message