English 中文(简体)
我怎么能够从ctor子身上获得反col的价值?
原标题:How can I get a value of a countercolumn out of cassandra with hector?

Hello I m trying to obtain data from cassandra using hector. There are two ways of doing this.

a) 类似情况:

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();

我在什么地方犯错误?

最佳回答

你的例子不完整,你没有说明失败之处。 但是,从研究你的法典来看,有几处错误:错误的类型、论点,你需要使用具体的反常类型,如果只读一栏,就不需要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());

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>
问题回答

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





相关问题
How does Voldemort compare to Cassandra?

How does Voldemort compare to Cassandra? I m not talking about size of community and only want to hear from people who have actually used both. Especially I m interested in: How they dynamically ...

How does Cassandra rebalance when nodes go down?

Does anyone have experience with Cassandra when nodes go down or are unavailable? I am mostly interested in whether the cluster rebalances and what happens when the nodes come online, or are replaced ...

Cassandra time series data

We are looking at using Cassandra to store a stream of information coming from various sources. One issue we are facing is the best way to query between two dates. For example we will need to ...

Picking a database technology

We re setting out to build an online platform (API, Servers, Data, Wahoo!). For context, imagine that we need to build something like twitter, but with the comments (tweets) organized around a live ...

Row count of a column family in Cassandra

Is there a way to get a row count (key count) of a single column family in Cassandra? get_count can only be used to get the column count. For instance, if I have a column family containing users and ...

Update an existing column value

What happens when a new value for an existing column is added? Will the older value be overwritten by the new value? Or the older value will also retain and can be retrieved (similar to simpleDB)?

Cassandra Vs Amazon SimpleDB

I m working on an application where data size and SQL queries are going to be heavy. I am thinking between Cassandra or Amazon SimpleDB. Can you please suggest which is more suitable in this kind of ...

Cassandra load balancing with an ordered partitioner?

So I see here that Cassandra does not have automatic load balancing, which comes into view when using the ordered partitioner (a certain common range of values of a group of rows would be stored on a ...

热门标签