Search in sources :

Example 1 with Rows

use of me.prettyprint.hector.api.beans.Rows in project cassandra-tutorial by zznate.

the class TutorialRunner method printResults.

@SuppressWarnings("unchecked")
private static void printResults(ResultStatus result) {
    log.info("+-------------------------------------------------");
    log.info("| Result executed in: {} microseconds against host: {}", result.getExecutionTimeMicro(), result.getHostUsed().getName());
    log.info("+-------------------------------------------------");
    // nicer display of Rows vs. HColumn or ColumnSlice
    if (result instanceof QueryResult) {
        System.out.println(((QueryResult) result).get());
        QueryResult<?> qr = (QueryResult) result;
        if (qr.get() instanceof Rows) {
            Rows<?, ?, ?> rows = (Rows) qr.get();
            for (Row row : rows) {
                log.info("| Row key: {}", row.getKey());
                for (Iterator iter = row.getColumnSlice().getColumns().iterator(); iter.hasNext(); ) {
                    log.info("|   col: {}", iter.next());
                }
            }
        } else if (qr.get() instanceof ColumnSlice) {
            for (Iterator iter = ((ColumnSlice) qr.get()).getColumns().iterator(); iter.hasNext(); ) {
                log.info("|   col: {}", iter.next());
            }
        } else {
            log.info("| Result: {}", qr.get());
        }
    }
    log.info("+-------------------------------------------------");
}
Also used : QueryResult(me.prettyprint.hector.api.query.QueryResult) ColumnSlice(me.prettyprint.hector.api.beans.ColumnSlice) Iterator(java.util.Iterator) Row(me.prettyprint.hector.api.beans.Row) Rows(me.prettyprint.hector.api.beans.Rows)

Aggregations

Iterator (java.util.Iterator)1 ColumnSlice (me.prettyprint.hector.api.beans.ColumnSlice)1 Row (me.prettyprint.hector.api.beans.Row)1 Rows (me.prettyprint.hector.api.beans.Rows)1 QueryResult (me.prettyprint.hector.api.query.QueryResult)1