gpt4 book ai didi

java - 读取 cassandra 中的行和反序列化问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:17 26 4
gpt4 key购买 nike

我想从列族中获取所有行并显示所有列。我试过这个:

// 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)

最佳答案

ML的回答: http://groups.google.com/group/hector-users/browse_thread/thread/8246ad59c9d5cf9d

另外,请看一下新的模板包。它提供了更加理智的类型化结果检索。这是一个使用这样的入门指南: https://github.com/rantav/hector/wiki/Getting-started-%285-minutes%29

关于java - 读取 cassandra 中的行和反序列化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6390154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com