Cassandra CQL 3 - Prefix Select

青春壹個敷衍的年華 提交于 2019-12-23 02:59:08

问题


is there a way to perform a select based on a string prefix using CQL3? For example, consider the following table:

Key | Value
------------
ABC | 0x01
ABD | 0x02
BBB | 0x03

I want to select all the keys with the prefix 'AB'. The database will be used to store spacial information, using a geohash approach.


回答1:


That is not possible "out of the box"... However, there are some "tricks" people came up with, see these two posts:

  • Cassandra (Pycassa/CQL) Return Partial Match
  • Is there any query for Cassandra as same as SQL:LIKE Condition?

...another (somehow similar) approach could be to define "composite key", where you define some prefixes as "partition key", e.g.: {key1,key2}, where key1 = ABand key2 = ABC... in these situations you could query by "key1" only and get a set of rows (like you want to do), or by "key1" and "key2" (in case you want a specific entry). You can also query only by "key2" (if you add "allow filtering" to your "select" query, however this can lead to "problems" if you have too many rows). Not sure if you can do this with your data...

HTH.




回答2:


Not built-in in C* but possible with cassandra-lucene-index C* plugin. You can create a lucene index on the column and search the text using prefix search.

UPDATE: Since v3.4 Cassandra introduced SASI indices that offer the required functionality.



来源:https://stackoverflow.com/questions/20602466/cassandra-cql-3-prefix-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!