如何在cassandra数据库中的post表上进行分页和排序?

时间:2018-08-17 16:29:06

标签: cassandra cassandra-3.0

我正在使用cassandra v3.0作为数据库

我的餐桌计划如下:

`CREATE TABLE db_name.post (
    postcreatedby timeuuid,
    contenttype text,
    createdat bigint,
    friendid timeuuid,
    posttype text,
    id timeuuid,
    PRIMARY KEY (postcreatedby, contenttype, createdat, friendid, posttype, id)
) WITH CLUSTERING ORDER BY (contenttype ASC, createdat ASC, friendid ASC, posttype ASC, id ASC)
    AND bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry`enter code here` = '99PERCENTILE';`

我正在尝试运行以下查询:

SELECT * from post WHERE postcreatedby = timeuuid  AND contenttype IN ('text', 'text') AND createdat < bigint AND friendid = timeuuid  AND posttype = 'text';

并出现以下错误:

InvalidRequest:来自服务器的错误:code = 2200 [Invalid query] message =“不能限制群集列“ friendid”(之前的列“ createdat”受非EQ关系限制)”

我的问题是:

我需要使用所有列来过滤数据,并且还需要对其进行排序。在这里,我使用'createdAt'参数来保持排序和分页。

我的问题是,如果我将createdAt设置为最后一个集群键,那么我也可以使用所有列进行过滤,但无法对该数据进行排序。而且,如果我将createdAt放在任何参数之前,那么我将不能使用最后一个参数作为过滤器。

0 个答案:

没有答案