【问题标题】:Why does Cassandra provides this error when using GROUP BY clause为什么 Cassandra 在使用 GROUP BY 子句时会提供此错误
【发布时间】:2020-03-03 05:52:44
【问题描述】:

遇到错误

当我执行以下 GROUP BY 子句时:

SELECT month, title, country, director, sum(sum_taps), avg(viewing) FROM taps GROUP BY month, title, country, director;

我检索到以下错误

SyntaxException: <Error from server: code=2000 [Syntax error in CQL query] message="line 1:78 no viable alternative at input 'GROUP' (...), avg(viewing) FROM [taps] GROUP...)">

表是如何创建的

表的创建方式如下:

CREATE TABLE taps (Month text, Title text, Country text, Director text, Viewing float, sum_taps float, PRIMARY KEY (Month,Title,Country,Director));

数据是从包含六列的 CSV 文件导入的:月份、标题、导演、国家/地区、查看百分比和总查看次数。 我提供的名称与列名不匹配,因此更易于理解。此文件与给定月份为某些客户购买的电影有关。我们必须对观看统计数据进行分析。

表格说明

描述表格输出:

CREATE TABLE assignment.taps (
    month text,
    title text,
    country text,
    director text,
    sum_taps float,
    viewing float,
    PRIMARY KEY (month, title, country, director)
) WITH CLUSTERING ORDER BY (title ASC, country ASC, director 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 = '99PERCENTILE';

关于我可能做错了什么有什么想法吗?

提前致谢

【问题讨论】:

  • 这能回答你的问题吗? MAX(), DISTINCT and group by in Cassandra
  • 我创建了您上面的表格,并尝试了您的查询。它应该工作。您使用的是哪个版本的 Cassandra?看来您可能需要使用 Cassandra 3.10 或更高版本。
  • 你好@JimWartnick 我可以承认问题是你所建议的。我将 Cassandra 更新到 3.11 并且它工作正常。非常感谢!
  • 我已将我的评论复制到“答案”中,以便其他人也可以看到答案。

标签: cassandra grouping


【解决方案1】:

我创建了您上面的表格,并尝试了您的查询。它应该工作。您使用的是哪个版本的 Cassandra?看来您可能需要使用 Cassandra 3.10 或更高版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 2013-04-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-17
    • 2011-09-25
    相关资源
    最近更新 更多