简体   繁体   English

关于Cassandra复合材料色谱柱的文档

[英]Documentation on Cassandra Composite Columns

When I try to find information on composite columns, I cannot find anything newer than 2013 (specifically this one is Google's top link, which has no CQL code when talking about using the composite columns, and apparently uses a very old Java driver). 当我试图找到有关复合列的信息时,我找不到比2013更新的东西(特别是这个是Google的顶级链接,在讨论使用复合列时没有CQL代码,显然使用的是非常旧的Java驱动程序)。 Do composite columns still exist in newer versions of Cassandra? 复合列是否仍然存在于较新版本的Cassandra中? I mean, apart from having a composite key. 我的意思是,除了有一个复合键。

I am new to Cassandra and actually want to learn if they are suitable for my use-case, described in the following. 我是Cassandra的新手并且实际上想要了解它们是否适合我的用例,如下所述。 Consider a table with 4 double-valued columns, say w , x , y , z . 考虑一个包含4个双值列的表,比如wxyz These data are collected from 3 sources, say a , b and c . 这些数据来自3个来源,比如abc Each source may be missing some part of the data, so there are a maximum of 12 numbers at each row of the table. 每个源可能缺少部分数据,因此表的每一行最多有12个数字。 Instead of creating 3 tables with 4 columns to store values from the different sources, and later merging the tables to fill in the missing fields, I am thinking of having a table that models the 4 data columns as 4 super columns or composite columns . 我不打算创建3个包含4列的表来存储来自不同源的值,然后合并表以填充缺少的字段,而是考虑使用一个表将4个数据列建模为4个super columnscomposite columns Something like a:w , b:w , c:w , a:x , b:x , c:x , a:y , b:y , c:y , a:z , b:z , c:z . 类似于a:wb:wc:wa:xb:xc:xa:yb:yc:ya:zb:zc:z Additionally, every row has a timestamp as the primary key. 此外,每一行都有一个时间戳作为主键。

What I want to find out is whether I can have a query like SELECT *:w AS w FROM MyTable such that for every row, one value for x is returned from any source that is available (doesn't matter from which source). 我想知道的是,我是否可以查询SELECT *:w AS w FROM MyTable ,以便对于每一行, x一个值从任何可用的源返回(与哪个源无关)。 Although I want to also preserve the capability to retrieve data from a specific source, like SELECT a:w FROM MyTable . 虽然我还希望保留从特定源检索数据的功能,例如SELECT a:w FROM MyTable

----------------------------------------------------------------
| key | a:w | b:w | c:w | a:x | b:x | c:x | a:y | b:y | c:y | ...
----------------------------------------------------------------
|  1  | 10  |  10 |  -  | ....
|  2  |  -  |  1  |  2  | ....
|  3  | 11  |  -  |  -  | ....
|  4  | 12  |  11 |  11 | ....
-----------------------------------------------------------------

SELECT *:w AS w FROM MyTable
(10, 1, 11, 12)   // would be an acceptable answer

SELECT a:w AS w FROM MyTable
(10, 11, 12)      // would be an acceptable answer

Composite column is a vocabulary related to Thrift protocol. 复合列是与Thrift协议相关的词汇表。 Internally, until Cassandra 2.2 the storage engine still deals with composite columns and translates them into clustering column , the new vocabulary that comes with CQL . 在内部,直到卡珊德拉2.2存储引擎仍与组合柱交易,并将它们转换集群柱 ,随CQL的新词汇。

Since Cassandra 3.x, the storage engine has been rewritten so we no longer store data using composite columns. 自Cassandra 3.x以来,存储引擎已被重写,因此我们不再使用复合列存储数据。 We align the storage engine with the new CQL semantics eg Partition key/clustering column. 我们将存储引擎与新的CQL语义(例如分区键/聚类列)对齐。 For backward compatibility we still translate clustering column back to composite column semantics when dealing with legacy Thrift protocol. 为了向后兼容,我们在处理传统Thrift协议时仍将集群列转换回复合列语义。

If you just start with Cassandra, forget about the old Thrift protocol and use right-away CQL semantics. 如果你只是从Cassandra开始,忘记旧的Thrift协议并使用正确的CQL语义。

For your needs, the following schema should do the job: 根据您的需要,以下架构应该完成这项工作:

CREATE TABLE my_data(
   data text,
   source text,
   PRIMARY KEY ((data), source)
);

INSERT INTO my_data(data, source) VALUES('data1','src1');
INSERT INTO my_data(data, source) VALUES('data1','src2');
...
INSERT INTO my_data(data, source) VALUES('dataN','src1');
...
INSERT INTO my_data(data, source) VALUES('dataN','srcN');

//Select all sources for data1
SELECT source FROM my_data WHERE data='data1';

//Select data and source
SELECT * FROM my_data WHERE data='data1' AND source='src1';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM