1
votes

i'm trying to do queries in my cassandra db. I want to retrieve data in a single Column which is in a superColumn, which is in a superColumn ... a bit complicated but i need it for modelise my db.

I used the documentation of Hector : http://www.datastax.com/sites/default/files/hector-v2-client-doc.pdf

but, when i try to read the single column, this doc purpose to use this method :

    <code>ColumnQuery<String, String, String> columnQuery =
HFactory.createStringColumnQuery(keyspace);
columnQuery.setColumnFamily("Standard1").setKey("jsmith").setName("first");
Result<HColumn<String, String>> result = columnQuery.execute(); </code>

but, what is "Result" ? I search on google , I found that the result is an object Result, but I've all libraries and no one know this object.

I replace Result by QueryResult, but, when I launch my class main, I got this error :

me.prettyprint.hector.api.exceptions.HInvalidRequestException: InvalidRequestException(why:supercolumn parameter is not optional for super CF Super2) at me.prettyprint.cassandra.service.ExceptionsTranslatorImpl.translate(ExceptionsTranslatorImpl.java:45) at me.prettyprint.cassandra.service.KeyspaceServiceImpl$23.execute(KeyspaceServiceImpl.java:851) at me.prettyprint.cassandra.service.KeyspaceServiceImpl$23.execute(KeyspaceServiceImpl.java:1) at me.prettyprint.cassandra.service.Operation.executeAndSetResult(Operation.java:103) at me.prettyprint.cassandra.connection.HConnectionManager.operateWithFailover(HConnectionManager.java:258) at me.prettyprint.cassandra.service.KeyspaceServiceImpl.operateWithFailover(KeyspaceServiceImpl.java:131) at me.prettyprint.cassandra.service.KeyspaceServiceImpl.getColumn(KeyspaceServiceImpl.java:857) at me.prettyprint.cassandra.model.thrift.ThriftColumnQuery$1.doInKeyspace(ThriftColumnQuery.java:57) at me.prettyprint.cassandra.model.thrift.ThriftColumnQuery$1.doInKeyspace(ThriftColumnQuery.java:1) at me.prettyprint.cassandra.model.KeyspaceOperationCallback.doInKeyspaceAndMeasure(KeyspaceOperationCallback.java:20) at me.prettyprint.cassandra.model.ExecutingKeyspace.doExecute(ExecutingKeyspace.java:85) at me.prettyprint.cassandra.model.thrift.ThriftColumnQuery.execute(ThriftColumnQuery.java:52) at com.riptano.cassandra.hector.example.InsertSuperColumn.main(InsertSuperColumn.java:74) Caused by: InvalidRequestException(why:supercolumn parameter is not optional for super CF Super2) at org.apache.cassandra.thrift.Cassandra$get_result.read(Cassandra.java:5930) at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78) at org.apache.cassandra.thrift.Cassandra$Client.recv_get(Cassandra.java:505) at org.apache.cassandra.thrift.Cassandra$Client.get(Cassandra.java:490) at me.prettyprint.cassandra.service.KeyspaceServiceImpl$23.execute(KeyspaceServiceImpl.java:846) ... 11 more

when I focus to the line which cause this error its the line :

**QueryResult<HColumn<String, String>> result5 = result3.execute();**

where I replace Result by QueryResult.

How can i resolve it please ?

1
It appears you are running a standard CF query against a super CF. Your code shows you're running a query against "Standard1", but the exception is for a query against "Super2". Are you sure this code produces that exception?rs_atl
i'm sure, that why I have some problem with my code. Cassandra configuration are so strange :/superstarz
I would suggest asking this in the Cassandra IRC channel, as it's probably a better fit for this type of question.rs_atl

1 Answers

1
votes

I see several problems here...

First -- "data in a single Column which is in a superColumn, which is in a superColumn". You can't do that. You can have columns in superColumns, but there's only one level of nesting. Either way, I'd recommend not using superColumns at all, they are something Cassandra is moving away from in favor of Composite Columns. See if you can adjust your data model to use Composites instead.

Now, moving to your code. You're doing a regular column query on a supercolumn...you need to use a SuperColumnQuery. A SuperColumnQuery takes 4 type params -- the key, super col name, col name, and value types. You also get back a QueryResult object, not a Result. The QueryResult object in this case contains a SuperColumn, which in turns contains a collection of Columns.

So it looks something like...

    SuperColumnQuery<String, String, String, String> superColumnQuery = 
    HFactory.createSuperColumnQuery(ksp);
    superColumnQuery.setColumnFamily("Standard1").setKey("jsmith").setSuperName("first");
    QueryResult<HSuperColumn<String, String, String>> queryResult = superColumnQuery.execute();

    if (queryResult != null && queryResult.get() != null) {
        List<HColumn<String, String>> resultCols = queryResult.get().getColumns();
        for (HColumn<String, String> col : resultCols) {
            doSomething(col.getValue());
        }
    }

Hope this helps!