首页 文章

Cassandra CQL中的字符串排序

提问于
浏览
2

在Cassandra CQL中查询文本主键时,字符串比较与预期的方式相反,即

cqlsh:test> select * from sl;

 name                     | data
--------------------------+------
 000000020000000000000003 | null
 000000010000000000000005 | null
 000000010000000000000003 | null
 000000010000000000000002 | null
 000000010000000000000001 | null

cqlsh:test> select name from sl where token(name) < token('000000010000000000000005');
name
--------------------------
 000000020000000000000003

(1 rows)

cqlsh:test> select name from sl where token(name) > token('000000010000000000000005');
 name
--------------------------
 000000010000000000000003
 000000010000000000000002
 000000010000000000000001

(3 rows)

相比之下,这是我从Python中的字符串比较中获得的(我认为在大多数其他语言中):

>>>'000000020000000000000003' < '000000010000000000000005'
False

如果我在没有令牌功能的情况下查询,则会收到以下错误:

cqlsh:test> select name from sl where name < '000000010000000000000005';
Bad Request: Only EQ and IN relation are supported on the partition key (unless you use the token() function)

表格描述如下:

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分区程序以防万一 .

2 回答

相关问题