Search code examples
javacassandracql3astyanax

Astyanax cql3 COUNT query returning ROWS not NUMBER


According to the example page of Astyanax:

https://github.com/Netflix/astyanax/wiki/Cql-and-cql3

When you run a COUNT query, the result returns a "number", so you can query that with:

try {
    OperationResult<CqlResult<String, String>> result
        = keyspace.prepareQuery(CF_STANDARD1)
            .withCql("SELECT count(*) FROM Standard1 where KEY='A';")
            .execute();

    System.out.println("CQL Count: " + result.getResult().getNumber());
} catch (ConnectionException e) {
}

And it should give you the COUNT result, but I am querying my table with cql3 and it isn't giving me a "Number", but "Rows", only one Row and only one Column.

The method hasNumber gives False and the method hasRows gives True, so now, How can I get the Result of my COUNT query?


Solution

  • You should use

    System.out.println("CQL Count: " + result.getResult().getRows().getRowByIndex(0).getColumns().getColumnByName("count").getLongValue());