當查詢在卡桑德拉CQL文本主鍵,字符串比較工作的什麼人預期相反的方向,即字符串在卡桑德拉排序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)
在constrast,這是我從字符串比較得到在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分區程序以防萬一。
謝謝你,我很困惑,行似乎是在DESC順序排序,但它看起來像一個純粹的巧合。項目進行的方式我不需要太多的分區,所以我可能會使用有序的分區程序,或者完全使用應用程序級別的排序和比較。 – alexk 2014-09-30 15:14:43
@alexk只是警告,字節順序分區程序已被棄用,應該*不能*被使用。 http://www.datastax.com/documentation/cassandra/2.1/cassandra/architecture/architecturePartitionerBOP_c.html – Aaron 2014-09-30 15:22:05