3
votes

I created 2 keyspaces :

CREATE KEYSPACE test1 WITH replication = {'class': 'SimpleStrategy', 'replicatio                                                                                                             n_factor': '3'} 

CREATE KEYSPACE test2 WITH replication = {'class': 'SimpleStrategy', 'replicatio                                                                                                             n_factor': '3'} 

Created table users on test1

CREATE TABLE test1.users (
  user_name varchar ,
  password varchar,
  id varchar,
  primary key(user_name,id)
);

create Materialized view on 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);

Get error :

InvalidRequest: Error from server: code=2200 [Invalid query] 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);

Works Good .

According to Cassandra documenation this should work .

https://docs.datastax.com/en/cql/3.3/cql/cql_reference/refCreateMV.html

"To create a materialized view in a keyspace other than the current keyspace, put the keyspace name in front of the materialized view name, followed by a period"

Checked it On Cassandra 3.0 and 3.9 - same issue .

I connect from cassandra node using cqlsh.

test1.users is accessible from test2:

cqlsh:test2> select * from test1.users;

 user_name | id | password
-----------+----+----------

(0 rows)

Do I miss something .

Thanks

Alon

1

1 Answers

3
votes

The table and the Materialized view must be in a same keyspace.
You misunderstood the documentation.

To create a materialized view in a keyspace other than the current keyspace, put the keyspace name in front of the materialized view name, followed by a period.

If your current keyspace is not same as table's keyspace then you have to put the table's keyspace name in front of the materialized view name, followed by a period. Materialized view will be created in the table's keyspace