incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Malone <m...@simplegeo.com>
Subject Re: How to write WHERE .. LIKE query ?
Date Tue, 11 May 2010 05:36:04 GMT
On Mon, May 10, 2010 at 9:00 PM, Shuge Lee <shuge.lee@gmail.com> wrote:

> Hi all:
>
> How to write WHERE ... LIKE query ?
> For examples(described in Python):
>
> Schema:
>
> # columnfamily name
> resources = [
>    # key
>     'foo': {
>         # columns and value
>         'url': 'foo.com',
>         'pushlier': 'foo',
>     },
>     'oof': {
>         'url': 'oof.com',
>         'pushlier': 'off',
>     },
>    #  ... ,
> }
>
> # this is very easy,
> SELECT * FROM KEY = 'foo'
>
> but following are really hard:
> SELECT * FROM resources WHERE key LIKE 'o%' # get all records which key
> name contains character 'o'?
>

get_range_slices(<keyspace>, ColumnParent(column_family),
SlicePredicate(slice_range=SliceRange('',''), KeyRange('o', 'o~'),
ConsistencyLevel.ONE);


> SELECT * FROM resources WHERE url == 'oof.com'
>

This is a projection. Cassandra doesn't support this sort of query out of
the box. You'll have to structure your data so that data you want to query
by is in the key or column name. Or you'll have to manually build secondary
indexes.

Mike

Mime
View raw message