Support null in CQL3 functions

patch by slebresne; reviewed by iamaleksey for CASSANDRA-5910


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

Branch: refs/heads/trunk
Commit: 8bedb57207d54c4e88a762221d20d814fc351b1f
Parents: 9b545ca
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Wed Sep 11 08:31:05 2013 +0200
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Wed Sep 11 08:31:05 2013 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/cql3/functions/TimeuuidFcts.java  | 24 ++++++++++++++++----
 .../cassandra/cql3/functions/TokenFct.java      |  7 +++++-
 3 files changed, 27 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bedb572/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index cfcb364..e420a7b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -12,6 +12,7 @@
  * Pig: handle CQL collections (CASSANDRA-5867)
  * Pass the updated cf to the PRSI index() method (CASSANDRA-5999)
  * Allow empty CQL3 batches (as no-op) (CASSANDRA-5994)
+ * Support null in CQL3 functions (CASSANDRA-5910)
 
 
 1.2.9

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bedb572/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java 
b/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
index e325e8f..52eca54 100644
--- a/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
+++ b/src/java/org/apache/cassandra/cql3/functions/TimeuuidFcts.java
@@ -47,7 +47,11 @@ public abstract class TimeuuidFcts
     {
         public ByteBuffer execute(List<ByteBuffer> parameters)
         {
-            return 
ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.minTimeUUID(DateType.instance.compose(parameters.get(0)).getTime())));
+            ByteBuffer bb = parameters.get(0);
+            if (bb == null)
+                return null;
+
+            return 
ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.minTimeUUID(DateType.instance.compose(bb).getTime())));
         }
     };
 
@@ -55,7 +59,11 @@ public abstract class TimeuuidFcts
     {
         public ByteBuffer execute(List<ByteBuffer> parameters)
         {
-            return 
ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.maxTimeUUID(DateType.instance.compose(parameters.get(0)).getTime())));
+            ByteBuffer bb = parameters.get(0);
+            if (bb == null)
+                return null;
+
+            return 
ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.maxTimeUUID(DateType.instance.compose(bb).getTime())));
         }
     };
 
@@ -63,7 +71,11 @@ public abstract class TimeuuidFcts
     {
         public ByteBuffer execute(List<ByteBuffer> parameters)
         {
-            return DateType.instance.decompose(new 
Date(UUIDGen.unixTimestamp(UUIDGen.getUUID(parameters.get(0)))));
+            ByteBuffer bb = parameters.get(0);
+            if (bb == null)
+                return null;
+
+            return DateType.instance.decompose(new 
Date(UUIDGen.unixTimestamp(UUIDGen.getUUID(bb))));
         }
     };
 
@@ -71,7 +83,11 @@ public abstract class TimeuuidFcts
     {
         public ByteBuffer execute(List<ByteBuffer> parameters)
         {
-            return 
ByteBufferUtil.bytes(UUIDGen.unixTimestamp(UUIDGen.getUUID(parameters.get(0))));
+            ByteBuffer bb = parameters.get(0);
+            if (bb == null)
+                return null;
+
+            return 
ByteBufferUtil.bytes(UUIDGen.unixTimestamp(UUIDGen.getUUID(bb)));
         }
     };
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/8bedb572/src/java/org/apache/cassandra/cql3/functions/TokenFct.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/TokenFct.java 
b/src/java/org/apache/cassandra/cql3/functions/TokenFct.java
index 21695ca..28da87a 100644
--- a/src/java/org/apache/cassandra/cql3/functions/TokenFct.java
+++ b/src/java/org/apache/cassandra/cql3/functions/TokenFct.java
@@ -62,8 +62,13 @@ public class TokenFct extends AbstractFunction
     public ByteBuffer execute(List<ByteBuffer> parameters) throws 
InvalidRequestException
     {
         ColumnNameBuilder builder = cfDef.getKeyNameBuilder();
-        for (ByteBuffer bb : parameters)
+        for (int i = 0; i < parameters.size(); i++)
+        {
+            ByteBuffer bb = parameters.get(i);
+            if (bb == null)
+                return null;
             builder.add(bb);
+        }
         return 
partitioner.getTokenFactory().toByteArray(partitioner.getToken(builder.build()));
     }
 }

Reply via email to