1

Currently, I have the following schema for one of my tables:

id
name
...
country
  - id
  - name
  - city
    - id
    - name

I was looking around the Cassandra documentation, and I cannot find any clear examples or demonstrations as to how I would represent my super columns in a column family. The code I have is as follows:

CREATE COLUMNFAMILY table (
    id varint,
    name varchar,
    <<regular columns omitted>>
    country ..?,
    PRIMARY KEY = (id)
);
madcrazydrumma
  • 1,727
  • 3
  • 15
  • 34
  • Can you explain what do you want to model? – Alex Ott Feb 11 '18 at 13:08
  • Yeah, **super columns** haven't really been a thing since the Thrift/C* 1.1 days. Any documentation you find which references them should be regarded as *terrifically* out-dated. – Aaron Feb 12 '18 at 15:59

1 Answers1

3

You can create a user-defined type to attach multiple data fields to a column.

For example, in your case

country
  - id
  - name
  - city
    - id
    - name

Can be represented in a UDT as

CREATE TYPE mykeyspace.countryudt (
  id uuid,
  name text,
  city map<uuid, text>
);

Now the table definition will look like,

CREATE COLUMNFAMILY table (
    id varint,
    name varchar,
    <<regular columns omitted>>
    country frozen <countryudt>,
    PRIMARY KEY = (id)
);

Additional reference for UDT here.

dilsingi
  • 2,700
  • 10
  • 23