Does CQL3 require a schema for Cassandra now?

前端 未结 4 1049
迷失自我
迷失自我 2021-02-08 18:39

I\'ve just had a crash course of Cassandra over the last week and went from Thrift API to CQL to grokking SuperColumns to learning I shouldn\'t use them and user Composite Keys

4条回答
  •  没有蜡笔的小新
    2021-02-08 19:22

    I suggest you to explore composite columns with "WITH COMPACT STORAGE". A "COMPACT STORAGE" column family allows you to practically only define key columns:

    Example:

    CREATE TABLE entities_cargo ( entity_id ascii, item_id ascii, qt ascii, PRIMARY KEY (entity_id, item_id) ) WITH COMPACT STORAGE

    Actually, when you insert different values from itemid, you dont add a row with entity_id,item_id and qt, but you add a column with name (item_id content) and value (qt content). So:

    insert into entities_cargo (entity_id,item_id,qt) values(100,'oggetto 1',3);

    insert into entities_cargo (entity_id,item_id,qt) values(100,'oggetto 2',3);

    Now, here is how you see this rows in CQL3:

    cqlsh:goh_master> select * from entities_cargo where entity_id = 100;

    entity_id | item_id | qt

    -----------+-----------+----

      100 | oggetto 1 |  3
    
      100 | oggetto 2 |  3
    

    And how they are if you check tnem from cli:

    [default@goh_master] get entities_cargo[100];

    => (column=oggetto 1, value=3, timestamp=1349853780838000)

    => (column=oggetto 2, value=3, timestamp=1349853784172000)

    Returned 2 results.

    You can access a single column with

    select * from entities_cargo where entity_id = 100 and item_id = 'oggetto 1';

    Hope it helps

提交回复
热议问题