Author: eevans
Date: Mon Feb  7 19:06:11 2011
New Revision: 1068054

URL: http://svn.apache.org/viewvc?rev=1068054&view=rev
Log:
uuid term definitions

Patch by eevans for CASSANDRA-2027

Modified:
    cassandra/trunk/doc/cql/CQL.html
    cassandra/trunk/doc/cql/CQL.textile
    cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
    cassandra/trunk/src/java/org/apache/cassandra/cql/Term.java
    cassandra/trunk/test/system/test_cql.py

Modified: cassandra/trunk/doc/cql/CQL.html
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/doc/cql/CQL.html?rev=1068054&r1=1068053&r2=1068054&view=diff
==============================================================================
--- cassandra/trunk/doc/cql/CQL.html (original)
+++ cassandra/trunk/doc/cql/CQL.html Mon Feb  7 19:06:11 2011
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD 
XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";><html 
xmlns="http://www.w3.org/1999/xhtml";><head><meta http-equiv="Content-Type" 
content="text/html; charset=utf-8"/></head><body><h1 
id="CassandraQueryLanguageCQLv0.99.1">Cassandra Query Language (CQL) 
v0.99.1</h1><h2 id="TableofContents">Table of Contents</h2><ol 
style="list-style: none;"><li><a 
href="#CassandraQueryLanguageCQLv0.99.1">Cassandra Query Language (CQL) 
v0.99.1</a><ol style="list-style: none;"><li><a href="#TableofContents">Table 
of Contents</a></li><li><a href="#USE">USE</a></li><li><a 
href="#SELECT">SELECT</a><ol style="list-style: none;"><li><a 
href="#SpecifyingColumns">Specifying Columns</a></li><li><a 
href="#ColumnFamily">Column Family</a></li><li><a 
href="#ConsistencyLevel">Consistency Level</a></li><li><a 
href="#Filteringrows">Filtering rows</a></li><li><a 
href="#Limits">Limits</a></li></ol></li>
 <li><a href="#UPDATE">UPDATE</a><ol style="list-style: none;"><li><a 
href="#ColumnFamily2">Column Family</a></li><li><a 
href="#ConsistencyLevel2">Consistency Level</a></li><li><a 
href="#SpecifyingColumnsandRow">Specifying Columns and 
Row</a></li></ol></li><li><a href="#DELETE">DELETE</a><ol style="list-style: 
none;"><li><a href="#SpecifyingColumns2">Specifying Columns</a></li><li><a 
href="#ColumnFamily3">Column Family</a></li><li><a 
href="#ConsistencyLevel3">Consistency Level</a></li><li><a 
href="#deleterows">Specifying Rows</a></li></ol></li><li><a 
href="#TRUNCATE">TRUNCATE</a></li><li><a href="#CREATEKEYSPACE">CREATE 
KEYSPACE</a></li><li><a href="#CommonIdioms">Common Idioms</a><ol 
style="list-style: none;"><li><a href="#consistency">Specifying 
Consistency</a></li><li><a href="#terms">Term specification</a><ol 
style="list-style: none;"><li><a href="#StringLiterals">String 
Literals</a></li><li><a href="#Integerslongs">Integers / 
longs</a></li></ol></li></ol></li></ol></li><
 /ol><h2 id="USE">USE</h2><p><i>Synopsis:</i></p><pre><code>USE 
&lt;KEYSPACE&gt;;
+<?xml version='1.0' encoding='utf-8' ?><!DOCTYPE html PUBLIC "-//W3C//DTD 
XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";><html 
xmlns="http://www.w3.org/1999/xhtml";><head><meta http-equiv="Content-Type" 
content="text/html; charset=utf-8"/></head><body><h1 
id="CassandraQueryLanguageCQLv0.99.1">Cassandra Query Language (CQL) 
v0.99.1</h1><h2 id="TableofContents">Table of Contents</h2><ol 
style="list-style: none;"><li><a 
href="#CassandraQueryLanguageCQLv0.99.1">Cassandra Query Language (CQL) 
v0.99.1</a><ol style="list-style: none;"><li><a href="#TableofContents">Table 
of Contents</a></li><li><a href="#USE">USE</a></li><li><a 
href="#SELECT">SELECT</a><ol style="list-style: none;"><li><a 
href="#SpecifyingColumns">Specifying Columns</a></li><li><a 
href="#ColumnFamily">Column Family</a></li><li><a 
href="#ConsistencyLevel">Consistency Level</a></li><li><a 
href="#Filteringrows">Filtering rows</a></li><li><a 
href="#Limits">Limits</a></li></ol></li>
 <li><a href="#UPDATE">UPDATE</a><ol style="list-style: none;"><li><a 
