You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by Yuhan Zhang <yz...@onescreen.com> on 2012/06/19 21:23:37 UTC

cassandra secondary index with

Hi all,

I'm trying to search by the secondary index of cassandra with "greater than
or equal". but reached an exception stating:
me.prettyprint.hector.api.exceptions.HInvalidRequestException:
InvalidRequestException(why:No indexed columns present in index clause with
operator EQ)

However, the same column family with the same column, work when the search
expression is an "equal". I'm using the Hector java client.
The secondary index type has been set to: {column_name: sport,
validation_class: DoubleType, index_type:KEYS }

here's the code reaching the exception:

public QueryResult<OrderedRows<String, String, Double>>
getIndexedSlicesGTE(String columnFamily, String columnName, double value,
String... columns) {
        Keyspace keyspace = getKeyspace();
        StringSerializer se = CassandraStorage.getStringExtractor();

        IndexedSlicesQuery<String, String, Double> indexedSlicesQuery =
createIndexedSlicesQuery(keyspace, se, se, DoubleSerializer.get());
        indexedSlicesQuery.setColumnFamily(columnFamily);
        indexedSlicesQuery.setStartKey("");
        if(columns != null)
            indexedSlicesQuery.setColumnNames(columns);
        else {
            indexedSlicesQuery.setRange("", "", true, MAX_RECORD_NUMBER);
        }
        indexedSlicesQuery.setRowCount(CassandraStorage.MAX_RECORD_NUMBER);
        indexedSlicesQuery.addGteExpression(columnName, value);
// this doesn't work :(
        //indexedSlicesQuery.addEqualsExpression(columnName, value);    //
this works!
        QueryResult<OrderedRows<String, String, Double>> result =
indexedSlicesQuery.execute();

        return result;
    }


Is there any column_meta setting that is required in order to make GTE
comparison works on secondary index?

Thank you.

Yuhan Zhang

Re: cassandra secondary index with

Posted by Yuhan Zhang <yz...@onescreen.com>.
Hi Jonathan, thanks for the reference. will read up on it.

Yuhan

Re: cassandra secondary index with

Posted by Jonathan Ellis <jb...@gmail.com>.
That this will get you *worse* performance than just doing a seq scan would.

Details as to why this is, are here:
http://www.datastax.com/dev/blog/whats-new-cassandra-07-secondary-indexes

On Tue, Jun 19, 2012 at 2:48 PM, Yuhan Zhang <yz...@onescreen.com> wrote:
> To anwser my own question:
>
> There should be at least on "equal" expression in the indexed query to
> combine with a "gte".
> so, I just added an trivial column that stays constant for equal comparison.
> and it works.
>
> not sure why this requirement exists.
>
> Thank you.
>
> Yuhan
>
>
> On Tue, Jun 19, 2012 at 12:23 PM, Yuhan Zhang <yz...@onescreen.com> wrote:
>>
>> Hi all,
>>
>> I'm trying to search by the secondary index of cassandra with "greater
>> than or equal". but reached an exception stating:
>> me.prettyprint.hector.api.exceptions.HInvalidRequestException:
>> InvalidRequestException(why:No indexed columns present in index clause with
>> operator EQ)
>>
>> However, the same column family with the same column, work when the search
>> expression is an "equal". I'm using the Hector java client.
>> The secondary index type has been set to: {column_name: sport,
>> validation_class: DoubleType, index_type:KEYS }
>>
>> here's the code reaching the exception:
>>
>> public QueryResult<OrderedRows<String, String, Double>>
>> getIndexedSlicesGTE(String columnFamily, String columnName, double value,
>> String... columns) {
>>         Keyspace keyspace = getKeyspace();
>>         StringSerializer se = CassandraStorage.getStringExtractor();
>>
>>         IndexedSlicesQuery<String, String, Double> indexedSlicesQuery =
>> createIndexedSlicesQuery(keyspace, se, se, DoubleSerializer.get());
>>         indexedSlicesQuery.setColumnFamily(columnFamily);
>>         indexedSlicesQuery.setStartKey("");
>>         if(columns != null)
>>             indexedSlicesQuery.setColumnNames(columns);
>>         else {
>>             indexedSlicesQuery.setRange("", "", true, MAX_RECORD_NUMBER);
>>         }
>>
>> indexedSlicesQuery.setRowCount(CassandraStorage.MAX_RECORD_NUMBER);
>>         indexedSlicesQuery.addGteExpression(columnName, value);
>> // this doesn't work :(
>>         //indexedSlicesQuery.addEqualsExpression(columnName, value);    //
>> this works!
>>         QueryResult<OrderedRows<String, String, Double>> result =
>> indexedSlicesQuery.execute();
>>
>>         return result;
>>     }
>>
>>
>> Is there any column_meta setting that is required in order to make GTE
>> comparison works on secondary index?
>>
>> Thank you.
>>
>> Yuhan Zhang
>>
>>
>>
>
>
>
> --
> Yuhan Zhang
> Application Developer
> OneScreen Inc.
> yzhang@onescreen.com
> www.onescreen.com
>
> The information contained in this e-mail is for the exclusive use of the
> intended recipient(s) and may be confidential, proprietary, and/or legally
> privileged. Inadvertent disclosure of this message does not constitute a
> waiver of any privilege.  If you receive this message in error, please do
> not directly or indirectly print, copy, retransmit, disseminate, or
> otherwise use the information. In addition, please delete this e-mail and
> all copies and notify the sender.



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of DataStax, the source for professional Cassandra support
http://www.datastax.com

