Reputation: 1
I am very new to astyanax, i have googled and could not find a simple example to insert a composite column. Can anyone provide a simple example? for example composite column type is Long:Long:Long as 123:122:233, value as string "test string". thanks ahead.
Upvotes: 0
Views: 2210
Reputation: 160
Try this:
//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();
Upvotes: 0
Reputation: 11
I would try downloading the source and looking at the unit tests. There's at least one test that demonstrates it. Once you look at the source you'll see why I recommended that route instead of just posting a code snippet. It covers a fair amount.
Upvotes: 1