【发布时间】:2014-10-28 13:21:25
【问题描述】:
是否可以从特定的 Unix 时间戳生成 Scala/Java 中的 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)
);
【问题讨论】:
-
您的标题与单词
random混淆。 Version 1 UUID 基于日期时间和 MAC 地址,128 位中只有少数是随机的。 Version 4 是几乎完全随机的类型。