You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2013/11/21 09:54:07 UTC

[1/2] git commit: Support NaN and Infinity as float constants

Updated Branches:
  refs/heads/trunk c04d74f10 -> e239ea61e


Support NaN and Infinity as float constants

patch by slebresne; reviewed by iamaleksey for CASSANDRA-6003


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

Branch: refs/heads/trunk
Commit: 08f2e9797fc518f44c198e4f4ffd76fa43987565
Parents: d869164
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Thu Nov 21 09:53:00 2013 +0100
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Thu Nov 21 09:53:00 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                            | 1 +
 NEWS.txt                                               | 4 ++++
 doc/cql3/CQL.textile                                   | 8 ++++++--
 pylib/cqlshlib/formatting.py                           | 8 +++++++-
 src/java/org/apache/cassandra/cql3/Cql.g               | 3 +++
 src/java/org/apache/cassandra/cql3/QueryProcessor.java | 2 +-
 6 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 6ae8e8c..8d15f6c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -26,6 +26,7 @@
  * Fix bug missing results with IN clauses (CASSANDRA-6327)
  * Fix paging with reversed slices (CASSANDRA-6343)
  * Set minTimestamp correctly to be able to drop expired sstables (CASSANDRA-6337)
+ * Support NaN and Infinity as float literals (CASSANDRA-6003)
 Merged from 1.2:
  * Optimize FD phi calculation (CASSANDRA-6386)
  * Improve initial FD phi estimate when starting up (CASSANDRA-6385)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index fe8e49f..fdc29ad 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -23,6 +23,10 @@ New features
 
 Upgrading
 ---------
