Nassim MOUALEK
Nassim MOUALEK

Reputation: 4864

Cassandra CQL where clause parentheses

Having this Entity

@Table(keyspace = KEYSPACE)
public class CE_TimeSeries extends Entity implements TimeSeriesPoint{

    @PartitionKey(1)
    private String typeId;
    @ClusteringColumn(value=1, asc=true)
    private String userId;
    @ClusteringColumn(value=2, asc=true)
    private Date startDate;  
    @Column
    private Date endDate;  
    @Column
    private int groupInterval;
    @Column
    private int interval;
}

This CQL

SELECT startDate, endDate, groupInterval, interval FROM CE_TimeSeries WHERE typeId 
= :typeId and userId = :userId and ( endDate >= :fromDate or  ( startDate >= 
:fromDate and   startDate <= :toDate ) )

Give the Exception :

Caused by: com.datastax.driver.core.exceptions.SyntaxError: line 1:142 
mismatched input 'or' expecting ')' (... ( endDate >= :fromDate [or]  (...)

Upvotes: 4

Views: 997

Answers (1)

Aaron
Aaron

Reputation: 57843

While I don't actually see a question here, I'll assume that you are wondering why you are getting an exception. There are two things wrong with your query.

  1. CQL does not allow the use of OR in the WHERE clause.
  2. CQL does not allow parens in the WHERE clause. Plus, not having OR available kind of precludes the need for parens.

The bottom line, is that CQL is not SQL, and the logic you can apply in the WHERE clause is largely dependent on the storage model.

Upvotes: 5

Related Questions