【问题标题】:How query cassandra using static column?如何使用静态列查询 cassandra?
【发布时间】:2017-11-23 23:07:30
【问题描述】:

我已将 locationtype 定义为静态列。

我想过滤静态列上的数据。

select count(*) from device_stats_by_location where locationtype = "garage";

但我面临异常 -

InvalidRequest: code=2200 [Invalid query] message="Predicates on non-primary-key columns (locationtype) are not yet supported for non secondary index queries"

如此尝试...

cqlsh:device_data> CREATE INDEX locationtype_indx on device_stats_by_location (locationtype);

产生了错误信息...

InvalidRequest: code=2200 [Invalid query] message="Secondary indexes are not allowed on static columns"

我的问题是 - 如何在 CQL 查询中使用静态列?

【问题讨论】:

  • 你为什么使用静态列?你的用例是什么?
  • 位置类型对于具有相同分区键的所有行都是固定的
  • 数据模型 => locationid(Pk), endof10minwindow (Ck1) , devicecategory (Ck2) , devicecount , locationtype (S) , region (S) => locationid 会有 2000 行聚集在一起,它们将具有相同的 locationtype 和 region => 这就是为什么 将它们指定为静态 => 按 locationtype 查询数据的最佳方法是什么?

标签: cassandra cassandra-2.0 cassandra-3.0


【解决方案1】:

在 Cassandra 中,不能使用静态列过滤数据,不能在静态列上创建索引和物化视图。

您可以使用以下任何解决方案

  • 将静态列更改为常规列并创建索引或物化视图

  • 创建另一个表,并将 locationtype 作为分区键,将 locationid、endof10minwindow、devicecategory 作为集群键。每当您在基表上插入/更新时,也要在此表上插入/更新。现在您可以使用 locationtype 过滤数据。

【讨论】:

    猜你喜欢
    • 2018-04-09
    • 1970-01-01
    • 2016-01-01
    • 2014-03-31
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多