Cassandra 3.x触发器创建复合分区键

问题描述:

我一直在休耕最新的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

你创建你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