b**********5 发帖数: 7881 | 1 twitter streaming api, status json里的ID 是
64 bit long。 我现在要换成cassandra里的 uuid, 怎么convert? | w**z 发帖数: 8232 | 2 why do you want to do that?
UUID is an auto generated ID, mostly based on time
http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/utils
/UUIDs.html
If the ID from twitter is unique and random, use that as partition key
【在 b**********5 的大作中提到】 : twitter streaming api, status json里的ID 是 : 64 bit long。 我现在要换成cassandra里的 uuid, 怎么convert?
| b**********5 发帖数: 7881 | 3 yes, i know. but i still want to convert that twitter ID to a uuid.
actually, there are various version of uuid, time based, name based, random.
twitter gives u the time based unique ID, the first 53 bits or so defines
the time lapsed. But let's say we have a cassandra schema table whose
primary key is uuid (or timeuuid). how can I convert the twitter ID to that
cassandra uuid?
【在 w**z 的大作中提到】 : why do you want to do that? : UUID is an auto generated ID, mostly based on time : http://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/utils : /UUIDs.html : If the ID from twitter is unique and random, use that as partition key
| w**z 发帖数: 8232 | 4 convert long to byte array, then construct UUID from the byte array?
From Java Source code:
/**
* Static factory to retrieve a type 3 (name based) [email protected]/* */ UUID} based
on
* the specified byte array.
*
* @param name
* A byte array to be used to construct a [email protected]/* */ UUID}
*
* @return A [email protected]/* */ UUID} generated from the specified array
*/
public static UUID nameUUIDFromBytes(byte[] name) {
MessageDigest md;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException nsae) {
throw new InternalError("MD5 not supported", nsae);
}
byte[] md5Bytes = md.digest(name);
md5Bytes[6] &= 0x0f; /* clear version */
md5Bytes[6] |= 0x30; /* set to version 3 */
md5Bytes[8] &= 0x3f; /* clear variant */
md5Bytes[8] |= 0x80; /* set to IETF variant */
return new UUID(md5Bytes);
}
random.
defines
that
【在 b**********5 的大作中提到】 : yes, i know. but i still want to convert that twitter ID to a uuid. : actually, there are various version of uuid, time based, name based, random. : twitter gives u the time based unique ID, the first 53 bits or so defines : the time lapsed. But let's say we have a cassandra schema table whose : primary key is uuid (or timeuuid). how can I convert the twitter ID to that : cassandra uuid?
|
|