Take the 2-minute tour ×

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

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)
share|improve this answer
add comment

Your Answer


