Milindkumar
Milindkumar

Reputation: 1

Create counter column family in cassandra?

I am using cassandra-2.0.10 and hector api.

I have tried :

    public static void createCounterColumnFamily(Keyspace keyspace, String ccfName) {   
    Mutator<String> mutator = HFactory.createMutator(keyspace,StringSerializer.get());
    mutator.addCounter("salary", ccfName, HFactory.createCounterColumn("salary", 10L));
    mutator.execute();}

But, I'm getting this exception :

Exception in thread "main" me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:unconfigured columnfamily counter_column_family_1)
    at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:45)
    at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:265)
    at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecuteOperation(ExecutingKeyspace.java:113)
    at me.prettyprint.cassandra.model.MutatorImpl.execute(MutatorImpl.java:243)
    at com.cassandra.practice.CounterColumnFamily.createCounterColumnFamily(CounterColumnFamily.java:18)
    at com.cassandra.practice.Bootstrapper.main(Bootstrapper.java:33)
Caused by: InvalidRequestException(why:unconfigured columnfamily counter_column_family_1)
    at org.apache.cassandra.thrift.Cassandra$batch_mutate_result.read(Cassandra.java:20833)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_batch_mutate(Cassandra.java:964)
    at org.apache.cassandra.thrift.Cassandra$Client.batch_mutate(Cassandra.java:950)
    at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:246)
    at me.prettyprint.cassandra.model.MutatorImpl$3.execute(MutatorImpl.java:243)
    at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:104)
    at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258)
    ... 4 more

Am I missing something ?

Upvotes: 0

Views: 150

Answers (1)

zznate
zznate

Reputation: 1908

You need to explicitly create both the column family and the keyspace before you can insert data.

That said the Hector API was deprecated more than five years ago and the Cassandra version you are using is just as far behind. More significantly, the Thrift API has been deprecated completely for years and has already been removed from trunk in the upcoming 4.0 release.

Please switch to 3.11.4 of Cassandra available here: http://cassandra.apache.org/download/

And to using CQL and the java driver for such available here: https://github.com/datastax/java-driver/tree/3.x/manual

Out of curiosity, how did you come across the versions you are currently using?

Upvotes: 2

Related Questions