简体   繁体   English

Cassandra复合材料列 - 如何选择CompositeTypes?

[英]Cassandra Composite Columns - How are CompositeTypes chosen?

I'm trying to understand the type used when I create composite columns. 我正在尝试理解创建复合列时使用的类型。

I'm using CQL3 (via cqlsh) to create the CF and then the CLI to issue a describe command. 我正在使用CQL3(通过cqlsh)创建CF,然后使用CLI来发出describe命令。 The Types in the Columns sorted by: ...CompositeType(Type1,Type2,...) are not the ones I'm expecting. 列中的类型排序依据:... CompositeType(Type1,Type2,...)不是我期望的那些。

I'm using Cassandra 1.1.6. 我正在使用Cassandra 1.1.6。

CREATE TABLE CompKeyTest1 (
             KeyA int,
             KeyB int,
             KeyC int,
             MyData varchar,
             PRIMARY KEY (KeyA, KeyB, KeyC)
           );

The returned CompositeType is 返回的CompositeType是

CompositeType(Int32,Int32,UTF8)

Shouldn't it be (Int32,Int32,Int32)? 不应该是(Int32,Int32,Int32)?

CREATE TABLE CompKeyTest2 (
             KeyA int,
             KeyB varchar,
             KeyC int,
             MyData varchar,
             PRIMARY KEY (KeyA, KeyB, KeyC)
           );

The returned CompositeType is 返回的CompositeType是

CompositeType(UTF8,Int32,UTF8)

Why isn't it the same as the types used when I define the table? 为什么它与我定义表时使用的类型不一样? I'm probably missing something basic in the type assignment... 我可能遗漏了类型分配中的基本内容......

Thanks! 谢谢!

The composite column name is composed of the values of primary keys 2...n and the name of the non-primary key column being saved. 复合列名称由主键2 ... n的和要保存的非主键列的名称组成。

(So if you have 5 non-key fields then you'll have five such columns and their column names will differ only in the last composed value which would be the non-key field name.) (因此,如果您有5个非关键字段,那么您将拥有5个这样的列,并且它们的列名将仅在最后一个组合值中有所不同,这将是非关键字段名称。)

So in both examples the composite column is made up of the values of KeyB, KeyC and the name of the column being stored ( "MyData" , in both cases). 因此,在这两个示例中,复合列由KeyB,KeyC的和要存储的列的名称组成(在两种情况下都是"MyData" )。 That's why you're seeing those CompositeTypes being returned. 这就是你看到返回那些CompositeTypes的原因。

(btw, the first key in the primary key is the partitioning key and its value is only used as the row key (if you're familiar with Cassandra under the covers). It is not used as part of any of the composite column names.) (顺便说一句,主键中的第一个键是分区键,它的值仅用作行键(如果你熟悉Cassandra的话)。它不作为任何复合列名的一部分使用。)

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

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