href="#ColumnFamily2">Column Family</a></li><li><a 
href="#ConsistencyLevel2">Consistency Level</a></li><li><a 
href="#SpecifyingColumnsandRow">Specifying Columns and 
Row</a></li></ol></li><li><a href="#DELETE">DELETE</a><ol style="list-style: 
none;"><li><a href="#SpecifyingColumns2">Specifying Columns</a></li><li><a 
href="#ColumnFamily3">Column Family</a></li><li><a 
href="#ConsistencyLevel3">Consistency Level</a></li><li><a 
href="#deleterows">Specifying Rows</a></li></ol></li><li><a 
href="#TRUNCATE">TRUNCATE</a></li><li><a href="#CREATEKEYSPACE">CREATE 
KEYSPACE</a></li><li><a href="#CommonIdioms">Common Idioms</a><ol 
style="list-style: none;"><li><a href="#consistency">Specifying 
Consistency</a></li><li><a href="#terms">Term specification</a><ol 
style="list-style: none;"><li><a href="#StringLiterals">String 
Literals</a></li><li><a href="#Integerslongs">Integers / longs</a></li><li><a 
href="#UUIDs">UUIDs</a><
 /li></ol></li></ol></li></ol></li></ol><h2 
id="USE">USE</h2><p><i>Synopsis:</i></p><pre><code>USE &lt;KEYSPACE&gt;;
 </code></pre><p>A <code>USE</code> statement consists of the <code>USE</code> 
keyword, followed by a valid keyspace name.  Its purpose is to assign the 
per-connection, current working keyspace.  All subsequent keyspace-specific 
actions will be performed in the context of the supplied value.</p><h2 
id="SELECT">SELECT</h2><p><i>Synopsis:</i></p><pre><code>SELECT [FIRST N] 
[REVERSED] &lt;SELECT EXPR&gt; FROM &lt;COLUMN FAMILY&gt; [USING 
&lt;CONSISTENCY&gt;]
         [WHERE &lt;CLAUSE&gt;] [LIMIT N];
 </code></pre><p>A <code>SELECT</code> is used to read one or more records from 
