cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Siddharth Verma <verma.siddha...@snapdeal.com>
Subject Get clustering column in Custom cassandra trigger
Date Thu, 26 May 2016 06:34:29 GMT
hi,
I am creating a trigger in cassandra
-----------------------------------------------------------------------------------------------------------------------
public class GenericAuditTrigger implements ITrigger
{

    private static SimpleDateFormat dateFormatter = new SimpleDateFormat
("yyyy/MM/dd");

    public Collection<Mutation> augment(Partition update)
    {
        String auditKeyspace = "test";
        String auditTable = "audit";

        RowUpdateBuilder audit = new
RowUpdateBuilder(Schema.instance.getCFMetaData(auditKeyspace, auditTable),
                FBUtilities.timestampMicros(),
                UUIDGen.getTimeUUID())
                .clustering(dateFormatter.format(new
Date()),update.metadata().ksName,update.metadata().cfName,UUID.randomUUID());


audit.add("primary_key",update.metadata().getKeyValidator().getString(update.partitionKey().getKey()));

        UnfilteredRowIterator unfilteredRowIterator =
update.unfilteredIterator();
        StringBuilder next=new StringBuilder();
        while(unfilteredRowIterator.hasNext()){
            next.append(unfilteredRowIterator.next().toString()+"\001");
        }

        audit.add("values",
next.length()==0?null:next.deleteCharAt(next.length()-1).toString()+";"+update.columns().toString());

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

-----------------------------------------------------------------------------------------------------------------------
CREATE TABLE test.test (pk1 text, pk2 text, ck1 text, ck2 text, v1 text, v2
text, PRIMARY KEY((pk1,pk2),ck1,ck2);
-----------------------------------------------------------------------------------------------------------------------
CREATE TABLE test.audit (
    timeuuid timeuuid,
    date text,
    keyspace_name text,
    table_name text,
    uuid UUID,
    primary_key text,
    values text,
    PRIMARY KEY (timeuuid, date, keyspace_name, table_name, uuid));
-----------------------------------------------------------------------------------------------------------------------



*How to get clustering column values in trigger?*insert into test(pk1 , pk2
, ck1 , ck2 , v1 , v2 ) VALUES ('pk1','pk2','ck1','ck2_del','v1','v2');

select * from audit;

timeuuid              | 0d117390-227e-11e6-9d80-dd871f2f22d2
date                    | 2016/05/25
keyspace_name  | test
table_name         | test
uuid                    | df274fc0-4362-42b1-a3bf-0030f8d2062f
primary_key        | pk1:pk2
values                | [[v1=v1 ts=1464184100769315], [v2=v2
ts=1464184100769315]]


How to audit ck1 and ck2 also?

Thanks,
Siddharth Verma

Mime
View raw message