【问题标题】:Cassandra 3.x trigger create composite partition keyCassandra 3.x 触发器创建复合分区键
【发布时间】:2016-11-28 19:17:52
【问题描述】:

我一直在学习最新 Cassandra 版本 https://github.com/apache/cassandra/blob/trunk/examples/triggers/src/org/apache/cassandra/triggers/AuditTrigger.java 的示例触发器代码,我想基本上执行相同的逻辑,但我得到了堆栈,因为我的架构包含一个复合键。

问题是如何创建复合键并将其传递到触发器中的 RowUpdateBuilder 中?

审计表的架构看起来像休闲:

CREATE TABLE audit_table (

    aggregate bigint,
    create_date timeuuid,

    ...

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

【问题讨论】:

  • 复合键的结构是什么?它有集群组件吗?您能否发布表格的架构。

标签: triggers cassandra


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-12-21
    • 1970-01-01
    • 2016-11-29
    • 2020-07-05
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    相关资源
    最近更新 更多