melli-182
melli-182

Reputation: 1234

Create Cassandra @Query for one or more @Params

I am trying to perform a SELECT on a cassandra database, using the datastax driver on a Java App.

I already developed simple queries as:

@Repository
public class CustomTaskRepository
    extends AbstractCassandraRepository<CustomTask> {

    @Accessor
    interface ProfileAccessor {
        @Query("SELECT * FROM tasks where status = :status")
        Result<CustomTask> getByStatus(@Param("status") String status);
    }

    public List<CustomTask> getByStatus(String status) {
        ProfileAccessor accessor = this.mappingManager.createAccessor(ProfileAccessor.class);
        Result<CustomTask> tasks = accessor.getByStatus(status);
        return tasks.all();
    }
}

Thats works great.

The problem I have now is that I want to execute a SELECT statement for more than one status. For example I would like to execute the query for one, two ... or more status codes (Pending, Working, Finalized,etc).

How could I create a @Query Statement with the flexibility of accepting one or more Status codes?

Thanks in advance!!!

EDIT: The table create statement is:

CREATE TABLE tasks(
"reservation_id" varchar,
"task_id" UUID,
"status" varchar,
"asignee" varchar,
PRIMARY KEY((reservation_id),task_id)
)

WITH compaction = {'class': 'org.apache.cassandra.db.compaction.LeveledCompactionStrategy'} ;


CREATE INDEX taskid_index ON tasks( task_id );
CREATE INDEX asignee_index ON tasks( asignee );

Upvotes: 1

Views: 568

Answers (1)

Marko Švaljek
Marko Švaljek

Reputation: 2101

Try using IN instead of = . If this is partitioning key you will get the rows that you need out. Also note that it might cause performance degradation if there are a lot of statuses in in.

Upvotes: 2

Related Questions