[英]Creating composite columns cassandra
I need to store benchmark runs for each nightly builds. 我需要存储每个夜间构建的基准运行。 To do this, i came up with the following data model.
为此,我想出了以下数据模型。
BenchmarkColumnFamily= {
build_1: {
(Run1, TPS) : 1000K
(Run1, Latency) : 0.5ms
(Run2, TPS) : 1000K
(Run2, Latency) : 0.5ms
(Run3, TPS) : 1000K
(Run3, Latency) : 0.5ms
}
build_2: {
...
}
...
}
To create such a schema, i came up with the following command on cassandra-cli: 为了创建这样的模式,我在cassandra-cli上想到了以下命令:
create column family BenchmarkColumnFamily with
comparator = 'CompositeType(UTF8Type,UTF8Type)' AND
key_validation_class=UTF8Type AND
default_validation_class=UTF8Type AND
column_metadata = [
{column_name: TPS, validation_class: UTF8Type}
{column_name: Latency, validation_class: UTF8Type}
];
Does the above command create the schema i intend to create? 上面的命令是否创建我打算创建的模式? The reason for my confusion is that, when i insert data into the above CF using:
set BenchmarkColumnFamily['1545']['TPS']='100';
我感到困惑的原因是,当我使用以下命令将数据插入上述CF时:
set BenchmarkColumnFamily['1545']['TPS']='100';
it gets inserted successfully even though the comparator type is composite. 即使比较器类型为复合类型,也可以成功插入。 Furthermore, even the following command gets executed successfully
此外,即使以下命令也可以成功执行
set BenchmarkColumnFamily['1545']['Run1:TPS']='1000';
What is it that im missing? 我想念的是什么?
The cassandra-cli tool is very limited in dealing with composites. cassandra-cli工具在处理复合材料方面非常有限。 Also, some unexpected things can happen in Cassandra with respect to validation of explicit, user-supplied composites.
此外,在验证用户提供的明确复合材料方面,Cassandra中可能会发生一些意外情况。 I don't know the exact answer for your situation, but I can tell you that you'll find this sort of model vastly easier to work with using the CQL 3 engine.
我不知道适合您情况的确切答案,但是我可以告诉您,您会发现使用CQL 3引擎可以大大简化此类模型。
For example, your model could be expressed as: 例如,您的模型可以表示为:
CREATE TABLE BenchmarkColumnFamily (
build text,
run int,
tps text,
latency text,
PRIMARY KEY (build, run)
);
INSERT INTO BenchmarkColumnFamily (build, run, tps, latency) VALUES ('1545', 1, '1000', '0.5ms');
See this post for more information about how that translates to the storage-engine layer. 有关如何将其转换为存储引擎层的更多信息,请参见这篇文章 。
I don't think you're doing anything wrong. 我认为您没有做错任何事情。 The CLI is parsing the strings for values based on the type, probably using
org.apache.cassandra.db.marshal.AbstractType<T>.fromString()
. CLI正在基于类型解析值的字符串,可能使用
org.apache.cassandra.db.marshal.AbstractType<T>.fromString()
。 And for Composite types, it uses ':' as field separator (not that I've seen documented, but I've experimented with Java code to convince myself. 对于Composite类型,它使用':'作为字段分隔符(不是我见过的文档,但我已经尝试使用Java代码说服自己。
Without a ':', it seems to just set the first part of the Composite, and leave the second as null. 如果没有':',似乎只设置Composite的第一部分,而将第二部分保留为null。 To set the second only, you can use
要仅设置第二个,可以使用
set BenchmarkColumnFamily['1545'][':NOT_TPS']='999';
From the CLI, dump out the CF: 从CLI,转储CF:
list BenchmarkColumnFamily;
and you should see all the names (for all the rows), eg 并且您应该看到所有名称(针对所有行),例如
RowKey: 1545
=> (column=:NOT_TPS, value=999, timestamp=1342474086048000)
=> (column=Run1:TPS, value=1000, timestamp=1342474066695000)
=> (column=TPS, value=100, timestamp=1342474057824000)
There is no way (via CLI) to constrain the composite elements to be non-null or specific values, that's something you'd have to do in code. 无法(通过CLI)将复合元素限制为非null或特定值,这是您在代码中必须要做的。
Also, the column_metadata option for the CF creation is unnecessary, since you've already listed the default validation as UTF8Type. 另外,由于已经将默认验证列为UTF8Type,因此不需要创建CF的column_metadata选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.