2
votes

I've been fallowing the example trigger code for the latest Cassandra release https://github.com/apache/cassandra/blob/trunk/examples/triggers/src/org/apache/cassandra/triggers/AuditTrigger.java and I want to basically perform the same logic, but I got stack because my schema contains a composite key.

The question is how can I create the composite key and pass it into RowUpdateBuilder within the trigger?

The schema of the audit table looks as fallows:

CREATE TABLE audit_table (

    aggregate bigint,
    create_date timeuuid,

    ...

    PRIMARY KEY(aggregate, create_date)
) WITH CLUSTERING ORDER BY (create_date ASC);
1
What is the structure of your composite key? Does it have a clustering component? Could you post the schema for the table please. - mikea

1 Answers

0
votes

After you've created you're RowBuilderUpdate you can then call the clustering function to set the clustering key. After that you use it as normal.

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());
}

Also if you need to get the key from the record that triggered it, check out this answer.