Pergunta

I see extra column being created in my column family when I use cql comparing to cli.

Create table using CQL and insert row:

cqlsh:cassandraSample> CREATE TABLE bedbugs(
               ...     id varchar,
               ...     name varchar,
               ...     description varchar,
               ...     primary key(id, name)
               ... )  ;

cqlsh:cassandraSample> insert into bedbugs (id, name, description) 
values ('Cimex','Cimex lectularius','http://en.wikipedia.org/wiki/Bed_bug');

Now insert column using cli:

[default@cassandraSample] set bedbugs['BatBedBug']['C. pipistrelli:description']='google.com';
Value inserted.
Elapsed time: 1.82 msec(s).
[default@cassandraSample] list bedbugs
...     ;
Using default limit of 100
Using default column limit of 100
-------------------
RowKey: Cimex
=> (column=Cimex lectularius:, value=, timestamp=1369682957658000)
=> (column=Cimex lectularius:description, value=http://en.wikipedia.org/wiki/Bed_bug, timestamp=1369682957658000)
-------------------
RowKey: BatBedBug
=> (column=C. pipistrelli:description, value=google.com, timestamp=1369688651442000)

2 Rows Returned.


cqlsh:cassandraSample> select * from bedbugs;

 id        | name              | description
-----------+-------------------+--------------------------------------
     Cimex | Cimex lectularius | http://en.wikipedia.org/wiki/Bed_bug
 BatBedBug |    C. pipistrelli |                           google.com

So, cql creates one extra column for each row, with empty non-primary key columns. Isn't it waste of space?

Foi útil?

Solução

When you created a column family using CQLSh and specified primary key(Id, name) you make cassandra create two indices of the data stored one for data sorted by ID and the other for data sorted by name. but when you do this by cassandra-cli your column family doesn't have the index column. cassandra-cli doesn't support having secondary indexes. I hope I made sense to you I lack words to explain my understanding.

Outras dicas

For compatibility with cassandra-cli and to prevent this extra column from being created, change your create table statement to include "WITH COMPACT STORAGE".

described here

So

CREATE TABLE bedbugs(
  id varchar,
  name varchar,
  description varchar,
  primary key(id, name)
);

becomes

CREATE TABLE bedbugs(
  id varchar,
  name varchar,
  description varchar,
  primary key(id, name)
) WITH COMPACT STORAGE;

WITH COMPACT STORAGE is also how you would go about supporting wide rows in cql.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top