Cassandra 3触发删除操作 [英] Cassandra 3 trigger on delete operation

查看:59
本文介绍了Cassandra 3触发删除操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Cassandra 3上实现触发器,以通过实现

I'm trying to implement a trigger on Cassandra 3 to catch delete operations on a specific table by implementing

 public Collection<Mutation> augment(Partition partition)

但我无法区分更新和删除操作。

on ITrigger interface but I can't differentiate between update and delete operations.

如何捕获该操作是删除操作?

How can I catch that the operation is a delete operation?

推荐答案

这是您如何捕获所有类型的删除

public Collection<Mutation> augment(Partition partition) {
    if(partition.partitionLevelDeletion().isLive()) {
        UnfilteredRowIterator it = partition.unfilteredIterator();
        while (it.hasNext()) {
            Unfiltered unfiltered = it.next();
            switch (unfiltered.kind()) {
                case ROW:
                    Row row = (Row) unfiltered;

                    if (!row.deletion().isLive()) {
                        // Row deletion
                    }

                    for (Cell cell : row.cell()) {
                        if (cell.isTombstone() {
                            // Cell deletion
                        } else {
                            // Insert or Update
                        }  
                    }
                    break;
                case RANGE_TOMBSTONE_MARKER:
                    // Range Deletion
                    break;
            }
        }
    } else {
        // Partition Level Deletion
    }
}

假设我们有此表:

CREATE TABLE kv (
    pk int,
    ck int,
    d int,
    PRIMARY KEY (pk, ck)
);

此处pk为分区键和ck是e集群键

分区级别删除:

DELETE from kv WHERE pk = 1;

范围删除:

DELETE from kv WHERE pk = 1 AND ck > 10;

行删除:

 DELETE from kv WHERE pk = 1 AND ck = 10;

单元格删除:

DELETE d from kv WHERE pk = 1 AND ck = 10;

这篇关于Cassandra 3触发删除操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