我创建了2个键空间:
CREATE KEYSPACE test1 WITH replication = {'class': 'SimpleStrategy', 'replicatio n_factor': '3'}
CREATE KEYSPACE test2 WITH replication = {'class': 'SimpleStrategy', 'replicatio n_factor': '3'}
CREATE TABLE test1.users (
user_name varchar ,
password varchar,
id varchar,
primary key(user_name,id)
);
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:服务器出错:code = 2200 [查询无效] message =“unconfigured table users”
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行)
我错过了什么。
由于
阿龙
答案 0 :(得分:3)
表格和物化视图必须位于相同的键空间中。
你误解了文档。
要在当前键空间以外的键空间中创建物化视图,请将键空间名称放在物化视图名称的前面,然后是句点。
如果您当前的键空间与表的键空间不同,则必须将表的键空间名称放在实例化视图名称的前面,然后是句点。 物化视图将在表的键空间中创建