Reading lines in cassandra and the problem of de-serialization

I would like to get all rows from a column family and display all columns. I tried this:

// Static import of HFactory!

// First, insert the data
Mutator<String> mutator = HFactory.createMutator(fKeyspace, fStringS);
mutator.insert("fahrer1", "Fahrer", createStringColumn("first", "John"));
mutator.insert("fahrer2", "Fahrer", createStringColumn("first", "Vorname"));
mutator.insert("fahrer2", "Fahrer", createStringColumn("second", "Nachname"));
mutator.
    addInsertion("fahrer3", "Fahrer",
            createColumn("first", "Firstname", fStringS,
                    fStringS)).
    addInsertion("fahrer3", "Fahrer",
            createColumn("second", "Lastname", fStringS,
                    fStringS)).
    addInsertion("fahrer3", "Fahrer",
            createColumn("age", 29L, fStringS, fLongS))
    .execute();

// Now select..
CqlQuery<String, String, String> cqlQuery =
   new CqlQuery<String, String, String>(fKeyspace,fStringS,fStringS,fStringS);
cqlQuery.setQuery("SELECT * FROM ColumnFamily");

QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();

CqlRows<String, String, String> rows = result.get();
for (Row<String, String, String> row : rows.getList()) {
    System.out.println(row.getKey() + ":");
    for(HColumn<String, Object>col : row.getColumnSlice().getColumns()) {
        System.out.println(col.getName() + " : " + col.getValue());
        }
    }
}

The problem is that all columns with long values, for example, are empty. If I change the last "parameterizer" to Object, I get a "CorruptedStreamException". How should I do it?

UPDATE: this is the result using the CLI

[default@Autorennen] list Fahrer;
Using default limit of 100
-------------------
RowKey: fahrer1
=> (column=first, value=John, timestamp=1308392358211000)
-------------------
RowKey: fahrer2
=> (column=first, value=SecondUpdated, timestamp=1308392358350000)
=> (column=second, value=584e6163686e616d65, timestamp=1308392358284000)
-------------------
RowKey: fahrer3
=> (column=age, value=000000000000001d, timestamp=1308392358286002)
=> (column=first, value=Firstname, timestamp=1308392358286000)
=> (column=second, value=4c6173746e616d65, timestamp=1308392358286001)
+3
source share
2 answers

Have you tried using byte [] instead of Object? The basic type of all Cassandra data elements is an array of bytes. eg.

QueryResult<CqlRows<String, String, byte[]>>

This is based on guesswork from web examples, since I'm using a Python client, not Java ...

You can also try to abandon generics:

CqlResult result = executeQuery("select * from ColumnFamily");
for (CqlRow row : result.getRows()) {
    System.out.println(new String (row.getKey()));
}

, , .

+1

All Articles