datastax - 在 cassandra 中选择不同计数的方法是什么?
问题描述
我需要在 cassandra 的表中选择不同的计数。
据我了解,cassandra 不支持直接不同的计数,甚至不支持像 rdbms 这样的嵌套查询。
select count(*) from (select distinct key_part_one from stackoverflow_composite) as count;
SyntaxException:第 1:21 行在输入 '(' 处没有可行的替代方案 (select count(*) from [(]...)
有什么方法可以得到。我是否可以直接从 cassandra 获取或需要使用任何插件工具/语言?
下面是我的创建表语句。
CREATE TABLE nishant_ana.ais_profile_table (
profile_key text,
profile_id text,
last_update_day date,
last_transaction_timestamp timestamp,
last_update_insertion_timestamp timeuuid,
profile_data blob,
PRIMARY KEY ((profile_key, profile_id), last_update_day)
) WITH CLUSTERING ORDER BY (last_update_day DESC)
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 = '99PERCENTILE';
我刚刚开始使用 cassandra。
解决方案
在 Cassandra 中,您只能执行select distinct partition_key from ...
.
如果你需要这样的东西,你可以使用 Spark + Spark Cassandra 连接器——它会工作,但不要指望真正的实时答案,因为它需要从所有节点读取必要的数据,然后计算答案。
推荐阅读
- java - 当我尝试对来自控制台 (Java) 的输入进行标记时,为什么会收到 ArrayIndexOutOfBoundsException?
- ansible - Ansible playbook 中允许分配多少个标签?
- windows - Godot - 游戏“可执行文件”找不到资源
- c# - 使用 Automapper 创建记录时出错
- jquery - 在 Razor 页面上转义特殊 JSON 字符,以便 JSON.parse 可以与日期恢复器一起使用
- java - 多线程奇怪的行为
- python - 使用免费赠款,我每月大约可以执行多少次此 Azure 功能?
- c# - 如何使用特定的派生类反序列化对象的属性
- javascript - SuiteScript - removeLine 不删除最后一行
- python - 大于 x 时将数据框中的值替换为 nan?