【发布时间】:2014-11-25 03:45:18
【问题描述】:
在 Cassandra CQL 中查询文本主键时,字符串比较的工作方式与预期相反,即
cqlsh:test> 从 sl 中选择 *; 姓名 |数据 --------------+------ 000000020000000000000003 |空值 000000010000000000000005 |空值 000000010000000000000003 |空值 000000010000000000000002 |空值 000000010000000000000001 |空值 cqlsh:test> select name from sl where token(name) < token('000000010000000000000005'); 姓名 -------------------------- 000000020000000000000003 (1 行) cqlsh:test> select name from sl where token(name) > token('000000010000000000000005'); 姓名 -------------------------- 000000010000000000000003 000000010000000000000002 000000010000000000000001 (3 行)相比之下,这是我从 Python 中的字符串比较中得到的(我认为在大多数其他语言中):
>>>'000000020000000000000003' < '000000010000000000000005'
False
如果我不使用令牌函数进行查询,则会收到以下错误:
cqlsh:test> 从 sl 中选择名称,其中名称 < '000000010000000000000005'; 错误请求:分区键仅支持 EQ 和 IN 关系(除非您使用 token() 函数)表格说明为:
CREATE TABLE sl (
name text,
data blob,
PRIMARY KEY (name)
) WITH
bloom_filter_fp_chance=0.010000 AND
caching='KEYS_ONLY' AND
comment='' AND
dclocal_read_repair_chance=0.000000 AND
gc_grace_seconds=864000 AND
index_interval=128 AND
read_repair_chance=0.100000 AND
replicate_on_write='true' AND
populate_io_cache_on_flush='false' AND
default_time_to_live=0 AND
speculative_retry='99.0PERCENTILE' AND
memtable_flush_period_in_ms=0 AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'LZ4Compressor'};
在我错过的文档或其他地方是否有解释为什么选择了这样一个奇怪的字符串比较顺序,或者字符串比较运算符是否不符合我的期望(即返回一些不相关的顺序,即写入数据库时的行顺序)。我正在使用 Murmur3Partitioner 分区器以防万一。
【问题讨论】: