cassandra - 如何对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 放在任何参数之前,那么我不能使用最后一个参数作为过滤器。
解决方案
推荐阅读
- mysql - 恢复使用 --no-create-info 创建的 mysqldump 并希望跳过当前数据库中不存在的表
- django - 返回查询集时如何仅计算()特定字段上的不同值
- node.js - Node.js TCP 客户端使用“net”包与远程服务器通信
- google-apps-script - 单击按钮后需要警报确认操作已执行
- c++ - 错误:由于要求 '!is_signed,static_assert 失败
::value' "" static_assert((!is_signed<_Tp>::value), ""); - javascript - 如何访问flutter web IFrameElement?
- python - 在 Python 中将数据打印为数组
- azure-devops-server-2020 - Azure DevOps 项目附件
- javascript - 如何在 PHP 和 Javascript Web 应用程序的打印对话框中禁用“另存为”选项。如果打印机已连接且未下载,则应出现该对话框
- css - 如何在选择器 CSS 中为某个元素设置特殊样式