You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2014/03/19 17:39:21 UTC

[3/6] git commit: Add uuid() function patch by Carl Yeksigian; reviewed by jbellis for CASSANDRA-6473

Add uuid() function
patch by Carl Yeksigian; reviewed by jbellis for CASSANDRA-6473


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

Branch: refs/heads/trunk
Commit: 32c15c2fb0d31a8f061a8fb812c2d4851d52ef2f
Parents: 91e4d22
Author: Carl Yeksigian <ca...@yeksigian.com>
Authored: Sat Mar 15 20:11:46 2014 -0400
Committer: Jonathan Ellis <jb...@apache.org>
Committed: Wed Mar 19 11:38:26 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 doc/cql3/CQL.textile                            |  4 ++
 .../cassandra/cql3/functions/Functions.java     |  1 +
 .../cassandra/cql3/functions/UuidFcts.java      | 42 ++++++++++++++++++++
 4 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/32c15c2f/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 2bb3605..41ec1d7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.7
+ * Add uuid() function (CASSANDRA-6473)
  * Omit tombstones from schema digests (CASSANDRA-6862)
  * Include correct consistencyLevel in LWT timeout (CASSANDRA-6884)
  * Lower chances for losing new SSTables during nodetool refresh and

http://git-wip-us.apache.org/repos/asf/cassandra/blob/32c15c2f/doc/cql3/CQL.textile
----------------------------------------------------------------------
diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile
index 566d13c..b323f20 100644
--- a/doc/cql3/CQL.textile
+++ b/doc/cql3/CQL.textile
@@ -1007,6 +1007,10 @@ CREATE TABLE users (
 
 then the @token@ function will take a single argument of type @text@ (in that case, the partition key is @userid@ (there is no clustering columns so the partition key is the same than the primary key)), and the return type will be @bigint@.
 
+h3(#uuidFun). Uuid
+
+The @uuid@ function takes no parameters and generates a random type 4 uuid suitable for use in INSERT or SET statements.
+
 h3(#timeuuidFun). Timeuuid functions
 
 h4. @now@

http://git-wip-us.apache.org/repos/asf/cassandra/blob/32c15c2f/src/java/org/apache/cassandra/cql3/functions/Functions.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/Functions.java b/src/java/org/apache/cassandra/cql3/functions/Functions.java
index 97a0e91..5f4201d 100644
--- a/src/java/org/apache/cassandra/cql3/functions/Functions.java
+++ b/src/java/org/apache/cassandra/cql3/functions/Functions.java
@@ -44,6 +44,7 @@ public abstract class Functions
         declared.put("maxtimeuuid", AbstractFunction.factory(TimeuuidFcts.maxTimeuuidFct));
         declared.put("dateof", AbstractFunction.factory(TimeuuidFcts.dateOfFct));
         declared.put("unixtimestampof", AbstractFunction.factory(TimeuuidFcts.unixTimestampOfFct));
+        declared.put("uuid", AbstractFunction.factory(UuidFcts.uuidFct));
 
         for (CQL3Type type : CQL3Type.Native.values())
         {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/32c15c2f/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java b/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java
new file mode 100644
index 0000000..718bcbc
--- /dev/null
+++ b/src/java/org/apache/cassandra/cql3/functions/UuidFcts.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.cql3.functions;
+
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.cassandra.db.marshal.UUIDType;
+import org.apache.cassandra.serializers.UUIDSerializer;
+
+public abstract class UuidFcts
+{
+    public static final Function uuidFct = new AbstractFunction("uuid", UUIDType.instance)
+    {
+        public ByteBuffer execute(List<ByteBuffer> parameters)
+        {
+            return UUIDSerializer.instance.serialize(UUID.randomUUID());
+        }
+
+        @Override
+        public boolean isPure()
+        {
+            return false;
+        }
+    };
+}