2016-08-25 80 views
2

有了这个实体卡桑德拉CQL where子句括号

@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; 
} 

这CQL

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

给异常:

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

回答

2

虽然我实际上没有看到一个问题在这里,我假设你想知道你为什么会得到一个例外。您的查询有两个错误。

  1. CQL不允许在WHERE子句中使用OR
  2. CQL不允许在WHERE子句中使用parens。另外,没有OR可用类型排除了对parens的需要。

底线是,CQL不是SQL,您可以在WHERE子句中应用的逻辑在很大程度上取决于存储模型。

+0

没有OR怎么办? –

+0

@NassimMOUALEK构建不依赖于它的使用的查询模型。 – Aaron