cassandrathrifthector

How to print column values in Mutator before execute?


Below is the code I going to insert into cassandra

Set<String> keys = MY_KEYS;
Map<String, String> pairsOfNameValues = MY_MUTATION_BY_NAME_AND_VALUE;

Set<HColumn<String, String>> colums = new HashSet<HColumn<String,String>>();
for (Entry<String, String> pair : pairsOfNameValues.entrySet()) {
    colums.add(HFactory.createStringColumn(pair.getKey(), pair.getValue()));
}

Mutator<String> mutator = template.createMutator();
String column_family_name = template.getColumnFamily();
for (String key : keys) {
    for (HColumn<String, String> column : colums) {
        mutator.addInsertion(key, BASIC_COLUMN_FAMILY, column);
    }
}
mutator.execute();

There are some cases where I don't know how many columns are inserted into the mutator. Is there any to print the data before/after the execution method.

I tried Mutationresult.tostring(). It gives the following response.

MutationResult took (3750us) for query (n/a) on host: localhost(127.0.0.1):9160

Also Mutator to String didn't give me desired result.

Please help.


Solution

  • Yep, try mutator.getPendingMutationCount() before executing the query.

    Other than that, you'll have to push the logic of counting what columns you are adding to the mutator manually. The toString() doesn't give you what you want as you are supposed to bind the mutator.execute() to a MutationResult. E.g:

    MutationResult mr = mutator.execute();
    

    But the mutation result doesn't give you much more either. You can know these 3 things (2 really...)

    // the execution time
    long getExecutionTimeMicro();
    long getExecutionTimeNano();
    // host used for the exec.
    CassandraHost getHostUsed();