我创建了2个键空间:
CREATE KEYSPACE test1 WITH replication = {'class': 'SimpleStrategy', 'replicatio n_factor': '3'}
CREATE KEYSPACE test2 WITH replication = {'class': 'SimpleStrategy', 'replicatio n_factor': '3'}
在test1上创建了表用户
CREATE TABLE test1.users (
user_name varchar ,
password varchar,
id varchar,
primary key(user_name,id)
);
在test2上创建物化视图
CREATE MATERIALIZED VIEW test2.user_by_id AS
SELECT * FROM test1.users where id is not null and user_name is not null
PRIMARY KEY (id,user_name);
得到错误:
InvalidRequest:来自服务器的错误:代码= 2200 [无效查询]消息=“未配置的表用户”
CREATE MATERIALIZED VIEW test1.user_by_id AS
SELECT * FROM test1.users where id is not null and user_name is not null
PRIMARY KEY (id,user_name);
工作得很好 .
根据 Cassandra 的文件,这应该有效 .
https://docs.datastax.com/en/cql/3.3/cql/cql_reference/refCreateMV.html
“要在当前键空间以外的键空间中创建物化视图,请将键空间名称放在物化视图名称的前面,然后是句点”
检查它在Cassandra 3.0和3.9 - 相同的问题 .
我使用cqlsh从cassandra节点连接 .
test1.users可以从test2访问:
cqlsh:test2> select * from test1.users;
user_name | id | password
-----------+----+----------
(0行)
我想念一些东西吗?
谢谢
阿龙
1 回答
The table and the Materialized view must be in a same keyspace.
你误解了文档 .
如果当前键空间与表的键空间不同,则必须将表的键空间名称放在实例化视图名称的前面,然后是句点 . 物化视图将在表的键空间中创建