Cassandra Sample Trigger Code获取插入值 [英] Cassandra Sample Trigger Code to get inserted value

查看:191
本文介绍了Cassandra Sample Trigger Code获取插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要您在触发扩充方法中提取列名称和值的帮助。

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键,第一个参数augment)。 '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 Sample Trigger Code获取插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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