Re: cassandra secondary index with

Posted by Yuhan Zhang <yz...@onescreen.com>.
To anwser my own question:

There should be at least on "equal" expression in the indexed query to
combine with a "gte".
so, I just added an trivial column that stays constant for equal
comparison. and it works.

not sure why this requirement exists.

Thank you.

Yuhan

On Tue, Jun 19, 2012 at 12:23 PM, Yuhan Zhang <yz...@onescreen.com> wrote:

> Hi all,
>
> I'm trying to search by the secondary index of cassandra with "greater
> than or equal". but reached an exception stating:
> me.prettyprint.hector.api.exceptions.HInvalidRequestException:
> InvalidRequestException(why:No indexed columns present in index clause with
> operator EQ)
>
> However, the same column family with the same column, work when the search
> expression is an "equal". I'm using the Hector java client.
> The secondary index type has been set to: {column_name: sport,
> validation_class: DoubleType, index_type:KEYS }
>
> here's the code reaching the exception:
>
> public QueryResult<OrderedRows<String, String, Double>>
> getIndexedSlicesGTE(String columnFamily, String columnName, double value,
> String... columns) {
>         Keyspace keyspace = getKeyspace();
>         StringSerializer se = CassandraStorage.getStringExtractor();
>
>         IndexedSlicesQuery<String, String, Double> indexedSlicesQuery =
> createIndexedSlicesQuery(keyspace, se, se, DoubleSerializer.get());
>         indexedSlicesQuery.setColumnFamily(columnFamily);
>         indexedSlicesQuery.setStartKey("");
>         if(columns != null)
>             indexedSlicesQuery.setColumnNames(columns);
>         else {
>             indexedSlicesQuery.setRange("", "", true, MAX_RECORD_NUMBER);
>         }
>         indexedSlicesQuery.setRowCount(CassandraStorage.MAX_RECORD_NUMBER);
>         indexedSlicesQuery.addGteExpression(columnName, value);
> // this doesn't work :(
>         //indexedSlicesQuery.addEqualsExpression(columnName, value);    //
> this works!
>         QueryResult<OrderedRows<String, String, Double>> result =
> indexedSlicesQuery.execute();
>
>         return result;
>     }
>
>
> Is there any column_meta setting that is required in order to make GTE
> comparison works on secondary index?
>
> Thank you.
>
> Yuhan Zhang
>
>
>
>


-- 
Yuhan Zhang
Application Developer
OneScreen Inc.
yzhang@onescreen.com <eh...@onescreen.com>
www.onescreen.com

The information contained in this e-mail is for the exclusive use of the
intended recipient(s) and may be confidential, proprietary, and/or legally
privileged. Inadvertent disclosure of this message does not constitute a
waiver of any privilege.  If you receive this message in error, please do
not directly or indirectly print, copy, retransmit, disseminate, or
otherwise use the information. In addition, please delete this e-mail and
all copies and notify the sender.