如何从 cassandra 和 hector 中获取反列的值?

发布于 2024-12-13 03:42:16 字数 965 浏览 0 评论 0原文

您好,我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

亣腦蒛氧 2024-12-20 03:42:16

你的例子不完整,你没有指出什么是失败的。但从你的代码来看,有一些错误:类型、参数不正确,你需要使用特定的 Counter 类型,如果只是获取单个列,则不需要 Slice。这个例子应该有效:

CounterQuery<String, String> query = HFactory.createCounterColumnQuery(keyspace, stringSerializer,stringSerializer);
query.setColumnFamily("page_view_counts").setKey("localhost").setName("home");
HCounterColumn<String> counter = query.execute().get();
System.out.println("Count:" + counter.getValue());

如果您确实需要一个 Slice,那么从 HFactory.createSliceCounterSliceQuery() 返回的结果将

QueryResult<CounterSlice<String>>

包含以下列表:

HCounterColumn<String>

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:

CounterQuery<String, String> query = HFactory.createCounterColumnQuery(keyspace, stringSerializer,stringSerializer);
query.setColumnFamily("page_view_counts").setKey("localhost").setName("home");
HCounterColumn<String> counter = query.execute().get();
System.out.println("Count:" + counter.getValue());

If you do need a Slice, then the result returned from HFactory.createSliceCounterSliceQuery() will be

QueryResult<CounterSlice<String>>

which will contain the List of

HCounterColumn<String>
混吃等死 2024-12-20 03:42:16

使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文