首页 > 解决方案 > 如何对cassandra数据库中的post表进行分页和排序?

问题描述

我使用 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 放在任何参数之前,那么我不能使用最后一个参数作为过滤器。

标签: cassandracassandra-3.0

解决方案


推荐阅读