+    - NaN and Infinity are new valid floating point constants in CQL3 and are now reserved
+      keywords. In the unlikely case you were using one of them as an identifier (for a
+      column, a keyspace or a table), you will now have to double-quote them (see
+      http://cassandra.apache.org/doc/cql3/CQL.html#identifiers for "quoted identifiers").
     - The IEndpointStateChangeSubscriber has a new method, beforeChange, that
       any custom implemenations using the class will need to implement.
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/doc/cql3/CQL.textile
----------------------------------------------------------------------
diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile
index c90b585..c6920c8 100644
--- a/doc/cql3/CQL.textile
+++ b/doc/cql3/CQL.textile
@@ -1,6 +1,6 @@
 <link rel="StyleSheet" href="CQL.css" type="text/css" media="screen">
 
-h1. Cassandra Query Language (CQL) v3.1.1
+h1. Cassandra Query Language (CQL) v3.1.2
 
 
  <span id="tableOfContents">
@@ -50,7 +50,7 @@ h3(#constants). Constants
 CQL defines the following kind of _constants_: strings, integers, floats, booleans, uuids and blobs:
 * A string constant is an arbitrary sequence of characters characters enclosed by single-quote(@'@). One can include a single-quote in a string by repeating it, e.g. @'It''s raining today'@. Those are not to be confused with quoted identifiers that use double-quotes.
 * An integer constant is defined by @'-'?[0-9]+@.
-* A float constant is defined by @'-'?[0-9]+('.'[0-9]*)?([eE][+-]?[0-9+])?@.
+* A float constant is defined by @'-'?[0-9]+('.'[0-9]*)?([eE][+-]?[0-9+])?@. On top of that, @NaN@ and @Infinity@ are also float constants.
 * A boolean constant is either @true@ or @false@ up to case-insensitivity (i.e. @True@ is a valid boolean constant).
 * A "UUID":http://en.wikipedia.org/wiki/Universally_unique_identifier constant is defined by @hex{8}-hex{4}-hex{4}-hex{4}-hex{12}@ where @hex@ is an hexadecimal character, e.g. @[0-9a-fA-F]@ and @{4}@ is the number of such characters.
 * A blob constant is an hexadecimal number defined by @0[xX](hex)+@ where @hex@ is an hexadecimal character, e.g. @[0-9a-fA-F]@.
@@ -1088,6 +1088,10 @@ h2(#changes). Changes
 
 The following describes the addition/changes brought for each version of CQL.
 
+h3. 3.1.2
+
+* @NaN@ and @Infinity@ has been added as valid float contants. They are now reserved keywords. In the unlikely case you we using them as a column identifier (or keyspace/table one), you will noew need to double quote them (see "quote identifiers":#identifiers).
+
 h3. 3.1.1
 
 * @SELECT@ statement now allows listing the partition keys (using the @DISTINCT@ modifier). See "CASSANDRA-4536":https://issues.apache.org/jira/browse/CASSANDRA-4536.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/pylib/cqlshlib/formatting.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index b571033..6570099 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -17,6 +17,7 @@
 import re
 import time
 import binascii
+import math
 from collections import defaultdict
 from . import wcwidth
 from .displaying import colorme, FormattedValue, DEFAULT_VALUE_COLORS
@@ -137,7 +138,12 @@ def format_value_boolean(val, colormap, **_):
     return format_python_formatted_type(val, colormap, 'boolean')
 
 def format_floating_point_type(val, colormap, float_precision, **_):
-    bval = '%.*g' % (float_precision, val)
+    if math.isnan(val):
+        bval = 'NaN'
+    elif math.isinf(val):
+        bval = 'Infinity'
+    else:
+        bval = '%.*g' % (float_precision, val)
     return colorme(bval, colormap, 'float')
 
 formatter_for('float')(format_floating_point_type)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/Cql.g b/src/java/org/apache/cassandra/cql3/Cql.g
index ed950da..e70fc75 100644
--- a/src/java/org/apache/cassandra/cql3/Cql.g
+++ b/src/java/org/apache/cassandra/cql3/Cql.g
@@ -742,6 +742,7 @@ constant returns [Constants.Literal constant]
     | t=BOOLEAN        { $constant = Constants.Literal.bool($t.text); }
     | t=UUID           { $constant = Constants.Literal.uuid($t.text); }
     | t=HEXNUMBER      { $constant = Constants.Literal.hex($t.text); }
+    | { String sign=""; } ('-' {sign = "-"; } )? t=(K_NAN | K_INFINITY) { $constant = Constants.Literal.floatingPoint(sign + $t.text); }
     ;
 
 map_literal returns [Maps.Literal map]
@@ -1056,6 +1057,8 @@ K_EXISTS:      E X I S T S;
 
 K_MAP:         M A P;
 K_LIST:        L I S T;
+K_NAN:         N A N;
+K_INFINITY:    I N F I N I T Y;
 
 K_TRIGGER:     T R I G G E R;
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/08f2e979/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/QueryProcessor.java b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
index fed78ff..2a18230 100644
--- a/src/java/org/apache/cassandra/cql3/QueryProcessor.java
+++ b/src/java/org/apache/cassandra/cql3/QueryProcessor.java
@@ -44,7 +44,7 @@ import org.apache.cassandra.utils.SemanticVersion;
 
 public class QueryProcessor
 {
-    public static final SemanticVersion CQL_VERSION = new SemanticVersion("3.1.1");
+    public static final SemanticVersion CQL_VERSION = new SemanticVersion("3.1.2");
 
     private static final Logger logger = LoggerFactory.getLogger(QueryProcessor.class);
     private static final MemoryMeter meter = new MemoryMeter();


[2/2] git commit: Merge branch 'cassandra-2.0' into trunk

Posted by sl...@apache.org.
Merge branch 'cassandra-2.0' into trunk


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

Branch: refs/heads/trunk
Commit: e239ea61e45bb4bba2e82583687f0e8461f1a884
Parents: c04d74f 08f2e97
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Thu Nov 21 09:53:59 2013 +0100
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Thu Nov 21 09:53:59 2013 +0100

----------------------------------------------------------------------
 CHANGES.txt                                            | 1 +
 NEWS.txt                                               | 4 ++++
 doc/cql3/CQL.textile                                   | 8 ++++++--
 pylib/cqlshlib/formatting.py                           | 8 +++++++-
 src/java/org/apache/cassandra/cql3/Cql.g               | 3 +++
 src/java/org/apache/cassandra/cql3/QueryProcessor.java | 2 +-
 6 files changed, 22 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


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

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e239ea61/NEWS.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e239ea61/src/java/org/apache/cassandra/cql3/Cql.g
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e239ea61/src/java/org/apache/cassandra/cql3/QueryProcessor.java
----------------------------------------------------------------------