Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

InvalidRequestException(why:Too many bytes for comparator)

DZone's Guide to

InvalidRequestException(why:Too many bytes for comparator)

· Database Zone
Free Resource

Check out the IT Market Clock report for recommendations on how to consolidate and replace legacy databases. Brought to you in partnership with MariaDB.

In the spirit of trying to save people time, I thought I would directly address the numerous "Too many bytes" errors that bubble up out of Astyanax when using Composites, especially when trying to perform range queries.

First, see my last two posts about connecting the dots:
http://brianoneill.blogspot.com/2012/09/composite-keys-connecting-dots-between.html
http://brianoneill.blogspot.com/2012/10/cql-astyanax-and-compoundcomposite-keys.html

After that, you'll probably still have issues.  If you see a "Too many bytes for comparator" it most likely means that you have a mistmatch between your PRIMARY KEY declaration in your CQL CREATE TABLE statement, and the composite you are using in Astyanax.

You have to be really careful that all of the components in the primary key are declared in your class *in order* and that all fields in your class are part of your primary key.  Otherwise, when Cassandra goes to compare two column keys/names, it will generate the bytes for that column name (from all the components) and it will end up with too many or too few.  (Hence the error you are seeing)

If you have too many, there is a good chance that you have a field declared in your annotated composite class, that is not part of your primary key declaration.

Hopefully that helps.  If you want the underlying theory/reasoning, see:
http://www.datastax.com/dev/blog/cql3-for-cassandra-experts

If it still takes you a while to get sorted out, accessing a CQL table from a thrift-based client, no worries... you are in good company:
http://stackoverflow.com/questions/12360067/invalidrequestexceptionwhytoo-many-bytes-for-comparator-on-execute-query-to-c

 

Interested in reducing database costs by moving from Oracle Enterprise to open source subscription?  Read the total cost of ownership (TCO) analysis. Brought to you in partnership with MariaDB.

Topics:

Published at DZone with permission of Brian O' Neill, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}