【问题标题】:Double range query in CassandraCassandra中的双范围查询
【发布时间】:2012-05-07 09:54:56
【问题描述】:

我想执行一个双范围查询以获得一个点附近的纬度和经度点,

现在在 Cassandra 中似乎可行,我刚刚尝试过

create column family users
 with comparator=UTF8Type
 AND key_validation_class=UTF8Type
 and column_metadata=[{column_name: full_name, validation_class: UTF8Type},
 {column_name: type, validation_class: UTF8Type, index_type: KEYS},
 {column_name: lat, validation_class: LongType, index_type: KEYS},
 {column_name: lon, validation_class:  LongType, index_type: KEYS}];

SET users['a']['type']='test';                                             
SET users['b']['type']='test';
SET users['c']['type']='test';
SET users['a']['lat']='12';                                                
SET users['b']['lat']='9'; 
SET users['c']['lat']='12';
SET users['b']['lon']='1'; 
SET users['a']['lon']='4';
SET users['c']['lon']='2';
get users where type = 'test' and lon < '6' and lon > '3' and lat > '10' and lat < '13';

行键:一个 =>(列=纬度,值=12,时间戳=1336339056413000) =>(列=lon,值=4,时间戳=1336339088170000) =>(列=类型,值=测试,时间戳=1336339033765000)

返回 1 行。

但是我很担心添加数千点时的性能,如果这 3 列被索引。

1) 我必须使用索引的“类型”列,因为没有它,查询会失败

No indexed columns present in index clause with operator EQ

可以绕过吗?

2) 自然地按纬度或经度对所有数据进行排序可能会很有趣,然后只查询另一个,

所以只需对 x 和 y 之间的 lat 进行 SliceQuery,然后进行查询

get users where type = 'test' and lon < '6' and lon > '3';

不按行名而是按另一个字段(例如:字符串 lat+lon 和 UTF8 比较器)对 CF 进行排序,如何做到这一点?

谢谢

【问题讨论】:

  • 澄清可能是一个重要的初步误解:这些都不是 CQL。您正在使用 cassandra-cli 工具的特殊语法。

标签: cassandra cql


【解决方案1】:

您的解决方案可能适用于较小的数据集。一旦它增长,您需要一些空间索引来执行快速查找。 Cassandra 目前不支持空间索引。我建议你看看 GeoCell / GeoHash

您为每个点坐标创建哈希,然后您可以对字符串执行范围查询。在这种情况下,Cassandra 范围查询将是一个不错的选择。

GeoHash是一种分层空间数据结构,将空间细分为网格形状的桶。

链接:

【讨论】:

    【解决方案2】:

    是的,就像 vladaman 所说,Cassandra geocells 是(唯一?)好方法,在 PythonJava

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 2015-03-10
      • 2013-08-14
      • 2012-03-13
      • 2015-08-18
      • 2015-06-06
      • 1970-01-01
      相关资源
      最近更新 更多