Cassandra Astyanax:如何插入复合柱?
我对astyanax非常陌生,我在谷歌上搜索过,找不到插入复合列的简单示例。有人能举个简单的例子吗?例如,复合列类型为Long:Long:Long为123:122:233,值为字符串“test string”。谢谢。我会尝试下载源代码并查看单元测试。至少有一个测试证明了这一点。一旦你看了源代码,你就会明白为什么我推荐这个路线,而不是仅仅发布一个代码片段。它涵盖了相当多的金额。试试这个:Cassandra Astyanax:如何插入复合柱?,cassandra,Cassandra,我对astyanax非常陌生,我在谷歌上搜索过,找不到插入复合列的简单示例。有人能举个简单的例子吗?例如,复合列类型为Long:Long:Long为123:122:233,值为字符串“test string”。谢谢。我会尝试下载源代码并查看单元测试。至少有一个测试证明了这一点。一旦你看了源代码,你就会明白为什么我推荐这个路线,而不是仅仅发布一个代码片段。它涵盖了相当多的金额。试试这个: //First you need an object. // Annotated composite cla
//First you need an object.
// Annotated composite class
public class SessionEvent{
@Component(ordinal=0) long sessiondId;
@Component(ordinal=1) long timestamp;
@Component(ordinal=2) long userId;
// Must have public default constructor
public SessionEvent() {
}
// ...
// Don't forget to implement hashcode and equals and a constructor that accepts (long, long, long)
}
//...
static AnnotatedCompositeSerializer<SessionEvent> eventSerializer
= new AnnotatedCompositeSerializer<SessionEvent>(SessionEvent.class);
static ColumnFamily<String, SessionEvent> CF_SESSION_EVENTS
= new ColumnFamily<String, SessionEvent>("SessionEvents",
StringSerializer.get(), eventSerializer);
//...
CompositeColumn cc = new SessionEvent("123","456","789"); // Column values
keyspace.prepareColumnMutation(CF_SESSION_EVENTS, "row key goes here", cc)
.putValue("this is the value", null)
.execute();
//首先需要一个对象。
//带注释的复合类
公共类会话事件{
@组件(序号=0)长sessionId;
@组件(序号=1)长时间戳;
@组件(序号=2)长用户ID;
//必须具有公共默认构造函数
公共会话事件(){
}
// ...
//不要忘记实现hashcode和equals以及接受(long,long,long)的构造函数
}
//...
静态AnnotatedCompositeSerializer事件序列化程序
=新的AnnotatedCompositeSerializer(SessionEvent.class);
静态列系列CF\U会话\U事件
=新ColumnFamily(“SessionEvents”,
StringSerializer.get(),eventSerializer);
//...
CompositeColumn cc=新会话事件(“123”、“456”、“789”);//列值
keyspace.prepareColumnMutation(CF_SESSION_事件,“行键转到此处”,cc)
.putValue(“这是值”,null)
.execute();