Greater than equals query and LIMIT with Pycassa

56 views
Skip to first unread message

Dan Theirl

unread,
Jun 25, 2013, 10:16:38 AM6/25/13
to pycassa...@googlegroups.com
Hello,

I am having a really hard time finding out the best way to do this CQL query with Pycassa.  I have found a nasty work around with thrift and execute_cql3_query but that's not fun to parse and creates a mess in my code.  Is there a easier pycassa way to do this:

"SELECT * FROM geoIPblock WHERE startIpNum >= 839593873 LIMIT 1"


I am wondering if I should just use python-cql and drop pycassa all together.


Thank you so much in advance!


Dan

Tyler Hobbs

unread,
Jun 25, 2013, 11:57:43 AM6/25/13
to pycassa...@googlegroups.com
It's generally not a good idea to mix cql3 and pycassa.  The only tables that pycassa can interact with through its normal API are cql3 tables that are created WITH COMPACT STORAGE.  (See http://www.datastax.com/dev/blog/cql3-for-cassandra-experts for more details.)

I don't know what your schema is, so I can't suggest how to do something equivalent in pycassa.


--
You received this message because you are subscribed to the Google Groups "pycassa-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycassa-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Tyler Hobbs
DataStax

Dan Theirl

unread,
Jun 25, 2013, 4:11:16 PM6/25/13
to pycassa...@googlegroups.com
Okay thanks Tyler,

Here is my schema:

startIpNum is Primary Key LongType
endIpNum is Secondary Index LongType
locId is IntegerType

column_type Standard
comparator_type UTF8Type
subcomparator_type None
key_validation_class LongType
default_validation_class LongType
gc_grace_seconds 864000

There's a 4-5 million rows, let me know if there is any other information you need.

Thanks,
Dan

Kumar Ranjan

unread,
Mar 7, 2014, 11:08:11 AM3/7/14
to pycassa...@googlegroups.com
Dan,

There is no such thing in Pycassa (MongoDB has something called Criteria where you can specify conditions, based on which results are returned, more like WHERE clause in RDBMS). Its very important piece missing in Pycassa. You would have to do this in your code like I do but then it makes code do tremendous amount of extra work or parsing and throwing unnecessary data and keep what you need. No fun. This has annoyed our team so much so that a decision was made to move to MongoDB.

Hope it helps.
-- K

Tyler Hobbs

unread,
Mar 7, 2014, 2:27:21 PM3/7/14
to pycassa...@googlegroups.com

On Fri, Mar 7, 2014 at 10:08 AM, Kumar Ranjan <winne...@gmail.com> wrote:

There is no such thing in Pycassa (MongoDB has something called Criteria where you can specify conditions, based on which results are returned, more like WHERE clause in RDBMS). Its very important piece missing in Pycassa. You would have to do this in your code like I do but then it makes code do tremendous amount of extra work or parsing and throwing unnecessary data and keep what you need.

For what it's worth, you certainly can do operations like this, although they tend to be clearer in CQL than through the pycassa API (for most users and use cases).  Additionally, data modeling in Cassandra is much different from how you would model your data in a relational database or a document database.  If you try to treat Cassandra like an RDBMS, you're not going to have a fun time.


--
Tyler Hobbs
DataStax

Kumar Ranjan

unread,
Mar 7, 2014, 3:50:44 PM3/7/14
to pycassa...@googlegroups.com
Tyler,

Can you please elaborate on this, 'For what it's worth, you certainly can do operations like this' ? How would you specify criteria (aka where clause) in get, xget or get_range() in pycassa? I understand CQL is the way going forward but dealing with tons of legacy stuff here which uses Pycassa.

Regards,
-- Kumar


--
You received this message because you are subscribed to a topic in the Google Groups "pycassa-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pycassa-discuss/I2xXND9qUE0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pycassa-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tyler Hobbs

unread,
Mar 7, 2014, 7:12:58 PM3/7/14
to pycassa...@googlegroups.com
Your "where clause" tools are effectively specifying the row key(s) and a column slice (or set of column names).  As I said, data modelling is not the same in Cassandra as in an RDBMS or a document store.  You have to model your queries, not your objects and their relationships.  Effectively, you are pre-building support for the "where clauses" you want to support.

I suggest watching some of Patrick's videos here: http://wiki.apache.org/cassandra/DataModel


--
You received this message because you are subscribed to the Google Groups "pycassa-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pycassa-discu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Tyler Hobbs
DataStax

Kumar Ranjan

unread,
Mar 7, 2014, 7:56:39 PM3/7/14
to pycassa...@googlegroups.com, pycassa...@googlegroups.com
I agree and thanks. Will checkout the video.

Sent from Mailbox for iPhone
Reply all
Reply to author
Forward
0 new messages