Add timeuuid type to CQL3 patch by slebresne; reviewed by jbellis for CASSANDRA-4194
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/e53d980f Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/e53d980f Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/e53d980f Branch: refs/heads/cassandra-1.1 Commit: e53d980f6af2ca6d696906a646a86808226ad629 Parents: 5b024bd Author: Sylvain Lebresne <sylv...@datastax.com> Authored: Thu May 3 09:14:01 2012 +0200 Committer: Sylvain Lebresne <sylv...@datastax.com> Committed: Thu May 3 09:14:01 2012 +0200 ---------------------------------------------------------------------- CHANGES.txt | 5 ++- src/java/org/apache/cassandra/cql3/CFPropDefs.java | 1 + .../org/apache/cassandra/db/marshal/DateType.java | 15 +++++--- .../apache/cassandra/db/marshal/TimeUUIDType.java | 27 +-------------- 4 files changed, 14 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/e53d980f/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 3c452ca..2bbe377 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -23,8 +23,9 @@ * Expose repairing by a user provided range (CASSANDRA-3912) * Add way to force the cassandra-cli to refresh it's schema (CASSANDRA-4052) * Avoids having replicate on write tasks stacking up at CL.ONE (CASSANDRA-2889) - * (cql) Fix order by for reversed queries (CASSANDRA-4160) - * (cql) Add ReversedType support (CASSANDRA-4004) + * (cql3) Fix order by for reversed queries (CASSANDRA-4160) + * (cql3) Add ReversedType support (CASSANDRA-4004) + * (cql3) Add timeuuid type (CASSANDRA-4194) Merged from 1.0: * Fix super columns bug where cache is not updated (CASSANDRA-4190) * fix maxTimestamp to include row tombstones (CASSANDRA-4116) http://git-wip-us.apache.org/repos/asf/cassandra/blob/e53d980f/src/java/org/apache/cassandra/cql3/CFPropDefs.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/cql3/CFPropDefs.java b/src/java/org/apache/cassandra/cql3/CFPropDefs.java index 593352a..8196c4e 100644 --- a/src/java/org/apache/cassandra/cql3/CFPropDefs.java +++ b/src/java/org/apache/cassandra/cql3/CFPropDefs.java @@ -74,6 +74,7 @@ public class CFPropDefs comparators.put("uuid", "UUIDType"); comparators.put("varchar", "UTF8Type"); comparators.put("varint", "IntegerType"); + comparators.put("timeuuid", "TimeUUIDType"); keywords.add(KW_COMMENT); keywords.add(KW_READREPAIRCHANCE); http://git-wip-us.apache.org/repos/asf/cassandra/blob/e53d980f/src/java/org/apache/cassandra/db/marshal/DateType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/DateType.java b/src/java/org/apache/cassandra/db/marshal/DateType.java index 9994876..671d31c 100644 --- a/src/java/org/apache/cassandra/db/marshal/DateType.java +++ b/src/java/org/apache/cassandra/db/marshal/DateType.java @@ -82,24 +82,28 @@ public class DateType extends AbstractType<Date> if (source.isEmpty()) return ByteBufferUtil.EMPTY_BYTE_BUFFER; + return ByteBufferUtil.bytes(dateStringToTimestamp(source)); + } + + public static long dateStringToTimestamp(String source) throws MarshalException + { long millis; - ByteBuffer idBytes = null; + source = source.toLowerCase(); if (source.toLowerCase().equals("now")) { millis = System.currentTimeMillis(); - idBytes = ByteBufferUtil.bytes(millis); } // Milliseconds since epoch? else if (source.matches("^\\d+$")) { try { - idBytes = ByteBufferUtil.bytes(Long.parseLong(source)); + millis = Long.parseLong(source); } catch (NumberFormatException e) { - throw new MarshalException(String.format("unable to make long (for date) from: '%s'", source), e); + throw new MarshalException(String.format("unable to make long (for date) from: '%s'", source), e); } } // Last chance, attempt to parse as date-time string @@ -108,7 +112,6 @@ public class DateType extends AbstractType<Date> try { millis = DateUtils.parseDate(source, iso8601Patterns).getTime(); - idBytes = ByteBufferUtil.bytes(millis); } catch (ParseException e1) { @@ -116,7 +119,7 @@ public class DateType extends AbstractType<Date> } } - return idBytes; + return millis; } public void validate(ByteBuffer bytes) throws MarshalException http://git-wip-us.apache.org/repos/asf/cassandra/blob/e53d980f/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java index f2ed1f5..48dd2c8 100644 --- a/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java +++ b/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java @@ -134,34 +134,9 @@ public class TimeUUIDType extends AbstractType<UUID> if (uuid.version() != 1) throw new MarshalException("TimeUUID supports only version 1 UUIDs"); } - else if (source.toLowerCase().equals("now")) - { - idBytes = ByteBuffer.wrap(UUIDGen.decompose(UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()))); - } - // Milliseconds since epoch? - else if (source.matches("^\\d+$")) - { - try - { - idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(Long.parseLong(source))); - } - catch (NumberFormatException e) - { - throw new MarshalException(String.format("unable to make version 1 UUID from '%s'", source), e); - } - } - // Last chance, attempt to parse as date-time string else { - try - { - long timestamp = DateUtils.parseDate(source, iso8601Patterns).getTime(); - idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(timestamp)); - } - catch (ParseException e1) - { - throw new MarshalException(String.format("unable to coerce '%s' to version 1 UUID", source), e1); - } + idBytes = ByteBuffer.wrap(UUIDGen.getTimeUUIDBytes(DateType.dateStringToTimestamp(source))); } return idBytes;