【问题标题】:Cassandra :[Invalid query] message="PRIMARY KEY column "lng" cannot be restrictedCassandra :[Invalid query] message="PRIMARY KEY 列 "lng" 不能被限制
【发布时间】:2015-01-30 19:21:57
【问题描述】:

在 cqlsh 中执行以下查询时出现错误

查询

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)"

Cassandra 版本

[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;

lng 列似乎有问题。

【问题讨论】:

    标签: cassandra cql


    【解决方案1】:

    你不能有这样的查询。您可以为 where 子句集群键的最后一部分添加 &gt; or &lt;,为前面的键提供 =。例如下面的查询可以正常工作,

    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'
    

    但是两个具有&gt; or &lt; condition 的 where 子句将不起作用。

    【讨论】:

    • 是他们实现相同的任何方式。任何技巧/解决方法。我不想在内存中获取大数据集并对其进行处理。
    【解决方案2】:

    如果我理解正确,您必须对除最后一个以外的所有复合键列使用“=”运算符。最后一个(在您的情况下为 lng)可以使用 '' 进行限制。

    这里是链接:http://www.datastax.com/dev/blog/whats-new-in-cql-3-0

    【讨论】:

    • 我想知道我怎么错过了你提到的链接中如此重要的一行。无论如何,重新阅读链接很有帮助。 +1 链接
    猜你喜欢
    • 2023-03-16
    • 2023-03-15
    • 2015-04-18
    • 2013-10-02
    • 2017-10-18
    • 1970-01-01
    • 2021-09-16
    • 2021-10-04
    • 1970-01-01
    相关资源
    最近更新 更多