我正在尝试重新构建一个SQL数据库Cassandra,以便我可以找到与SQL查询等效的Cassandra.我使用CQL 3和Cassandra v1.2.我在cassandra中对db设计进行了建模,以便它支持子句和非规范化表的顺序以支持连接操作.但是,当谈到DISTINCT,SUM()和GROUPBY等价时,我在海上
SELECT a1,MAX(b1) FROM demo1 group by a1.
SELECT DISTINCT (a2) FROM demo2 where b2='sea'
SELECT sum(a3), sum(b3) from demo3 where c3='water' and d3='ocean'
Run Code Online (Sandbox Code Playgroud)
在过去的几天里,这就像我的工作一样.在Cassandra中有没有办法,我可以建模db模式来支持这类查询?我无法想象卡桑德拉的任何方式.如何使用Cassandra实现此类查询?
我读到Cassandra上的hive层可能会使这些查询起作用.我只是想知道这是否是在Cassandra中支持此类查询的唯一方法..?请建议任何其他可能的方法..
我有一个表/列系列,我插入的行在一定时间后过期.是否可以查询表以检查哪些行即将过期(出于诊断目的,即:
select subject, ?ttl? from discussions;
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的tabe:
CREATE TABLE test (
"type" varchar,
"value" varchar,
PRIMARY KEY(type,value)
);
Run Code Online (Sandbox Code Playgroud)
我在其中插入了5行:
INSERT INTO test(type,value) VALUES('test','tag1')
INSERT INTO test(type,value) VALUES('test','tag2')
INSERT INTO test(type,value) VALUES('test','tag3')
INSERT INTO test(type,value) VALUES('test','tag4')
INSERT INTO test(type,value) VALUES('test','tag5')
Run Code Online (Sandbox Code Playgroud)
我跑了SELECT * from test LIMIT 3,它按预期工作.
type | value
------+------
test | tag1
test | tag2
test | tag3
Run Code Online (Sandbox Code Playgroud)
当我跑SELECT COUNT(*) from test LIMIT 3,它产生:
count
-------
5
Run Code Online (Sandbox Code Playgroud)
不应该说3吗?
该Datastax文件似乎表明,指定LIMIT将覆盖10000默认值.为什么在这种情况下不起作用?如果重要的话,我在Cassandra 2.2.5上并通过cqlsh运行所有查询.
更新
Java驱动程序和CQLSH都经过测试,表明LIMIT确实无法按照文档中的规定运行.如果有任何Datastax员工阅读,您的意见将非常感谢.
我正在尝试创建一个20,000多列的WIDE列表
最初我以为我会用:
CREATE TABLE details (
key TEXT,
detail map<TEXT, TEXT>
PRIMARY KEY (KEY)
);
Run Code Online (Sandbox Code Playgroud)
插入此表工作正常
UPDATE details SET detail = detail + { 'col1': '12'} where key='123' ;
UPDATE details SET detail = detail + { 'col20000': 'ABCD'} where key='123' ;
Run Code Online (Sandbox Code Playgroud)
但是,我想阅读一个单独的细节:
select detail[col1] where key='123'
Run Code Online (Sandbox Code Playgroud)
执行此查询时,我收到以下错误:
no viable alternative at input '['
Run Code Online (Sandbox Code Playgroud)
这会起作用吗,还是我需要一种不同的方法?
我在CQL下面的表格 -
create table test (
employee_id text,
employee_name text,
value text,
last_modified_date timeuuid,
primary key (employee_id)
);
Run Code Online (Sandbox Code Playgroud)
我在上表中插入了几条记录,我将在实际用例场景中插入这些记录 -
insert into test (employee_id, employee_name, value, last_modified_date) values ('1', 'e27', 'some_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('2', 'e27', 'some_new_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('3', 'e27', 'some_again_value', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('4', 'e28', 'some_values', now());
insert into test (employee_id, employee_name, value, last_modified_date) values ('5', 'e28', 'some_new_values', now()); …Run Code Online (Sandbox Code Playgroud) 我创建了一个表用户如下:
create table users (user_id text primary key, email text, first_name text, last_name text, session_token int);
Run Code Online (Sandbox Code Playgroud)
我指的是DataStax网站上的CQL帮助文档.
我现在想将电子邮件列重命名为"电子邮件".但是当我执行命令时 -
alter table users rename email to emails;
Run Code Online (Sandbox Code Playgroud)
我收到错误 - 错误请求:无法重命名非主要部分电子邮件
我正在使用CQL 3.我的CQLSH是3.1.6,C*是1.2.8.
为什么我不能重命名上面的专栏?如果我运行help alter table,它会显示重命名列的选项.如何重命名列?
如何在cassandra数据库中创建第一个用户?
我试过了:
CREATE USER username WITH PASSWORD "";
Run Code Online (Sandbox Code Playgroud)
它说:
Bad Request: Only superusers are allowed to perform CREATE USER queries
Run Code Online (Sandbox Code Playgroud)
但是我在尝试之前从未创建过用户,那么如何在cassandra数据库中创建第一个用户呢?
这看起来有点奇怪,因为它就像鸡和蛋的问题,但人们使用Cassandra,所以我相信某处必须有解决方案.
我试图从这里运行以下示例
CREATE TYPE address (
street text,
city text,
zip int
);
CREATE TABLE user_profiles (
login text PRIMARY KEY,
first_name text,
last_name text,
email text,
addresses map<text, address>
);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试创建user_profiles表时,我收到以下错误:
InvalidRequest: code=2200 [Invalid query] message="Non-frozen collections are not
allowed inside collections: map<text, address>
Run Code Online (Sandbox Code Playgroud)
有关为什么会发生这种情况的任何想法?
也许这是一个愚蠢的问题,但我无法确定Cassandra中桌子的大小.
这是我试过的:
select count(*) from articles;
如果表很小,它可以正常工作但是一旦它填满,我总是会遇到超时问题:
cqlsh:
DBeaver:
我认为它会达到一些超时并且只是中止.表中的实际条目数可能要高得多.
我正在测试一个完全空闲的本地Cassandra实例.我不介意它是否必须进行全表扫描并且在此期间没有响应.
有没有办法可靠地计算Cassandra表中的条目数?
我正在使用Cassandra 2.1.13.
当我尝试使用以下查询在Cassandra中插入数据时,我收到下面提到的错误
cqlsh:assign> insert into tblFiles1(rec_no,clientid,contenttype,datafiles,filename) values(1,2,'gd','dgfsdg','aww');
Run Code Online (Sandbox Code Playgroud)
WriteTimeout:code = 1100 [协调器节点超时等待副本节点的响应] message ="操作超时 - 仅收到0个响应".info = {'received_responses':0,'required_responses':1,'一致':'ONE'}
我的版本Cassandra和DSE:
[cqlsh 5.0.1 | 卡桑德拉2.1.5.469 | DSE 4.7.0 | CQL规范3.2.0 | Native protoco l v3]