2014-12-02 56 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