Cassandra 取回整行
我正在用一个非常简单的例子来尝试 Cassandra。 我在 cassandra 数据库中存储了一个列族:
[default@Hotelier] list Hotel;
Using default limit of 100
-------------------
RowKey: AZS_011
=> (column=name, value=43616d6272696120537569746573, timestamp=527682928555011)
上面的值实际上是“Cambria Suites”。当我使用以下代码从数据库检索值时:
String key = "AZS_011";
Connector connector = new Connector();
Cassandra.Client client = connector.connect();
ColumnPath cp = new ColumnPath("Hotel");
cp.setColumn(to_bb("name"));
ColumnOrSuperColumn col = client.get(to_bb(key), cp, CL);
String hotel_name = new String(col.column.value.array(), UTF8);
System.out.println("I found: " + hotel_name);
connector.close();
我最终得到输出: 我发现:?getname坎布里亚套房酒店 ??乙?
看来通过引用 col.column.value,我已经得到了整行中的所有内容。我的问题是如何只获取没有名称和时间戳部分的值?多谢。
I'm trying Cassandra with a very simple example.
I have a column family stored in the cassandra database:
[default@Hotelier] list Hotel;
Using default limit of 100
-------------------
RowKey: AZS_011
=> (column=name, value=43616d6272696120537569746573, timestamp=527682928555011)
The value above is actually "Cambria Suites". And when I use the following code to retrieve the value from the database:
String key = "AZS_011";
Connector connector = new Connector();
Cassandra.Client client = connector.connect();
ColumnPath cp = new ColumnPath("Hotel");
cp.setColumn(to_bb("name"));
ColumnOrSuperColumn col = client.get(to_bb(key), cp, CL);
String hotel_name = new String(col.column.value.array(), UTF8);
System.out.println("I found: " + hotel_name);
connector.close();
I end up with the output:
I found: ?getnameCambria Suites
??B?
It seems that by referring to col.column.value, I have got everything within the whole row. My question is how can I only get the value without the name and timestamp part? Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下方式获取每一列。我让方法获取如下值:
Use following way to get each column. I made method get the values as below: