Skip to content

Embedded super columns in Cassandra

chhavigangwal edited this page Nov 6, 2013 · 5 revisions

Introduction

In order to add more dimensions to traditional key value (row -column) model of Cassandra, you can create further sub-columns in a column. This can be done by embedding super columns in Cassandra using thrift.

This can be achieved using Kundera. Following is an example :

@Entity
@Table(name = "USER", schema = "KunderaExamples@twissandraTest")
public class UserCassandra
{

    @Id
    @Column(name = "USER_ID")
    private String userId;

    // Embedded object, will persist co-located
    @Embedded
    private PersonalDetailCassandra personalDetail;

    // Embedded object, will persist co-located
    @Embedded
    private ProfessionalDetailCassandra professionalDetail;

 
@Embeddable
@IndexCollection(columns = { @Index(name = "name"), @Index(name = "relationshipStatus") })
public class PersonalDetailCassandra
{
    @Column(name = "personal_detail_id")
    private String personalDetailId;

    @Column(name = "person_name")
    private String name;

    @Column(name = "person_password")
    private String password;

    @Column(name = "rel_status")
    private String relationshipStatus;
@Embeddable
@IndexCollection(columns = { @Index(name = "professionId"), @Index(name = "departmentName"),
        @Index(name = "isExceptional"), @Index(name = "age"), @Index(name = "grade"),
        @Index(name = "digitalSignature"), @Index(name = "rating"), @Index(name = "compliance"),
        @Index(name = "height"), @Index(name = "enrolmentDate"), @Index(name = "enrolmentTime"),
        @Index(name = "joiningDateAndTime"), @Index(name = "yearsSpent"), @Index(name = "uniqueId"),
        @Index(name = "monthlySalary"), @Index(name = "birthday"), @Index(name = "birthtime"),
        @Index(name = "anniversary"), @Index(name = "jobAttempts"), @Index(name = "accumulatedWealth"),
        @Index(name = "graduationDay") })
public class ProfessionalDetailCassandra
{
    // Primitive Types
    @Column(name = "PROFESSION_ID")
    private long professionId;

    @Column(name = "DEPARTMENT_NAME")
    private String departmentName;

    @Column(name = "IS_EXCEPTIONAL")
    private boolean isExceptional;

    @Column(name = "AGE")
    private int age;

    @Column(name = "GRADE")
    private char grade; // A,B,C,D,E,F for i to vi

    @Column(name = "DIGITAL_SIGNATURE")
    private byte digitalSignature;

    @Column(name = "RATING")
    private short rating; // 1-10

    @Column(name = "COMPLIANCE")
    private float compliance;

    @Column(name = "HEIGHT")
    private double height;

Cassandra Equivalent :

CREATE TABLE "USER" (
  key text,
  column1 text,
  value blob,
  PRIMARY KEY (key, column1)
) ;
Clone this wiki locally