Cassandra Apache 查询 [英] Cassandra Apache query

查看:22
本文介绍了Cassandra Apache 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 cassandra 中的表格有问题.以下是我所做的:

I have a problems with a table in cassandra. Below is what I did:

CREATE KEYSPACE tfm WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1 };

我在一台机器上工作.

CREATE TABLE tfm.foehis(hocpny 文本、hocol 文本、honumr 文本、holinh 文本、hodtto 文本、hotour 文本、hoclic 文本、hooe 文本、hotpac 文本、hodtac 文本、hohrac 文本、hodesf 文本、hocdan 文本,hocdrs 文字,hocdsl 文字,hoobs 文字,hotdsc 文字,honrac 文字,holinr 文字,housca 文字,hodtea 文字,hohrea 文字,housea 文字,hodtcl 文字,hohrcl 文字,houscl 文字,hodtrc 文字,hohrrc 文字,housrc 文字,hodtra文本,hohrra 文本,housra 文本,hodtcm 文本,hohrcm 文本,houscm 文本,hodtua 文本,hohrua 文本,houser 文本, PRIMARY KEY((hooe,hodtac,hohrac),hoclic));

到目前为止一切正常.但是当我尝试执行一些选择查询时,我收到警告和错误:

Until this point everything is OK. But when I try to do some select queries, I get warnings and errors:

cqlsh>从 tfm.foehis 中选择 count(*);

计数

-------

56980

(1 行)

警告:没有分区键的聚合查询

读取 100 个活动行和 1055 个墓碑单元以查询 SELECT * FROM tfm.foehis LIMIT 100(参见 tombstone_warn_threshold)

读取 100 个活动行和 1066 个墓碑单元以查询 SELECT * FROM tfm.foehis WHERE token(hooe, hodtac, hohrac) >= token(1045161613, 20180502, 2304) LIMIT toresstone_hold_n(见 100)代码>

Read 100 live rows and 1066 tombstone cells for query SELECT * FROM tfm.foehis WHERE token(hooe, hodtac, hohrac) >= token(1045161613, 20180502, 2304) LIMIT 100 (see tombstone_warn_threshold)

cqlsh>select count(*) from tfm.foehis where hoclic=1011;

InvalidRequest:来自服务器的错误:code=2200 [Invalid query] message=针对hoclic"的无效整数常量(1011);文本类型"

cqlsh>select count(*) from tfm.foehis where hotpac=ANOE;

SyntaxException:第 1:49 行在输入 ';' 处没有可行的替代方案(...来自 tfm.foehis,其中 hotpac=[ANOE];)

我认为问题出在表的定义上,但我不知道问题出在哪里.

I supposed that the problems is in the definition of table, but I don't know where the problems is.

推荐答案

实际上您的问题在于查询.由于您的所有列都是文本,因此您需要在值周围使用简单的引号.

Actually your issue is in the queries. Since all your columns are text you need to use simple quotes around values.

此外,根据您的表定义,分区键由 hooe、hodtac、hohrac 列组成,这意味着您的所有查询都必须包含具有精确值 (=) 的此列.hoclic 将是聚类列,在这一列上您将能够使用其他运算符和排序.

Also, according to your table definition, the partition key is formed by hooe,hodtac,hohrac columns which means that all your queries must include this columns with exact values (=). hoclic will be the clustering column and on this one you will be able to use other operators and ordering.

另外,请记住,在 Cassandra 中不推荐在没有分区键的情况下运行查询(如您的选择),因为这会触发完整的集群扫描,并且您可能会遇到各种问题(例如,垃圾收集问题).

Also, have in mind that running queries without the partition key is not recommended in Cassandra (like your select) since this will trigger a full cluster scan and you can run in all sorts of problems (for instance, garbage collection issues).

我会推荐一些基本的阅读:https://www.datastax.com/dev/blog/the-most-important-thing-to-know-in-cassandra-data-modeling-the-primary-键https://docs.datastax.com/en/cql/3.3/index.html

I would recommend some basic reading: https://www.datastax.com/dev/blog/the-most-important-thing-to-know-in-cassandra-data-modeling-the-primary-key and https://docs.datastax.com/en/cql/3.3/index.html

这篇关于Cassandra Apache 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