You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Lucas Di Pentima <lu...@di-pentima.com.ar> on 2010/04/24 00:51:54 UTC
Question about TimeUUIDType
Hello,
I'm using Cassandra 0.6.1 with ruby library
I want to log events on a CF like this:
Events = { // CF CompareWith: TimeUUIDType
SomeEventID : { // Row
uuid_from_unix_timestamp : event_data,
...
}
}
I receive event data with a UNIX timestamp (nr of seconds passed since some date on 1970), so I would do something like:
db = Cassandra.new('Keyspace')
db.insert('Events', SomeEventID, {SimpleUUID:UUID.new(Time.at(unix_timestamp)} => event_data)
My first question was: What happens if I have more than one event at the same second? I tried this on irb console and checked that TimeUUIDs are different.
So, my second question is: How different TimeUUIDs generated from the same UNIX timestamp are going to be ordered in the ColumnFamily?
Thanks in advance!!
--
Lucas Di Pentima - Santa Fe, Argentina
Jabber: lucas@di-pentima.com.ar
MSN: ldipenti75@hotmail.com
Re: Question about TimeUUIDType
Posted by Tatu Saloranta <ts...@gmail.com>.
On Sun, Apr 25, 2010 at 5:43 PM, Jonathan Ellis <jb...@gmail.com> wrote:
> On Sun, Apr 25, 2010 at 5:40 PM, Tatu Saloranta <ts...@gmail.com> wrote:
>>> Now with TimeUUIDType, if two UUID have the same timestamps, they are ordered
>>> by bytes order.
>>
>> Naively for the whole UUID? That would not be good, given that
>> timestamp within UUID is not stored in expected lexical order, but
>> with sort of little-endian mess (first bytes are least-significant
>> bytes of timestamp).
>
> I think the code here is clearer than explaining in English. :)
>
> comparing timeuuids o1 and o2:
>
> long t1 = LexicalUUIDType.getUUID(o1).timestamp();
> long t2 = LexicalUUIDType.getUUID(o2).timestamp();
> return t1 < t2 ? -1 : (t1 > t2 ? 1 :
> FBUtilities.compareByteArrays(o1, o2));
:-)
Yes, this makes sense, so it is a two-part sort, not just latter part.
-+ Tatu +-
ps. Not sure if this matters, but I am finally working on Java Uuid
Generator v3, which might help with time-location based UUIDs. Will
announce it on the list when it's ready (in couple of weeks)
Re: Question about TimeUUIDType
Posted by Jonathan Ellis <jb...@gmail.com>.
On Sun, Apr 25, 2010 at 5:40 PM, Tatu Saloranta <ts...@gmail.com> wrote:
>> Now with TimeUUIDType, if two UUID have the same timestamps, they are ordered
>> by bytes order.
>
> Naively for the whole UUID? That would not be good, given that
> timestamp within UUID is not stored in expected lexical order, but
> with sort of little-endian mess (first bytes are least-significant
> bytes of timestamp).
I think the code here is clearer than explaining in English. :)
comparing timeuuids o1 and o2:
long t1 = LexicalUUIDType.getUUID(o1).timestamp();
long t2 = LexicalUUIDType.getUUID(o2).timestamp();
return t1 < t2 ? -1 : (t1 > t2 ? 1 :
FBUtilities.compareByteArrays(o1, o2));
-Jonathan
Re: Question about TimeUUIDType
Posted by Tatu Saloranta <ts...@gmail.com>.
On Sat, Apr 24, 2010 at 2:08 AM, Sylvain Lebresne <sy...@yakaz.com> wrote:
> On Sat, Apr 24, 2010 at 12:53 AM, Jesse McConnell
> <je...@gmail.com> wrote:
>> try LexicalUUIDType, that will distinguish the secs correctly
>>
>> imo based on the existing impl (last I checked at least) TimeUUIDType
>> was equivalent to LongType
>
> It uses to be true that the TimeUUIDType comparator was only comparing the
> timestamps of the UUIDs. But this was more a bug than anything else
> since it made
> different UUID collide and was fixed for 0.6
> (https://issues.apache.org/jira/browse/CASSANDRA-907).
>
> Now with TimeUUIDType, if two UUID have the same timestamps, they are ordered
> by bytes order.
Naively for the whole UUID? That would not be good, given that
timestamp within UUID is not stored in expected lexical order, but
with sort of little-endian mess (first bytes are least-significant
bytes of timestamp).
-+ Tatu +-
Re: Question about TimeUUIDType
Posted by Sylvain Lebresne <sy...@yakaz.com>.
On Sat, Apr 24, 2010 at 12:53 AM, Jesse McConnell
<je...@gmail.com> wrote:
> try LexicalUUIDType, that will distinguish the secs correctly
>
> imo based on the existing impl (last I checked at least) TimeUUIDType
> was equivalent to LongType
It uses to be true that the TimeUUIDType comparator was only comparing the
timestamps of the UUIDs. But this was more a bug than anything else
since it made
different UUID collide and was fixed for 0.6
(https://issues.apache.org/jira/browse/CASSANDRA-907).
Now with TimeUUIDType, if two UUID have the same timestamps, they are ordered
by bytes order.
--
Sylvain
>
> cheers,
> jesse
>
> --
> jesse mcconnell
> jesse.mcconnell@gmail.com
>
>
>
> On Fri, Apr 23, 2010 at 17:51, Lucas Di Pentima <lu...@di-pentima.com.ar> wrote:
>> Hello,
>>
>> I'm using Cassandra 0.6.1 with ruby library
>>
>> I want to log events on a CF like this:
>>
>> Events = { // CF CompareWith: TimeUUIDType
>> SomeEventID : { // Row
>> uuid_from_unix_timestamp : event_data,
>> ...
>> }
>> }
>>
>> I receive event data with a UNIX timestamp (nr of seconds passed since some date on 1970), so I would do something like:
>>
>> db = Cassandra.new('Keyspace')
>> db.insert('Events', SomeEventID, {SimpleUUID:UUID.new(Time.at(unix_timestamp)} => event_data)
>>
>> My first question was: What happens if I have more than one event at the same second? I tried this on irb console and checked that TimeUUIDs are different.
>>
>> So, my second question is: How different TimeUUIDs generated from the same UNIX timestamp are going to be ordered in the ColumnFamily?
>>
>> Thanks in advance!!
>> --
>> Lucas Di Pentima - Santa Fe, Argentina
>> Jabber: lucas@di-pentima.com.ar
>> MSN: ldipenti75@hotmail.com
>>
>>
>>
>>
>>
>
Re: Question about TimeUUIDType
Posted by Jesse McConnell <je...@gmail.com>.
try LexicalUUIDType, that will distinguish the secs correctly
imo based on the existing impl (last I checked at least) TimeUUIDType
was equivalent to LongType
cheers,
jesse
--
jesse mcconnell
jesse.mcconnell@gmail.com
On Fri, Apr 23, 2010 at 17:51, Lucas Di Pentima <lu...@di-pentima.com.ar> wrote:
> Hello,
>
> I'm using Cassandra 0.6.1 with ruby library
>
> I want to log events on a CF like this:
>
> Events = { // CF CompareWith: TimeUUIDType
> SomeEventID : { // Row
> uuid_from_unix_timestamp : event_data,
> ...
> }
> }
>
> I receive event data with a UNIX timestamp (nr of seconds passed since some date on 1970), so I would do something like:
>
> db = Cassandra.new('Keyspace')
> db.insert('Events', SomeEventID, {SimpleUUID:UUID.new(Time.at(unix_timestamp)} => event_data)
>
> My first question was: What happens if I have more than one event at the same second? I tried this on irb console and checked that TimeUUIDs are different.
>
> So, my second question is: How different TimeUUIDs generated from the same UNIX timestamp are going to be ordered in the ColumnFamily?
>
> Thanks in advance!!
> --
> Lucas Di Pentima - Santa Fe, Argentina
> Jabber: lucas@di-pentima.com.ar
> MSN: ldipenti75@hotmail.com
>
>
>
>
>