a Cassandra column family. It returns a result-set of rows, where each row 
consists of a key and a collection of columns corresponding to the 
query.</p><h3 id="SpecifyingColumns">Specifying Columns</h3><pre><code>SELECT 
[FIRST N] [REVERSED] name1, name2, name3 FROM ...
@@ -29,4 +29,4 @@ UPDATE ... WHERE KEY IN (keyname1, keyna
 </code></pre><p>Accepts a single argument for the column family name, and 
permanently removes all data from said column family.</p><h2 
id="CREATEKEYSPACE">CREATE 
KEYSPACE</h2><p><em>Synopsis:</em></p><pre><code>CREATE KEYSPACE &lt;NAME&gt; 
WITH replication_factor = &lt;NUM&gt; AND strategy_class = "&lt;STRATEGY&gt;"
     [AND strategy_options.&lt;OPTION&gt; = &lt;VALUE&gt; [AND 
strategy_options.&lt;OPTION&gt; = &lt;VALUE&gt;]];
 </code></pre><p>The <code>CREATE KEYSPACE</code> statement creates a new 
top-level namespace (aka &#8220;keyspace&#8221;). Valid names are any string 
constructed of alphanumeric characters and underscores, but must begin with a 
letter.  Properties such as replication strategy and count are specified during 
creation using the following accepted keyword 
arguments:</p><table><tr><th>keyword</th><th>required</th><th>description</th></tr><tr><td>replication_factor</td><td>yes</td><td>Numeric
 argument that specifies the number of replicas for this 
keyspace.</td></tr><tr><td>strategy_class</td><td>yes</td><td>Class name to use 
for managing replica placement.  Any of the shipped strategies can be used by 
specifying the class name relative to org.apache.cassandra.locator, others will 
need to be fully-qualified and located on the 
classpath.</td></tr><tr><td>strategy_options</td><td>no</td><td>Some strategies 
require additional arguments which can be supplied by appending the option na
 me to the <code>strategy_options</code> keyword, separated by a colon 
(<code>:</code>).  For example, a strategy option of &#8220;DC1&#8221; with a 
value of &#8220;1&#8221; would be specified as <code>strategy_options:DC1 = 
"1"</code>.</td></tr></table><h2 id="CommonIdioms">Common Idioms</h2><h3 
id="consistency">Specifying Consistency</h3><pre><code>... USING 
&lt;CONSISTENCY&gt; ...
-</code></pre><p>Consistency level specifications are made up the keyword 
<code>USING</code>, followed by a consistency level identifier. Valid 
consistency levels are as 
follows:</p><ul><li><code>CONSISTENCY.ZERO</code></li><li><code>CONSISTENCY.ONE</code>
 
(default)</li><li><code>CONSISTENCY.QUORUM</code></li><li><code>CONSISTENCY.ALL</code></li><li><code>CONSISTENCY.DCQUORUM</code></li><li><code>CONSISTENCY.DCQUORUMSYNC</code></li></ul><h3
 id="terms">Term specification</h3><p>Where possible, the type of terms are 
inferred; the following term types are supported:</p><h4 
id="StringLiterals">String Literals</h4><p>String literals are any value 
enclosed in double-quotes, (`"`).  String literals are treated as raw bytes; no 
interpolation is performed.</p><h4 id="Integerslongs">Integers / 
longs</h4><p>Integers are any term consisting soley of unquoted numericals, 
longs are any otherwise valid integer term followed by an upper case 
&#8220;L&#8221;, (e.g. 100L).  It is an error to s
 pecify an integer term that will not fit in 4 bytes unsigned, or a long that 
will not fit in 8 bytes unsigned.</p></body></html>
\ No newline at end of file
+</code></pre><p>Consistency level specifications are made up the keyword 
<code>USING</code>, followed by a consistency level identifier. Valid 
consistency levels are as 
follows:</p><ul><li><code>CONSISTENCY.ZERO</code></li><li><code>CONSISTENCY.ONE</code>
 
(default)</li><li><code>CONSISTENCY.QUORUM</code></li><li><code>CONSISTENCY.ALL</code></li><li><code>CONSISTENCY.DCQUORUM</code></li><li><code>CONSISTENCY.DCQUORUMSYNC</code></li></ul><h3
 id="terms">Term specification</h3><p>Where possible, the type of terms are 
inferred; the following term types are supported:</p><h4 
id="StringLiterals">String Literals</h4><p>String literals are any value 
enclosed in double-quotes, (`"`).  String literals are treated as raw bytes; no 
interpolation is performed.</p><h4 id="Integerslongs">Integers / 
longs</h4><p>Integers are any term consisting soley of unquoted numericals, 
longs are any otherwise valid integer term followed by an upper case 
&#8220;L&#8221;, (e.g. 100L).  It is an error to s
 pecify an integer term that will not fit in 4 bytes unsigned, or a long that 
will not fit in 8 bytes unsigned.</p><h4 id="UUIDs">UUIDs</h4><p>There are two 
types of UUIDs supported by the CQL specification, time-based (version 1) and 
randomly generated (version 4). These are specified in statements using the 
<code>timeuuid(&lt;UUID STRING&gt;)</code> and <code>uuid(&lt;UUID 
STRING&gt;)</code> notations respectively.</p><p>In addition to the hex-based 
string representation, <code>timeuuid()</code> terms also accept arguments to 
specify the data-time component. The full list of <code>timeuuid()</code> 
arguments 
are:</p><table><tr><th>argument</th><th>example</th><th>behavior</th></tr><tr><td>none</td><td>timeuuid()</td><td>Results
 in the creation of a new UUID based on system time of the node parsing the 
query.</td></tr><tr><td>now</td><td>timeuuid(&#8220;now&#8221;)</td><td>Results 
in the creation of a new UUID based on system time of the node parsing the 
query.</td></tr><tr>
 <td>milliseconds since epoch</td><td>timeuuid(1296755320376)</td><td>Creates a 
UUID with a time component that is based on the supplied 
time-stamp.</td></tr><tr><td><a 
href="http://en.wikipedia.org/wiki/8601";>iso8601 
timestamp</a></td><td>timeuuid(&#8220;2011-02-01T14:00-0600&#8221;)</td><td>Creates
 a UUID with a time component that is based on the supplied 
time-stamp.</td></tr><tr><td><a 
href="http://tools.ietf.org/html/rfc4122";>string representation 
(hex)</a></td><td>timeuuid(&#8220;e9229b24-2fbe-11e0-a4de-0026c650d722&#8221;)</td><td>Reproduces
 the specified version 1 UUID node-side.</td></tr></table></body></html>
\ No newline at end of file

Modified: cassandra/trunk/doc/cql/CQL.textile
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/doc/cql/CQL.textile?rev=1068054&r1=1068053&r2=1068054&view=diff
==============================================================================
--- cassandra/trunk/doc/cql/CQL.textile (original)
+++ cassandra/trunk/doc/cql/CQL.textile Mon Feb  7 19:06:11 2011
@@ -202,3 +202,18 @@ String literals are any value enclosed i
 h4. Integers / longs
 
 Integers are any term consisting soley of unquoted numericals, longs are any 
otherwise valid integer term followed by an upper case "L", (e.g. 100L).  It is 
an error to specify an integer term that will not fit in 4 bytes unsigned, or a 
long that will not fit in 8 bytes unsigned.
+
+h4. UUIDs
+
+There are two types of UUIDs supported by the CQL specification, time-based 
(version 1) and randomly generated (version 4). These are specified in 
statements using the @timeuuid(<UUID STRING>)@ and @uuid(<UUID STRING>)@ 
notations respectively.
+
+In addition to the hex-based string representation, @timeuuid()@ terms also 
accept arguments to specify the data-time component. The full list of 
@timeuuid()@ arguments are:
+
+|_. argument|_. example|_. behavior|
+|none|timeuuid()|Results in the creation of a new UUID based on system time of 
the node parsing the query.|
+|now|timeuuid("now")|Results in the creation of a new UUID based on system 
time of the node parsing the query.|
+|milliseconds since epoch|timeuuid(1296755320376)|Creates a UUID with a time 
component that is based on the supplied time-stamp.|
+|"iso8601 
timestamp":http://en.wikipedia.org/wiki/8601|timeuuid("2011-02-01T14:00-0600")|Creates
 a UUID with a time component that is based on the supplied time-stamp.|
+|"string representation 
(hex)":http://tools.ietf.org/html/rfc4122|timeuuid("e9229b24-2fbe-11e0-a4de-0026c650d722")|Reproduces
 the specified version 1 UUID node-side.|
+
+

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g?rev=1068054&r1=1068053&r2=1068054&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g Mon Feb  7 19:06:11 
2011
@@ -176,10 +176,12 @@ createKeyspaceStatement returns [CreateK
       }
     ;
 
-// TODO: date/time, utf8
 term returns [Term item]
-    : ( t=STRING_LITERAL | t=LONG | t=INTEGER | t=UNICODE )
-      { $item = new Term($t.text, $t.type); }
+    : ( t=timeuuid | t=uuid | t=literal ) { $item = t; }
+    ;
+
+literal returns [Term term]
+    : ( t=STRING_LITERAL | t=LONG | t=INTEGER | t=UNICODE ) { $term = new 
Term($t.text, $t.type); }
     ;
 
 termList returns [List<Term> items]
@@ -224,11 +226,20 @@ selectExpression returns [SelectExpressi
 truncateStatement returns [String cfam]
     : K_TRUNCATE columnFamily=IDENT { $cfam = $columnFamily.text; } endStmnt
     ;
-    
+
 endStmnt
     : (EOF | ';')
     ;
 
+uuid returns [Term term]
+    : 'uuid(' uuidstr=STRING_LITERAL ')' { return new Term($uuidstr.text, 
TermType.UUID); }
+    ;
+    
+timeuuid returns [Term term]
+    : 'timeuuid(' uuidstr=( STRING_LITERAL | INTEGER | LONG )? ')' { return 
new Term($uuidstr.text, TermType.TIMEUUID); }
+    ;
+
+
 // Case-insensitive keywords
 K_SELECT:      S E L E C T;
 K_FROM:        F R O M;

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/Term.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/Term.java?rev=1068054&r1=1068053&r2=1068054&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Term.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Term.java Mon Feb  7 
19:06:11 2011
@@ -22,13 +22,32 @@ package org.apache.cassandra.cql;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
+import java.text.ParseException;
 
+import org.apache.cassandra.db.marshal.LexicalUUIDType;
+import org.apache.cassandra.db.marshal.TimeUUIDType;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.UUIDGen;
+import org.apache.commons.lang.time.DateUtils;
 
 /** A term parsed from a CQL statement. */
 public class Term
 {
+    private static String[] iso8601Patterns = new String[] {
+            "yyyy-MM-dd HH:mm",
+            "yyyy-MM-dd HH:mm:ss",
+            "yyyy-MM-dd HH:mmZ",
+            "yyyy-MM-dd HH:mm:ssZ",
+            "yyyy-MM-dd'T'HH:mm",
+            "yyyy-MM-dd'T'HH:mmZ",
+            "yyyy-MM-dd'T'HH:mm:ss",
+            "yyyy-MM-dd'T'HH:mm:ssZ",
+            "yyyy-MM-dd",
+            "yyyy-MM-ddZ"
+    };
+    
     private final String text;
     private final TermType type;
     
@@ -41,10 +60,16 @@ public class Term
      */
     public Term(String text, int type)
     {
-        this.text = text;
+        this.text = text == null ? "" : text;
         this.type = TermType.forInt(type);
     }
     
+    public Term(String text, TermType type)
+    {
+        this.text = text == null ? "" : text;
+        this.type = type;
+    }
+    
     protected Term()
     {
         this.text = "";
@@ -100,6 +125,53 @@ public class Term
                 {
                    throw new RuntimeException(e);
                 }
+            case UUID:
+                try
+                {
+                    return LexicalUUIDType.instance.fromString(text);
+                }
+                catch (IllegalArgumentException e)
+                {
+                    throw new InvalidRequestException(text + " is not valid 
for type uuid");
+                }
+            case TIMEUUID:
+                if (text.equals("") || text.toLowerCase().equals("now"))
+                {
+                    return 
ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(FBUtilities.getLocalAddress())));
+                }
+                
+                // Milliseconds since epoch?
+                if (text.matches("^\\d+$"))
+                {
+                    try
+                    {
+                        return 
ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(Long.parseLong(text)));
+                    }
+                    catch (NumberFormatException e)
+                    {
+                        throw new InvalidRequestException(text + " is not 
valid for type timeuuid");
+                    }
+                }
+                
+                try
+                {
+                    long timestamp = DateUtils.parseDate(text, 
iso8601Patterns).getTime();
+                    return 
ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(timestamp));
+                }
+                catch (ParseException e1)
+                {
+                    // Ignore failures; we'll move onto the Next Thing.
+                }
+                
+                // Last chance, a UUID string (i.e. 
f79326be-2d7b-11e0-b074-0026c650d722)
+                try
+                {
+                    return TimeUUIDType.instance.fromString(text);
+                }
+                catch (IllegalArgumentException e)
+                {
+                    throw new InvalidRequestException(text + " is not valid 
for type timeuuid");
+                }
         }
         
         // FIXME: handle scenario that should never happen
@@ -125,7 +197,7 @@ public class Term
 
 enum TermType
 {
-    STRING, LONG, INTEGER, UNICODE;
+    STRING, LONG, INTEGER, UNICODE, UUID, TIMEUUID;
     
     static TermType forInt(int type)
     {

Modified: cassandra/trunk/test/system/test_cql.py
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_cql.py?rev=1068054&r1=1068053&r2=1068054&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_cql.py (original)
+++ cassandra/trunk/test/system/test_cql.py Mon Feb  7 19:06:11 2011
@@ -1,6 +1,6 @@
 
 from os.path import abspath, dirname, join
-import sys
+import sys, uuid, time
 
 sys.path.append(join(abspath(dirname(__file__)), '../../drivers/py'))
 
@@ -15,6 +15,9 @@ def assert_raises(exception, method, *ar
     except exception:
         return
     raise AssertionError("failed to see expected exception")
+    
+def uuid1bytes_to_millis(uuidbytes):
+    return (uuid.UUID(bytes=uuidbytes).get_time() / 10000) - 12219292800000L
 
 def load_sample(dbconn):
     dbconn.execute("""
@@ -257,3 +260,76 @@ class TestCql(ThriftTester):
         assert ksdef.strategy_class == strategy_class
         assert ksdef.strategy_options['DC1'] == "1"
 
+    def test_time_uuid(self):
+        "store and retrieve time-based (type 1) uuids"
+        conn = init()
+        
+        # Store and retrieve a timeuuid using it's hex-formatted string
+        timeuuid = uuid.uuid1()
+        conn.execute("""
+            UPDATE Standard2 SET timeuuid("%s") = 10 WHERE KEY = "uuidtest"
+        """ % str(timeuuid))
+        
+        r = conn.execute("""
+            SELECT timeuuid("%s") FROM Standard2 WHERE KEY = "uuidtest"
+        """ % str(timeuuid))
+        assert r[0].columns[0].name == timeuuid.bytes
+        
+        # Tests a node-side conversion from long to UUID.
+        ms = uuid1bytes_to_millis(uuid.uuid1().bytes)
+        conn.execute("""
+            UPDATE Standard2 SET "id" = timeuuid(%d) WHERE KEY = "uuidtest"
+        """ % ms)
+        
+        r = conn.execute('SELECT "id" FROM Standard2 WHERE KEY = "uuidtest"')
+        assert uuid1bytes_to_millis(r[0].columns[0].value) == ms
+        
+        # Tests a node-side conversion from ISO8601 to UUID.
+        conn.execute("""
+            UPDATE Standard2 SET "id2" = timeuuid("2011-01-31 17:00:00-0000")
+                    WHERE KEY = "uuidtest"
+        """)
+        
+        r = conn.execute('SELECT "id2" FROM Standard2 WHERE KEY = "uuidtest"')
+        # 2011-01-31 17:00:00-0000 == 1296493200000ms
+        ms = uuid1bytes_to_millis(r[0].columns[0].value)
+        assert ms == 1296493200000, \
+                "%d != 1296493200000 (2011-01-31 17:00:00-0000)" % ms
+
+        # Tests node-side conversion of empty term to UUID
+        conn.execute("""
+            UPDATE Standard2 SET "id3" = timeuuid() WHERE KEY = "uuidtest"
+        """)
+        
+        r = conn.execute('SELECT "id3" FROM Standard2 WHERE KEY = "uuidtest"')
+        ms = uuid1bytes_to_millis(r[0].columns[0].value)
+        assert ((time.time() * 1e3) - ms) < 100, \
+            "timeuuid() not within 100ms of now (UPDATE vs. SELECT)"
+            
+        # Tests node-side conversion of timeuuid("now") to UUID
+        conn.execute("""
+            UPDATE Standard2 SET "id4" = timeuuid("now") WHERE KEY = "uuidtest"
+        """)
+        
+        r = conn.execute('SELECT "id4" FROM Standard2 WHERE KEY = "uuidtest"')
+        ms = uuid1bytes_to_millis(r[0].columns[0].value)
+        assert ((time.time() * 1e3) - ms) < 100, \
+            "timeuuid(\"now\") not within 100ms of now (UPDATE vs. SELECT)"
+        
+        # TODO: slices of timeuuids from cf w/ TimeUUIDType comparator
+        
+    def test_lexical_uuid(self):
+        "store and retrieve lexical uuids"
+        conn = init()
+        uid = uuid.uuid4()
+        conn.execute("""
+            UPDATE Standard2 SET uuid("%s") = 10 WHERE KEY = "uuidtest"
+        """ % str(uid))
+        
+        r = conn.execute("""
+            SELECT uuid("%s") FROM Standard2 WHERE KEY = "uuidtest"
+        """ % str(uid))
+        assert r[0].columns[0].name == uid.bytes
+        
+        # TODO: slices of uuids from cf w/ LexicalUUIDType comparator
+


Reply via email to