Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

nilau.tiw@gmail.com avatar image
nilau.tiw@gmail.com asked ·

Why is it mandatory to add IS NOT NULL condition while creating materialized view?

When we are creating Metalized view, it is mandatory to add is not null condition for new partition key and clustering key. But why we are adding not null condition for partition key from existing table.

I am asking this question because, partition key can never be null.

for example below table name_data

id(Partition Key) name age

Now, If I want to create Metalized of above table (name_data) to get data by age then, I have to write query.

CREATE MATERIALIZED VIEW name_data_view
AS SELECT name, id, age 
FROM name_data
WHERE name IS NOT NULL AND id IS NOT NULL
PRIMARY KEY ((name), id) ;

Why We should need to add not null condition for id column. Id Column was a partition key of existing table, that never be a null.

Just a concern . Can you please clarify ?

materialized views
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

The IS NOT NULL phrase is required to guarantee that only rows with data in the base table are copied to the view.

Don't confuse it with the partition key of the base table being null because that's a completely a different thing. Cheers!

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.