(Quick Reference)

4 Querying and Persistence Options - Reference Documentation

Authors: Paras Lakhani

Version: 5.0.8.RELEASE

Table of Contents

4 Querying and Persistence Options

The GORM for Cassandra plugin supports passing various options to Cassandra when querying or persisting.

4.1 Querying Options

Limiting results

Using the max parameter, you can specify that the query return a limited number of rows. Example:
def people = Person.list(max:2)

Note that Cassandra does not support the offset parameter, so you cannot page results this way.

Fetch Size

Setting the fetch size, or number of rows returned simultaneously by a select query, is typically needed when queries return extremely large numbers of rows. To do this you can use the fetchSize argument:

def people = Person.list([fetchSize: 200])
people = Person.findAllByFirstName("Barney", [fetchSize: 200])

Setting the fetch size to small values is discouraged as it will yield very poor performance.

In some cases you may want or have to disable paging entirely, for example when using order by and IN, in which case set the fetchSize to Integer.MAX_VALUE. Example:

People.createCriteria().list {
    'in' "lastName", ["Flintstone", "Rubble"]
    order "name"
    fetchSize Integer.MAX_VALUE
}

Allow filtering

When you attempt a potentially expensive query Cassandra may throw an exception mentioning ALLOW FILTERING. To run the query, you can use the allowFiltering argument which is passed onto Cassandra. Imposing a limit using the max parameter is recommended to reduce memory used.

Example:

def people = Person.findAllByFirstNameAndAgeLessThanEquals('Barney', 35, [allowFiltering:true, max:5])
def person = Person.findOrSaveWhere(firstName: 'Rubble', age: 35, [allowFiltering:true, flush:true])
def criteria = Person.createCriteria()  
people = criteria.list (allowFiltering:true, max:5) {
            and {
                eq('firstName', 'Fred')
                eq('age', 40)
            }
         }  
people = criteria.list {
            projections {
                eq('firstName', 'Bob')
                between("age", 40, 43)                   
            }
            allowFiltering true
            max 5    
         }