cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patricio Echagüe <patric...@gmail.com>
Subject Re: Converting a TimeUUID to a long (timestamp) and vice-versa
Date Wed, 05 Jan 2011 18:13:27 GMT
Roshan, just a comment in your solution. The time returned is not a simple
long. It also contains some bits indicating the version.
On the other hand, you are assuming that the same machine is processing your
request and recreating a UUID base on a long you provide. The
clockseqAndNode id will vary if another machine takes care of the request
(referring to your use case) .

Is it possible for you to send the UUID to the view? I think that would be
the correct behavior as a simple long does not contain enough information to
recreate the original UUID.

Does it make sense?

On Wed, Jan 5, 2011 at 8:36 AM, Nate McCall <nate@riptano.com> wrote:

> It was our original intention on discussing this feature was to have
> back-and-forth conversion from timestamps (we were modelling similar
> functionality in Pycassa). It's lack of inclusion may have just been
> an oversight. We will add this in Hector trunk shortly - thanks for
> the complete code sample.
>
>
>
> On Tue, Jan 4, 2011 at 10:06 PM, Roshan Dawrani <roshandawrani@gmail.com>
> wrote:
> > Ok, found the solution - finally ! - by applying opposite of what
> > createTime() does in TimeUUIDUtils. Ideally I would have preferred for
> this
> > solution to come from Hector API, so I didn't have to be tied to the
> private
> > createTime() implementation.
> >
> > ================================================================
> > import java.util.UUID;
> > import me.prettyprint.cassandra.utils.TimeUUIDUtils;
> >
> > public class TryHector {
> >     public static void main(String[] args) throws Exception {
> >         final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH =
> > 0x01b21dd213814000L;
> >
> >         UUID u1 = TimeUUIDUtils.getUniqueTimeUUIDinMillis();
> >         final long t1 = u1.timestamp();
> >
> >         long tmp = (t1 - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
> >
> >         UUID u2 = TimeUUIDUtils.getTimeUUID(tmp);
> >         long t2 = u2.timestamp();
> >
> >         System.out.println(u2.equals(u1));
> >         System.out.println(t2 == t1);
> >     }
> >
> > }
> >  ================================================================
> >
> >
> > On Wed, Jan 5, 2011 at 8:15 AM, Roshan Dawrani <roshandawrani@gmail.com>
> > wrote:
> >>
> >> If I use com.eaio.uuid.UUID directly, then I am able to do what I need
> >> (attached a Java program for the same), but unfortunately I need to deal
> >> with java.util.UUID in my application and I don't have its equivalent
> >> com.eaio.uuid.UUID at the point where I need the timestamp value.
> >>
> >> Any suggestion on how I can achieve the equivalent using Hector
> library's
> >> TimeUUIDUtils?
> >>
> >> On Wed, Jan 5, 2011 at 7:21 AM, Roshan Dawrani <roshandawrani@gmail.com
> >
> >> wrote:
> >>>
> >>> Hi Victor / Patricio,
> >>>
> >>> I have been using Hector library's TimeUUIDUtils. I also just looked at
> >>> TimeUUIDUtilsTest also but didn't find anything similar being tested
> there.
> >>>
> >>> Here is what I am trying and it's not working - I am creating a Time
> >>> UUID, extracting its timestamp value and with that I create another
> Time
> >>> UUID and I am expecting both time UUIDs to have the same timestamp()
> value -
> >>> am I doing / expecting something wrong here?:
> >>>
> >>> =======================================================
> >>> import java.util.UUID;
> >>> import me.prettyprint.cassandra.utils.TimeUUIDUtils;
> >>>
> >>> public class TryHector {
> >>>     public static void main(String[] args) throws Exception {
> >>>         UUID someUUID = TimeUUIDUtils.getUniqueTimeUUIDinMillis();
> >>>         long timestamp1 = someUUID.timestamp();
> >>>
> >>>         UUID otherUUID = TimeUUIDUtils.getTimeUUID(timestamp1);
> >>>         long timestamp2 = otherUUID.timestamp();
> >>>
> >>>         System.out.println(timestamp1);
> >>>         System.out.println(timestamp2);
> >>>     }
> >>> }
> >>> =======================================================
> >>>
> >>> I have to create the timestamp() equivalent of my time UUIDs so I can
> >>> send it to my UI client, for which it will be simpler to compare "long"
> >>> timestamp than comparing UUIDs. Then for the "long" timestamp chosen by
> the
> >>> client, I need to re-create the equivalent time UUID and go and filter
> the
> >>> data from Cassandra database.
> >>>
> >>> --
> >>> Roshan
> >>> Blog: http://roshandawrani.wordpress.com/
> >>> Twitter: @roshandawrani
> >>> Skype: roshandawrani
> >>>
> >>> On Wed, Jan 5, 2011 at 1:32 AM, Victor Kabdebon
> >>> <victor.kabdebon@gmail.com> wrote:
> >>>>
> >>>> Hi Roshan,
> >>>> Sorry I misunderstood your problem.It is weird that it doesn't work,
> it
> >>>> works for me...
> >>>> As Patricio pointed out use hector "standard" way of creating TimeUUID
> >>>> and tell us if it still doesn't work.
> >>>> Maybe you can paste here some of the code you use to query your
> columns
> >>>> too.
> >>>>
> >>>> Victor K.
> >>>> http://www.voxnucleus.fr
> >>>>
> >>>> 2011/1/4 Patricio Echagüe <patricioe@gmail.com>
> >>>>>
> >>>>> In Hector framework, take a look at TimeUUIDUtils.java
> >>>>>
> >>>>> You can create a UUID using   TimeUUIDUtils.getTimeUUID(long time);
> or
> >>>>> TimeUUIDUtils.getTimeUUID(ClockResolution clock)
> >>>>>
> >>>>> and later on, TimeUUIDUtils.getTimeFromUUID(..) or just
> >>>>> UUID.timestamp();
> >>>>>
> >>>>> There are some example in TimeUUIDUtilsTest.java
> >>>>>
> >>>>> Let me know if it helps.
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Tue, Jan 4, 2011 at 10:27 AM, Roshan Dawrani
> >>>>> <roshandawrani@gmail.com> wrote:
> >>>>>>
> >>>>>> Hello Victor,
> >>>>>>
> >>>>>> It is actually not that I need the 2 UUIDs to be exactly same
- they
> >>>>>> need to be same timestamp wise.
> >>>>>>
> >>>>>> So, what I need is to extract the timestamp portion from a time
UUID
> >>>>>> (say, U1) and then later in the cycle, use the same long timestamp
> value to
> >>>>>> re-create a UUID (say, U2) that is equivalent of the previous
one in
> terms
> >>>>>> of its timestamp portion - i.e., I should be able to give this
U2
> and filter
> >>>>>> the data from a column family - and it should be same as if
I had
> used the
> >>>>>> original UUID U1.
> >>>>>>
> >>>>>> Does it make any more sense than before? Any way I can do that?
> >>>>>>
> >>>>>> rgds,
> >>>>>> Roshan
> >>>>>>
> >>>>>> On Tue, Jan 4, 2011 at 11:46 PM, Victor Kabdebon
> >>>>>> <victor.kabdebon@gmail.com> wrote:
> >>>>>>>
> >>>>>>> Hello Roshan,
> >>>>>>> Well it is normal to do not be able to get the exact same
UUID from
> a
> >>>>>>> timestamp, it is its purpose.
> >>>>>>> When you create an UUID you have in fact two information
: random
> 64
> >>>>>>> bits number - 64 bits timestamp. You put that together and
you have
> your
> >>>>>>> uuid.
> >>>>>>> .
> >>>>>>> So unless you save your random number two UUID for the same
milli(
> or
> >>>>>>> micro) second are different.
> >>>>>>> Best regards,
> >>>>>>> Victor K.
> >>>>>>> http://www.voxnucleus.fr
> >>>>>>>
> >>>>>>> 2011/1/4 Roshan Dawrani <roshandawrani@gmail.com>
> >>>>>>>>
> >>>>>>>> Hi,
> >>>>>>>> I am having a little difficulty converting a time UUID
to its
> >>>>>>>> timestamp equivalent and back. Can someone please help?
> >>>>>>>>
> >>>>>>>> Here is what I am trying. Is it not the right way to
do it?
> >>>>>>>>
> >>>>>>>> ===========================================================
> >>>>>>>>         UUID someUUID = TimeUUIDUtils.getUniqueTimeUUIDinMillis();
> >>>>>>>>
> >>>>>>>>         long time = someUUID.timestamp(); /* convery
from UUID to
> a
> >>>>>>>> long timestamp */
> >>>>>>>>         UUID otherUUID = TimeUUIDUtils.getTimeUUID(time);
/* do
> the
> >>>>>>>> reverse and get back the UUID from timestamp */
> >>>>>>>>
> >>>>>>>>         System.out.println(someUUID); /* someUUID and
otherUUID
> >>>>>>>> should be same, but are different */
> >>>>>>>>         System.out.println(otherUUID);
> >>>>>>>> ===========================================================
> >>>>>>>>
> >>>>>>>> --
> >>>>>>>> Roshan
> >>>>>>>> Blog: http://roshandawrani.wordpress.com/
> >>>>>>>> Twitter: @roshandawrani
> >>>>>>>> Skype: roshandawrani
> >>>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> --
> >>>>>> Roshan
> >>>>>> Blog: http://roshandawrani.wordpress.com/
> >>>>>> Twitter: @roshandawrani
> >>>>>> Skype: roshandawrani
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Patricio.-
> >>>>
> >>>
> >
> >
> >
> > --
> > Roshan
> > Blog: http://roshandawrani.wordpress.com/
> > Twitter: @roshandawrani
> > Skype: roshandawrani
> >
> >
>



-- 
Patricio.-

Mime
View raw message