2014-12-02 19 views
1

我正在同時執行以下查詢在cqlsh卡桑德拉:[無效查詢]消息=「PRIMARY KEY列 」LNG「 不能被限制

查詢錯誤

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat > 100.00 and lat < 120.00 and lng > 50 and lng < 100 allow filtering; 

CREATE TABLE ragchews.disc_location (
    country_code int, 
    lat float, 
    lng float, 
    uid text, 
    PRIMARY KEY (country_code, lat, lng, uid) 
); 

錯誤:

code=2200 [Invalid query] message="PRIMARY KEY column "lng" cannot be restricted (preceding column "ColumnDefinition{name=lat, type=org.apache.cassandra.db.marshal.FloatType, kind=CLUSTERING_COLUMN, componentIndex=0, indexName=null, indexType=null}" is either not restricted or by a non-EQ relation)" 

卡桑德拉版本

[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3] 

編輯1

下面的查詢工作正常,我

SELECT * FROM ragchews.disc_location WHERE country_code=91 and lat > 32 and lat < 100 allow filtering; 

這看起來像什麼是錯與列。

回答

3

你不能有這樣的查詢。您可以將> or <添加到您的where子句羣集密鑰的最後部分,爲前面的鍵提供=。例如,下面的查詢將正常工作,

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat = 100.00 and lng > 50 and lng < 100; 

甚至下面的工作,

SELECT * FROM ragchews.disc_location WHERE country_code = 12 AND lat = 100.00 and lng = 50 and uid > '500' and uid < '1000' 

但有兩個where子句中有> or < condition將不會工作。

+0

是他們的任何方式來實現相同。任何技巧/解決方法。我不想將大數據集放入內存並處理它。 – guptakvgaurav 2014-12-02 14:43:03

2

如果我理解了這個權利,那麼除了最後一個之外,您必須對所有組合鍵列使用'='運算符。最後一個(在你的案例lng)可以用'<'或'>'來限制。

下面的鏈接:http://www.datastax.com/dev/blog/whats-new-in-cql-3-0

+0

我想知道我是如何錯過你提到的鏈接中的這種重要的行。任何方式重讀鏈接都很有幫助。鏈接爲+1 – guptakvgaurav 2014-12-02 14:59:01

+0

歡迎您! :) – leshkin 2014-12-02 15:47:05