2017-06-21 107 views
0

我已经将定位类型定义为一个静态列。如何查询cassandra使用静态列?

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

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查询中使用静态列?

+1

为什么使用静态列?你的用例是什么? –

+0

locationtype对于所有具有相同分区键的行都是固定的 –

+0

DataType => ** locationid(Pk),endof10minwindow(Ck1),devicecategory(Ck2),devicecount,locationtype(S),region(S)** => for一个给定的位置ID将有2000行聚集在一起,它们将具有相同的位置类型和区域=>多数民众赞成为什么**指定它们为静态** =>什么是通过位置类型查询数据的最佳方法? –

回答

1

在Cassandra中,您无法使用静态列过滤数据,也无法在静态列上创建索引和实例化视图。

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

  • 改变静态列专栏,并创建索引或物化视图

  • 创建另一个表,使的locationType作为分区键和locationid,endof10minwindow,devicecategory作为集群密钥。无论何时在基表上插入/更新,也在此表上插入/更新。现在您可以使用locationtype过滤数据。