Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
复合blob键上的cassandra触发器_Cassandra - Fatal编程技术网

复合blob键上的cassandra触发器

复合blob键上的cassandra触发器,cassandra,Cassandra,我使用Cassandra 2.1.9,并具有类似于表的功能 create table "Keyspace1"."Standard4" ( id blob, user_name blob, data blob, primary key(id, user_name)); 创建表“Keyspace1”。“Standard4”(id blob、用户名blob、数据blob、主键(id、用户名)); 我跟着帖子,做了如下的触发代码 public class InvertedIndex implements

我使用Cassandra 2.1.9,并具有类似于表的功能

create table "Keyspace1"."Standard4" ( id blob, user_name blob, data blob, primary key(id, user_name)); 创建表“Keyspace1”。“Standard4”(id blob、用户名blob、数据blob、主键(id、用户名)); 我跟着帖子,做了如下的触发代码

public class InvertedIndex implements ITrigger { private static final Logger logger = LoggerFactory.getLogger(InvertedIndex.class); public Collection augment(ByteBuffer key, ColumnFamily update) { CFMetaData cfm = update.metadata(); ByteBuffer id_bb = key; String id_Value = new String(id_bb.array()); Iterator col_itr=update.iterator(); Cell username_col=(Cell)col_itr.next(); ByteBuffer username_bb=CompositeType.extractComponent(username_col.name().collectionElement(),0); String username_Value = new String(username_bb.array()); Cell data_col=(Cell)col_itr.next(); ByteBuffer data_bb=BytesType.instance.compose(data_col.value()); String data_Value = new String(data_bb.array()); logger.info(" id --> "+id_Value); logger.info(" username-->"+username_Value); logger.info(" data ---> "+data_Value); return null; } } 公共类InvertDindex实现ITrigger { 私有静态最终记录器Logger=LoggerFactory.getLogger(InvertedIndex.class); 公共集合扩充(ByteBuffer键,ColumnFamily更新) { CFMetaData cfm=update.metadata(); ByteBuffer id_bb=键; 字符串id_值=新字符串(id_bb.array()); 迭代器col_itr=update.Iterator(); 单元格用户名_col=(单元格)col_itr.next(); ByteBuffer username\u bb=CompositeType.extractComponent(username\u col.name().collectionElement(),0); 字符串username_Value=新字符串(username_bb.array()); Cell data_col=(Cell)col_itr.next(); ByteBuffer data_bb=BytesType.instance.compose(data_col.value()); 字符串数据_值=新字符串(data_bb.array()); logger.info(“id-->”+id_值); logger.info(“用户名-->”+用户名值); logger.info(“数据-->”+数据值); 返回null; } } 我尝试在“Keyspace1”“Standard4”(id、用户名、数据)中插入值(textAsBlob('id1')、textAsBlob('user\u name1')、textAsBlob('data1')

并在ByteBuffer username_bb=CompositeType.extractComponent(username_col.name().collectionElement(),0)中获得运行时异常

原因:java.lang.NullPointerException:null 在org.apache.cassandra.db.marshal.CompositeType.extractComponent(CompositeType.java:191)~[apache-cassandra-2.1.9.jar:2.1.9] 在org.apache.cassandra.triggers.inversedindex.augment(inversedindex.java:52)~[na:na] 在org.apache.cassandra.triggers.TriggerExecutor.executeInternal(TriggerExecutor.java:223)~[apache-cassandra-2.1.9.jar:2.1.9] ... 省略17个公共框架
有人能告诉我如何更正吗?

您正在尝试正确显示所有插入的列名和值?
代码如下:

@Override
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) {
    CFMetaData cfm = update.metadata();
    System.out.println("key => " + ByteBufferUtil.toInt(key));
    for (Cell cell : update) {
        if (cell.value().remaining() > 0) {
            try {
                String name = cfm.comparator.getString(cell.name());
                String value = cfm.getValueValidator(cell.name()).getString(cell.value());
                System.out.println("Column Name => " + name + " Value => " + value);
            } catch (Exception e) {
                System.out.println("Exception : " + e.getMessage());
            }
        }
    }
    return null;
}
@覆盖
公共集合扩充(ByteBuffer键,ColumnFamily更新){
CFMetaData cfm=update.metadata();
System.out.println(“key=>”+ByteBufferUtil.toInt(key));
用于(单元格:更新){
if(cell.value().remaining()>0){
试一试{
String name=cfm.comparator.getString(cell.name());
String value=cfm.getValueValidator(cell.name()).getString(cell.value());
System.out.println(“列名=>”+Name+“值=>”+Value);
}捕获(例外e){
System.out.println(“异常:+e.getMessage());
}
}
}
返回null;
}
@Override
public Collection<Mutation> augment(ByteBuffer key, ColumnFamily update) {
    CFMetaData cfm = update.metadata();
    System.out.println("key => " + ByteBufferUtil.toInt(key));
    for (Cell cell : update) {
        if (cell.value().remaining() > 0) {
            try {
                String name = cfm.comparator.getString(cell.name());
                String value = cfm.getValueValidator(cell.name()).getString(cell.value());
                System.out.println("Column Name => " + name + " Value => " + value);
            } catch (Exception e) {
                System.out.println("Exception : " + e.getMessage());
            }
        }
    }
    return null;
}