I'm a newbie in cassandra and I have an issue with "sort".
我是cassandra的新手,我有一个“排序”的问题。
My table is very simple, It like that:
我的表很简单,就像那样:
CREATE TABLE test.user_daily_report (
stringdate bigint,
m_date date,
users int,
PRIMARY KEY (stringdate, m_date)
) WITH CLUSTERING ORDER BY (m_date DESC)
AND read_repair_chance = 0.0
AND dclocal_read_repair_chance = 0.1
AND gc_grace_seconds = 864000
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 default_time_to_live = 0
AND speculative_retry = '99PERCENTILE'
AND min_index_interval = 128
AND max_index_interval = 2048
AND crc_check_chance = 1.0;
But the result not have any effect of sort:
但结果没有任何排序的影响:
When I try to order by m_date i meet this issue:
当我尝试通过m_date订购时,我遇到了这个问题:
Please help me, It makes me confuse a lot.
请帮帮我,这让我很困惑。
Thanks
1 个解决方案
#1
2
In contrast to traditional relational database, in Cassandra ORDER BY
works only inside partition - when you specify the WHERE
condition on partition key (stringdate
in your example), i.e., select * from table where stringdate = 'something' order by m_date desc
- in this case data related to particular stringdate
will be sorted because they are in the same partition.
与传统的关系数据库相比,在Cassandra中,ORDER BY仅在分区内部工作 - 当您在分区键上指定WHERE条件时(在您的示例中为stringdate),即,从表中选择*,其中stringdate ='something'顺序由m_date desc - in在这种情况下,与特定stringdate相关的数据将被排序,因为它们位于同一分区中。
In your case, you're receiving all results from Cassandra because you added 'ALLOW FILTERING' - in this case, Cassandra performs scanning of the whole cluster using your condition, fetches data, and returns it to you - but it didn't perform any sorting.
在您的情况下,您收到了Cassandra的所有结果,因为您添加了“允许过滤” - 在这种情况下,Cassandra使用您的条件执行整个群集的扫描,获取数据并将其返回给您 - 但它没有执行任何排序。
I recommend to watch "DS220: Data Modeling" course from DataStax Academy - they provide a lot of useful information...
我建议从DataStax Academy观看“DS220:数据建模”课程 - 它们提供了许多有用的信息......
P.S. Can you describe what task do you want to solve? I believe that you need to change data model.
附:你能描述一下你想要解决的任务吗?我相信你需要改变数据模型。
#1
2
In contrast to traditional relational database, in Cassandra ORDER BY
works only inside partition - when you specify the WHERE
condition on partition key (stringdate
in your example), i.e., select * from table where stringdate = 'something' order by m_date desc
- in this case data related to particular stringdate
will be sorted because they are in the same partition.
与传统的关系数据库相比,在Cassandra中,ORDER BY仅在分区内部工作 - 当您在分区键上指定WHERE条件时(在您的示例中为stringdate),即,从表中选择*,其中stringdate ='something'顺序由m_date desc - in在这种情况下,与特定stringdate相关的数据将被排序,因为它们位于同一分区中。
In your case, you're receiving all results from Cassandra because you added 'ALLOW FILTERING' - in this case, Cassandra performs scanning of the whole cluster using your condition, fetches data, and returns it to you - but it didn't perform any sorting.
在您的情况下,您收到了Cassandra的所有结果,因为您添加了“允许过滤” - 在这种情况下,Cassandra使用您的条件执行整个群集的扫描,获取数据并将其返回给您 - 但它没有执行任何排序。
I recommend to watch "DS220: Data Modeling" course from DataStax Academy - they provide a lot of useful information...
我建议从DataStax Academy观看“DS220:数据建模”课程 - 它们提供了许多有用的信息......
P.S. Can you describe what task do you want to solve? I believe that you need to change data model.
附:你能描述一下你想要解决的任务吗?我相信你需要改变数据模型。