Question

After creating a table in CQL3:

CREATE TABLE data(
 row_key text,
 k1 text,
 k2 text,
 PRIMARY KEY (row_key , k1 ,k2 )
);

I would like to know all of the cassandra rows stored in that table. but when I run this in cqlsh:

SELECT row_key  FROM data;

I get back many duplicate entries. I basically get an entry for every column that I inserted. Meaning: I get an entry for row_key for every ( k1 & k2).

But my original intent was: "Give me a list of all the partition (row) keys". I do not want to serialize all of the columns (k1 & k2) too.

What am I doing wrong here?

Was it helpful?

Solution 2

I have currently hot fixed this by using "LIMIT 1" in my SELECT query. It still serializes one column, but not the entire row. This is better than nothing.

OTHER TIPS

This is how CQL3 represents the data internally. it makes partitions for columns. You need to understand the storage model of CQL3. There are very good reads regarding this on DataStax blog. Have a look at these :

http://www.datastax.com/dev/blog/thrift-to-cql3

http://www.datastax.com/dev/blog/cql3-for-cassandra-experts

Edit :
here we are dealing with CQL3 not thrift. if you read the second link in my answer (cql3-for-cassandra-experts) you will understand how data is stored in the storage engine when a table is created using CQL3. say we have created the following table :

    CREATE TABLE song_tags (
      id uuid,
      tag_name text,
      PRIMARY KEY (id, tag_name)
    );

and say we have following rows as represented by a single storage engine :

    f665cfc469eb |    blues  | 1973 

    f665cfc469ea |    covers | 2003

These are stored by CQL3 as follows :

    |id             |    tag_name |
     -----------------------------
    |f665cfc469eb        blues    |
    |f665cfc469eb   |    1973     |
    |                             |
    |f665cfc469ea        covers   |
    |f665cfc469ea   |    2003     |

Now if you do a SELECT * FROM song_tags; this is going to be the output:

    id                                   | column1 | value
    --------------------------------------+---------+-------
    8a172618-b121-4136-bb10-f665cfc469ea |    2003 |
    8a172618-b121-4136-bb10-f665cfc469ea |  covers |
    a3e64f8f-bd44-4f28-b8d9-f665cfc469eb |    1973 |
    a3e64f8f-bd44-4f28-b8d9-f665cfc469eb |   blues |

P.S to achieve what you want; you could try using sets and maps. they might solve your problem.

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