2016-08-25 79 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