读取 cassandra 中的行和反序列化问题
我想从列族中获取所有行并显示所有列。我尝试了这个:
// 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());
}
}
}
问题是,例如,所有具有长值的列都是空的。如果我将最后一个“参数化器”更改为“对象”,则会收到“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)
I'd like to get all rows from a column family and display all columns as well. I tried this one:
// 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 the columns which have long-values for example are empty. If I change the last "parameterizer" to Object, I get a "CorruptedStreamException". How do I have to do this?
UPDATE: this is the output using 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ML的答案:
http://groups.google.com/group/hector-users/browse_thread /thread/8246ad59c9d5cf9d
另外,请看一下新的模板包。它提供了更加明智的键入结果检索。这是使用此类的入门指南:
https://github.com/rantav/hector/wiki/入门-%285-分钟%29
The answer from the ML:
http://groups.google.com/group/hector-users/browse_thread/thread/8246ad59c9d5cf9d
Also, please take a look at the new template package. It provides significantly more sane retrieval of typed results. Here is a getting started guide utilizing such:
https://github.com/rantav/hector/wiki/Getting-started-%285-minutes%29
您是否尝试过使用 byte[] 而不是 Object ?所有 Cassandra 数据项的基础类型都是字节数组。例如,
这是基于对 Web 示例的猜测,因为我使用 Python 客户端而不是 Java...
您也可以尝试省略泛型:
并查看返回的类型(如果有)。
Have you tried using byte[] instead of Object? The underlying type of all Cassandra data items is a byte array. e.g.
This is based on guesswork from web examples, as I use a Python client rather than Java...
You could also try omitting the generics:
and see what types you get back, if any.