complex column design in Cassandra and query with Hector

120 views Asked by At

I have a requirement to design like following

Row      Column          Column     
 A  |      B        |      E      |

       SubColumn         SubColumn
       C        D       F        G
       1        2       3        4

I don't know if this type of structure is possible. also i would like to know How to query such a table using Hector client. It would be nice if I can read some examples of insertion , deletion and updation using Hector.

1

There are 1 answers

1
Saurabh Kumar On BEST ANSWER

Inserting a Column on a SuperColumn with Mutator is quite similar to what we have already seen. The only difference is we are now creating an HSuperColumn in place of HColumn to provide some additional structure. For example, if we wanted to store our users under the "billing" department, we would use the following call to Mutator:

 Mutator<String> mutator =
 HFactory.createMutator(keyspace, stringSerializer);
 mutator.insert("billing", "Super1", HFactory.createSuperColumn("jsmith",
 Arrays.asList(HFactory.createStringColumn("first", "John")),
 stringSerializer, stringSerializer, stringSerializer));

As for retrieval of a SuperColumn, the simple case is almost identical to retrieval of a standard Column. The only difference is the Query implementation used.

 SuperColumnQuery<String, String, String, String> superColumnQuery =
 HFactory.createSuperColumnQuery(keyspace, stringSerializer,
 stringSerializer, stringSerializer, stringSerializer);
 superColumnQuery.setColumnFamily("Super1")
 .setKey("billing").setSuperName("jsmith");
  Result<HSuperColumn<String, String, String>> result = superColumnQuery.execute();