用于获取插入值的 Cassandra 示例触发代码 [英] Cassandra Sample Trigger Code to get inserted value
本文介绍了用于获取插入值的 Cassandra 示例触发代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要你的帮助来在触发器扩充方法中提取列名和值.
I need your help on extract column names and values in the trigger augment method.
表格定义:
create table dy_data (
id timeuuid,
data_key text,
time timestamp,
data text,primary key((id,data_key),time)
) with clustering order by (time desc);
触发代码:
public class ArchiveTrigger implements ITrigger {
public Collection<RowMutation> augment(ByteBuffer key, ColumnFamily cf) {
try {
// Below loop only has 2 columns ( one is "data" and another one may be "time" but i am not sure, because i cannot get value.
for (Column cell : cf) {
//Got Exception if I try to get column name
String name = ByteBufferUtil.string(cell.name());
//Got only "data" column value and empty value for another column may be "time". If I try ByteBufferUtil.toLong(cell.value()) it throws exception
String value = ByteBufferUtil.string(cell.value());
log(" name = " + name);
log(" value = " + value);
}
} catch (Exception e) {
logger.warn("Exception ", e);
}
return null;
}
}
我已尽力在 google 中搜索示例代码.但是失败了.请帮助我提供示例代码.提前致谢.
I tried my best to search sample code in google. But failed. Please help me with sample code. Thanks in advance.
推荐答案
要获得 'id' 和 'data_key',您必须拆分键(ByteBuffer 键,要扩充的第一个参数).'time' 将在 cell.name() 的第一部分 - 你仍然需要拆分它.'data' 将是 cell.value(),不需要做任何拆分.
To get 'id' and 'data_key' you'll have to split the key (ByteBuffer key, the first argument to augment). 'time' will be in the first part of cell.name() - you'd still need to split it. 'data' will be the cell.value(), no need to do any splitting.
这篇关于用于获取插入值的 Cassandra 示例触发代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文