在 Cassandra 中按 timeuuid 类型的主键排序

标签 sorting cassandra

我是 Cassandra 的新手。我想根据主键(即 timeuuid)获得排序的结果集。我的表结构是。

CREATE TABLE user_session
(
  session_id timeuuid,
  ip inet,
  device_type int,
  is_active int,
  last_access_time timestamp,
  logout_reason text,
  logout_type int,
  start_time timestamp,  
  uid int,
  PRIMARY KEY(session_id)
);

谁能帮帮我。

最佳答案

您不能在主列的查询中使用 order by。它仅在集群列上受支持。您必须更改此表才能执行此类查询。它可能看起来像这样:

CREATE TABLE user_session
(
user_id int,
session_id timeuuid,
ip inet,
device_type int,
is_active int,
last_access_time timestamp,
logout_reason text,
logout_type int,
start_time timestamp,  
uid int,
PRIMARY KEY(user_id, session_id)
);

然后,您的查询将如下所示:

select * from user_session where user_id=5 order by session_id ASC;

基本上,您需要一些主键,用于搜索仅允许EQIN 关系的数据,因此您不能有user_id > 5 或类似的东西,然后您可以通过在您的情况下为 session_id 的聚类列对结果进行排序。

卓然

关于在 Cassandra 中按 timeuuid 类型的主键排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31217129/

相关文章:

cassandra - 如何在 cassandra 中永久设置一致性级别?

cassandra - 在 CQL 中对分区键和(聚集键或索引列)使用 IN 运算符

apache-flex - 对 AdvancedDatagrid 中的分组列进行排序

java - NoNodeAvailableException : No node was available to execute the query

Python Cassandra 驱动程序仅插入一条记录

unix - gnu 排序中的 --general-numeric-sort 和 --numeric-sort 选项有什么区别

kubernetes - 使用 kubectl 补丁将卷添加到 Kubernetes StatefulSet

linux - 按同一行中引用的次数对文本中的单词进行排序

java - Scala如何将 "None"排序到底部(如果存在)并选择每组中的第一行?

R:按字母和数字顺序对包含字符和数值的字符串向量进行排序