是否可以從Scala/Java(用於Cassandra中)在特定Unix時間戳中生成Type 1 UUID,以便可以使用它來獲取範圍記錄片段和表格中的單個記錄。以下結果似乎表明它可能是可能的。從Unix時間戳生成隨機Type 1 UUID以與Cassandra一起使用
import com.datastax.driver.core.utils._
var td = new DateTime(2003,1,1,0,0)
val time_millis = td.getMillis()
val lower = UUIDs.startOf(time_millis)
val upper = UUIDs.endOf(time_millis)
println(lower.getLeastSignificantBits()) # 9187201950435737472
println(lower.getMostSignificantBits()) # -545498504376938025
println(upper.getLeastSignificantBits()) # -9187201950435737471
println(upper.getMostSignificantBits()) # -545455558998945321
背景(如果存在要解決的問題一個更好的方法)。
我想批量導入幾千個車輛記錄到一個Cassandra數據庫。包含日期的列包含將車輛添加到原始數據庫(VCA)的日期,並且在特定日期通常不超過幾百次,這似乎表明在timeuuid中可用的熵可能足以解決此問題;即mac地址,小時,秒,...,100納秒和隨機部分。
示例查詢我需要執行
SELECT * FROM vehicles WHERE manufacturer = 'BMW';
SELECT * FROM vehicles WHERE manufacturer = 'BMW' AND id = a8bb5800-694c-11d7-8080-808080808080;
SELECT * FROM vehicles WHERE manufacturer = 'BMW' AND id < a8bb5800-694c-11d7-8080-808080808080 AND id >= cb59c000-1c26-11d6-8080-808080808080;
在CQL的表模式。
CREATE TABLE vehicles (
id timeuuid,
manufacturer text,
model text,
transmission text,
description text,
engine_capacity double,
fuel_type text,
metric_urban double,
metric_extra_urban double,
metric_combined double,
co2_g_per_km double,
euro_standard int,
noise double,
co double,
hc_nox double,
hc double,
nox double,
particulates double,
date_included timestamp,
PRIMARY KEY (manufacturer, id)
) WITH CLUSTERING ORDER BY (id ASC);
同伴廠家表
SELECT * from manufacturers;
CREATE TABLE manufacturers (
id uuid,
manufacturer text,
years set<int>
PRIMARY KEY (manufacturer, id)
);
您的標題混淆詞'隨機'。 [版本1 UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28MAC_address_.26_date-time.29)基於日期時間和MAC地址,128位中只有少數是隨機的。 [版本4](http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29)是幾乎完全隨機的類型。 – 2014-10-10 05:21:08