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 <roshandawr...@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 <roshandawr...@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 <http://twitter.com/roshandawrani>
>> Skype: roshandawrani
>>
>> On Wed, Jan 5, 2011 at 1:32 AM, Victor Kabdebon <
>> victor.kabde...@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 <patric...@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 <
>>>> roshandawr...@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.kabde...@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 <roshandawr...@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 <http://twitter.com/roshandawrani>
>>>>>>> Skype: roshandawrani
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Roshan
>>>>> Blog: http://roshandawrani.wordpress.com/
>>>>> Twitter: @roshandawrani <http://twitter.com/roshandawrani>
>>>>> Skype: roshandawrani
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Patricio.-
>>>>
>>>
>>>
>>


-- 
Roshan
Blog: http://roshandawrani.wordpress.com/
Twitter: @roshandawrani <http://twitter.com/roshandawrani>
Skype: roshandawrani

Reply via email to