HowTo: Range scan on secondary indexes?

82 views
Skip to first unread message

SunboX

unread,
Nov 14, 2010, 11:56:04 AM11/14/10
to phpcassa
Hi,

i'm using v0.7.0-beta3 and want to do something like this:

$indexExpLatLeft = CassandraUtil::create_index_expression('latitude',
50, cassandra_IndexOperator::GT);
$indexExpLatRight = CassandraUtil::create_index_expression('latitude',
51, cassandra_IndexOperator::LT);
$indexExpLngLeft = CassandraUtil::create_index_expression('longitude',
12, cassandra_IndexOperator::GT);
$indexExpLngRight =
CassandraUtil::create_index_expression('longitude', 13,
cassandra_IndexOperator::LT);

$expressions = array($indexExpLatLeft, $indexExpLatRight,
$indexExpLngLeft, $indexExpLngRight);

$locations = $cf->get_indexed_slices(

CassandraUtil::create_index_clause($expressions)
// ...
);

But i get the error message:

No indexed columns present in index clause with operator EQ


How do i have to perform such a call? thx André

SunboX

unread,
Nov 14, 2010, 11:59:00 AM11/14/10
to phpcassa
more readable demo code is at: https://gist.github.com/676305

Pieter Maes

unread,
Nov 14, 2010, 12:00:47 PM11/14/10
to phpc...@googlegroups.com
What does your storage conf look like?

Op 14/11/10 17:59, SunboX schreef:

>> How do i have to perform such a call? thx Andr�

SunboX

unread,
Nov 14, 2010, 12:06:31 PM11/14/10
to phpcassa
this was a fast response.. ;o)

the conf looks like this:

https://gist.github.com/676307

Pieter Maes

unread,
Nov 14, 2010, 12:34:37 PM11/14/10
to phpc...@googlegroups.com
hm, the error looks straight forward

No indexed columns present in index clause with operator EQ

means that you need an index expression with an EQ operator :)
you only have GT and LT
I'm not sure why this is needed, i'm a bit behind on cassandra (since 0.6)

Op 14/11/10 18:06, SunboX schreef:

SunboX

unread,
Nov 14, 2010, 12:41:30 PM11/14/10
to phpcassa
Hm, yes.. it sounds like i need a eq index. But there isn´t one. :/
Maybe i could build one, but i don´t think that it should be
necessary... :(

Imbuit

unread,
Dec 29, 2010, 7:59:10 AM12/29/10
to phpcassa
I have experienced the same difficulty. The solution is to incorporate
an additional comparison.

$expr = CassandraUtil::create_index_expression ('field1', 1,
cassandra_IndexOperator::EQ);
$expr2 = CassandraUtil::create_index_expression ('field2', 1,
cassandra_IndexOperator::GTE);
$ic = CassandraUtil::create_index_clause (array ($expr, $expr2));
$ics = $cf->get_indexed_slices ($ic, '', '', '',true);

I really do not need expr, but if I not incorporated I get the same
error message.
Would this be correct?.

My additional difficulty is because I do not get the results sorted by
field2, so finally I create a new column family where I can get that
order.

Regards,

Victor.


On 14 nov, 18:41, SunboX <fiedler.an...@googlemail.com> wrote:
> Hm, yes.. it sounds like i need a eq index. But there isn´t one. :/
> Maybe i could build one, but i don´t think that it should be
> necessary... :(
>
> On 14 Nov., 18:34, Pieter Maes <maesc...@gmail.com> wrote:
>
> > hm, the error looks straight forward
>
> > No indexed columns present in index clause with operator EQ
>
> > means that you need an index expression with an EQ operator :)
> > you only have GT and LT
> > I'm not sure why this is needed, i'm a bit behind on cassandra (since 0.6)
>
> > Op 14/11/10 18:06, SunboX schreef:
>
> > > this was a fast response.. ;o)
>
> > > the conf looks like this:
>
> > >https://gist.github.com/676307
>
> > > On 14 Nov., 18:00, Pieter Maes <maesc...@gmail.com> wrote:
> > >> What does your storage conf look like?
>
> > >> Op 14/11/10 17:59, SunboX schreef:
>
> > >>> more readable demo code is at:https://gist.github.com/676305
> > >>> On 14 Nov., 17:56, SunboX <fiedler.an...@googlemail.com> wrote:
> > >>>> Hi,
> > >>>> i'm using v0.7.0-beta3 and want to do something like this:
> > >>>> $indexExpLatLeft = CassandraUtil::create_index_expression('latitude',
> > >>>> 50,cassandra_IndexOperator::GT);
> > >>>> $indexExpLatRight = CassandraUtil::create_index_expression('latitude',
> > >>>> 51,cassandra_IndexOperator::LT);
> > >>>> $indexExpLngLeft = CassandraUtil::create_index_expression('longitude',
> > >>>> 12,cassandra_IndexOperator::GT);

Tyler Hobbs

unread,
Dec 31, 2010, 2:09:21 PM12/31/10
to phpc...@googlegroups.com
Yes, In your case it would probably be easier to build an index yourself.  You would want to use the values of 'field2' as the column names in a row (or set of rows) so that the rows are sorted by that value.

- Tyler
Reply all
Reply to author
Forward
0 new messages