如何从 cassandra 和 hector 中获取反列的值?
您好,我正在尝试使用 hector 从 cassandra 获取数据。 有两种方法可以做到这一点。
一个是像这样的 cqlQuery:
CqlQuery<String, String, Long> cqlQuery = new CqlQuery<String, String, Long>(connect.tutorialKeyspace, stringSerializer, stringSerializer, longSerializer);
cqlQuery.setQuery("select home from page_view_counts where KEY ="localhost");
QueryResult<CqlRows<String, String, Long>> result;
try
{
result = cqlQuery.execute();
}
catch(HectorException e){
result = null;
message = e.getMessage();
}
如果没有查询,它应该是这样的,但我无法让它工作:
SliceQuery<String, String, Long> query = HFactory.createSliceQuery(connect.tutorialKeyspace, stringSerializer,stringSerializer,longSerializer);
QueryResult<ColumnSlice<String, Long>> result2 = query.setColumnFamily("page_view_counts").setKey("localhost").setColumnNames("home").execute();
我在哪里犯了错误?
Hello I'm trying to obtain data from cassandra using hector.
There are two ways of doing this.
one is with a cqlQuery like this:
CqlQuery<String, String, Long> cqlQuery = new CqlQuery<String, String, Long>(connect.tutorialKeyspace, stringSerializer, stringSerializer, longSerializer);
cqlQuery.setQuery("select home from page_view_counts where KEY ="localhost");
QueryResult<CqlRows<String, String, Long>> result;
try
{
result = cqlQuery.execute();
}
catch(HectorException e){
result = null;
message = e.getMessage();
}
And without queries it should be something like this, but I can't get it to work:
SliceQuery<String, String, Long> query = HFactory.createSliceQuery(connect.tutorialKeyspace, stringSerializer,stringSerializer,longSerializer);
QueryResult<ColumnSlice<String, Long>> result2 = query.setColumnFamily("page_view_counts").setKey("localhost").setColumnNames("home").execute();
Where do I make the mistake?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的例子不完整,你没有指出什么是失败的。但从你的代码来看,有一些错误:类型、参数不正确,你需要使用特定的 Counter 类型,如果只是获取单个列,则不需要 Slice。这个例子应该有效:
如果您确实需要一个 Slice,那么从 HFactory.createSliceCounterSliceQuery() 返回的结果将
包含以下列表:
Your examples are incomplete, you give no indication of what is failing. But from looking at your code, there are a few things wrong: incorrect types, arguments, you need to use specific Counter types, and if just getting a single column then don't need Slice. This example should work:
If you do need a Slice, then the result returned from HFactory.createSliceCounterSliceQuery() will be
which will contain the List of
使用 ColumnFamilyTemplate API 可能是轻松入门的最佳方式。请参阅:http://rantav.github.com/hector/build/html /content/getting_started.html(上面提到的部分或hector-client.org)。
Using the ColumnFamilyTemplate API might be the best way to get started easily. See: http://rantav.github.com/hector/build/html/content/getting_started.html (part or hector-client.org mentioned above).