Question

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. The Types in the Columns sorted by: ...CompositeType(Type1,Type2,...) are not the ones I'm expecting.

I'm using 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(Int32,Int32,UTF8)

Shouldn't it be (Int32,Int32,Int32)?

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

The returned CompositeType is

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!

Was it helpful?

Solution

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.

(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.)

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). That's why you're seeing those CompositeTypes being returned.

(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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top