我尝试在Cassandra 3上实现触发器,通过实现
来捕获特定表上的删除操作 public Collection<Mutation> augment(Partition partition)
ITrigger
界面上的但我无法区分更新和删除操作。
我怎样才能发现该操作是删除操作?
答案 0 :(得分:2)
以下是捕捉所有类型删除的方法
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是群集键
分区级别删除:
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;