我想从列系列中获取所有行并显示所有列。我试过这个:
// 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());
}
}
}
问题是,所有具有long值的列都是空的。如果我将最后一个“参数化器”更改为Object,则会出现“CorruptedStreamException”。我该怎么做?
更新:这是使用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)
答案 0 :(得分:4)
ML的答案: http://groups.google.com/group/hector-users/browse_thread/thread/8246ad59c9d5cf9d
另外,请查看新模板包。它提供了更加理智的类型结果检索。这是一个使用这样的入门指南: https://github.com/rantav/hector/wiki/Getting-started-%285-minutes%29
答案 1 :(得分:1)
您是否尝试使用byte []而不是Object?所有Cassandra数据项的基础类型是字节数组。 e.g。
QueryResult<CqlRows<String, String, byte[]>>
这是基于Web示例的猜测,因为我使用的是Python客户端而不是Java ...
您也可以尝试省略泛型:
CqlResult result = executeQuery("select * from ColumnFamily");
for (CqlRow row : result.getRows()) {
System.out.println(new String (row.getKey()));
}
并查看您获得的类型,如果有的话。