2016-07-25 105 views
2

我一直在休耕最新的Cassandra版本https://github.com/apache/cassandra/blob/trunk/examples/triggers/src/org/apache/cassandra/triggers/AuditTrigger.java的示例觸發器代碼,我基本上執行相同的邏輯,但是我得到堆棧是因爲我的模式包含複合鍵。Cassandra 3.x觸發器創建複合分區鍵

問題是如何創建組合鍵並將其傳遞到觸發器中的RowUpdateBuilder中?

審覈表的架構看起來休耕:

CREATE TABLE audit_table (

    aggregate bigint, 
    create_date timeuuid, 

    ... 

    PRIMARY KEY(aggregate, create_date) 
) WITH CLUSTERING ORDER BY (create_date ASC); 
+0

你的組合鍵的結構是什麼?它有一個集羣組件嗎?你可以發佈表格的架構嗎? – mikea

回答

0

你創建你RowBuilderUpdate,那麼你可以調用clustering函數來設置聚集鍵後。之後,您可以正常使用它。

public Collection<Mutation> augment(Partition update) { 
    ... 

    int cluster = 1; 
    ... 

    RowUpdateBuilder audit = 
     new RowUpdateBuilder(Schema.instance.getCFMetaData(auditKeyspace, auditTable), 
          FBUtilities.timestampMicros(), 
          (java.lang.Object)key); 

    audit = audit.clustering(cluster); 

    ... 
    return Collections.singletonList(audit.build()); 
} 

此外,如果你需要從觸發它的記錄項,檢查出this answer