2013-07-11 80 views
0

我在SQL世界一個簡單的要求,我想創建卡桑德拉複合柱族

CREATE TABLE event_tracking (
    key text, 
    trackingid timeuuid, 
    entityId bigint, 
    entityType text 
    userid bigint 
    PRIMARY KEY (key, trackingid) 
) 

我需要一個CLI命令創建這是我不能做到這一點。我需要通過CLI創建列族豬不能讀取列家族通過cqlsh(杜)

在這裏創造了什麼我嘗試,並沒有工作

create column family event_tracking 
... WITH comparator='CompositeType(TimeUUIDType)' 
... AND key_validation_class=UTF8Type 
... AND default_validation_class = UTF8Type; 

1)我不知道爲什麼它的價值列添加到當我看到它在cqlsh

CREATE TABLE event_tracking (
    key text, 
    trackingid timeuuid, 
    value text, 
    PRIMARY KEY (key, trackingid) 
) WITH COMPACT STORAGE AND 
    bloom_filter_fp_chance=0.010000 AND 
    caching='KEYS_ONLY' AND 
    comment='' AND 
    dclocal_read_repair_chance=0.000000 AND 
    gc_grace_seconds=864000 AND 
    read_repair_chance=0.100000 AND 
    replicate_on_write='true' AND 
    populate_io_cache_on_flush='false' AND 
    compaction={'class': 'SizeTieredCompactionStrategy'} AND 
    compression={'sstable_compression': 'SnappyCompressor'}; 

2)我使用asynatax插入行。

OperationResult<CqlResult<Integer, String>> result = keyspace.prepareQuery(CQL3_CF) 
    .withCql("INSERT INTO event_tracking (key, column1, value) VALUES ("+System.currentTimeMillis()+","+TimeUUIDUtils.getTimeUUID(System.currentTimeMillis())+",'23232323');").execute(); 

但只要我嘗試添加動態列,它是不能夠識別

OperationResult<CqlResult<Integer, String>> result = keyspace.prepareQuery(CQL3_CF) 
.withCql("INSERT INTO event_tracking (key, column1, value, userId, event) VALUES ("+System.currentTimeMillis()+","+TimeUUIDUtils.getTimeUUID(System.currentTimeMillis())+",'23232323', 123455, 'view');").execute(); 

貌似我無法通過cql3添加動態列

3)如果我嘗試通過cql3添加新列

alter table event_tracking add eventid bigint; 

它給了我

Bad Request: Cannot add new column to a compact CF 

回答

1

0)如果您使用COMPACT STORAGE創建表格,即使您使用CQL3創建表格,Pig也應該能夠看到它。但是,您需要將entityIdentityType放入主鍵中以供其使用(緊湊存儲基本上意味着主鍵中的第一列變爲行鍵,並且以下變爲用作列鍵的組合類型,然後只有一個空間可以再增加一列,這就是價值)。

1)當你創建表的老辦法總是會有一個value,它的列的值,並在CQL3被表示爲稱爲value。這就是CQL3如何將底層存儲模型映射到表。

2)您已經創建了一個表格,其列的類型爲CompositeType(TimeUUIDType),因此您只能添加​​s的列。您無法告訴C *將字符串保存爲​​列鍵。

3)循環回0使用此表:

CREATE TABLE event_tracking (
    key text, 
    trackingid timeuuid, 
    entityId bigint, 
    entityType text, 
    userid bigint, 
    PRIMARY KEY (key, trackingid, entityId, entityType) 
) WITH COMPACT STORAGE 

這一假設只能有一個trackingId/entityId/entityType組合每個userid(什麼與你的不一致資本回事,順便說一句)? 。這不是你需要去完整的動態列路線,但你不能有entityIdentityType不同的數據類型(但這也是CQL3之前的情況),看到這個問題的例子如何做動態欄目:Inserting arbitrary columns in Cassandra using CQL3

+0

謝謝Theo。我的意圖是創建列家族以長鍵(System.getCurrentMilliSeconds()),跟蹤id爲uuid並將它們作爲組合鍵,然後將entityid,entitytype,userid和event添加爲動態列。目的是即使我們同時獲得同時請求,我們也可以在同一行記錄事件。我希望我能說得通。 – plzdontkillme

+0

我可以創建CREATE TABLE event_tracking( 關鍵文字, trackingid timeuuid – plzdontkillme