cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amila Paranawithana <amila1...@gmail.com>
Subject Re: Creating counter columns in cassandra
Date Sat, 28 Jul 2012 18:44:31 GMT
Thanks Tamar and all.. :)
Since I want to do queries like SELECT * FROM counters WHERE
CounterColumnName>1; I want to index my counter columns, and I use the
following code. But I get the following error
Exception in thread "main"
me.prettyprint.hector.api.exceptions.HInvalidRequestException:
InvalidRequestException(why:No indexed columns present in by-columns clause
with "equals" operator)

void indexColumn(String idxColumnName,String CountercfName){

        Cluster cluster = HFactory.getOrCreateCluster(
BasicConf.CASSANDRA_CLUSTER, BasicConf.CLUSTER_PORT);
        KeyspaceDefinition keyspaceDefinition =
cluster.describeKeyspace(BasicConf.KEYSPACE);

        List<ColumnFamilyDefinition> cdfs = keyspaceDefinition.getCfDefs();
        ColumnFamilyDefinition cfd = null;
        for(ColumnFamilyDefinition c:cdfs){
        if(c.getName().toString().equals(CountercfName)) {
        System.out.println(c.getName());
        cfd=c;
        break;
        }
        }

        BasicColumnFamilyDefinition columnFamilyDefinition = new
BasicColumnFamilyDefinition(cfd);

        BasicColumnDefinition bcdf = new BasicColumnDefinition();
        bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName));
        bcdf.setIndexName(idxColumnName+"index");
        bcdf.setIndexType(ColumnIndexType.KEYS);
        bcdf.setValidationClass(ComparatorType.COUNTERTYPE.getClassName());

        columnFamilyDefinition.addColumnDefinition(bcdf);
        cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));

}


On Thu, Jul 26, 2012 at 7:06 PM, Vivek Mishra <mishra.vivs@gmail.com> wrote:

> Check out Kundera for Counter column support. Here is the link for Counter
> column tests:
>
>
> https://github.com/impetus-opensource/Kundera/tree/kundera-2.0.7/kundera-cassandra/src/test/java/com/impetus/client/crud/countercolumns
>
>
> -Vivek
>
>
> On Thu, Jul 26, 2012 at 12:27 PM, Abhijit Chanda <
> abhijit.chanda0@gmail.com> wrote:
>
>> You can check Astyanax API
>>
>> https://github.com/Netflix/astyanax/blob/5c05d118e22eef541a7a201adf7c1c610da13f5b/src/test/java/com/netflix/astyanax/thrift/ThrifeKeyspaceImplTest.java
>> There are some counter column example which will surely help you.
>>
>
>


-- 
Amila Iroshani Paranawithana
CSE-University of Moratuwa.
B-http://amilaparanawithana.blogspot.com
T-https://twitter.com/#!/AmilaPara

Mime
View raw message