Reputation: 57
I am storing file data. I read the file though java and when ever i am storing the file data in cassandra it gives me this error.
Exception in thread "main" com.datastax.driver.core.exceptions.SyntaxError: line 1:115 no viable alternative at input 'PRIMARY' (...* from sensorkeyspace.sensortable WHERE [PRIMARY]...)
Here my query is here
CREATE MATERIALIZED VIEW IF NOT EXISTS sensorkeyspace.texttable AS select * from sensorkeyspace.sensortable WHERE PRIMARY KEY (sensor_id) IS NOT NULL
Upvotes: 2
Views: 406
Reputation: 57748
Try altering your WHERE clause to this:
WHERE sensor_id IS NOT NULL PRIMARY KEY (sensor_id)
If you get an error indicating that:
No columns are defined for Materialized View other than primary key
Based on CASSANDRA-13564:
That error message implies you re-used only the partition key/primary key from the base as the partition key for your view (you had no extra clustering columns in your base primary key).
I get that message when I have a table with a simple PRIMARY KEY, and I try to create a view with that same, simple PRIMARY KEY.
For example, if I have this table:
CREATE TABLE stackoverflow.newtable (
name text PRIMARY KEY,
score float,
value float,
value2 blob);
This fails:
cassdba@cqlsh:stackoverflow> CREATE MATERIALIZED VIEW IF NOT EXISTS
stackoverflow.newtable_view AS SELECT * FROM stackoverflow.newtable
WHERE name IS NOT NULL PRIMARY KEY (name);
InvalidRequest: Error from server: code=2200 [Invalid query]
message="No columns are defined for Materialized View other than primary key"
But this works for the same table:
cassdba@cqlsh:stackoverflow> CREATE MATERIALIZED VIEW IF NOT EXISTS
stackoverflow.newtable_view AS SELECT * FROM stackoverflow.newtable
WHERE score IS NOT NULL AND name IS NOT NULL PRIMARY KEY (score,name);
Warnings :
Materialized views are experimental and are not recommended for production use.
Not really related, but do note that last part; about how using MVs in Cassandra really isn't a good idea, yet.
Upvotes: 1