spring-data-cassandra
spring-data-cassandra copied to clipboard
Support materialized views [DATACASS-383]
Mark Paluch opened DATACASS-383 and commented
See http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views
5 votes, 9 watchers
Andrew commented
To speed up the process, just wanted to suggest an example of what we implemented in our project.
Define additional views on table entities:
@Table("user")
@MaterializedViews({
@MaterializedView(name="user_by_email", primaryKeyColumns = {
@PrimaryKeyColumn(value = "email", type = PrimaryKeyType.PARTITIONED),
@PrimaryKeyColumn(value = "id")
})
})
Use a query:
@Table("user")
@MaterializedViews({
@MaterializedView(name="user_by_email",
query="SELECT * FROM user WHERE email IS NOT NULL AND id IS NOT NULL",
primaryKeyColumns = {
@PrimaryKeyColumn(value = "email", type = PrimaryKeyType.PARTITIONED),
@PrimaryKeyColumn(value = "id")
})
})
Plus added schema specs and generation/drop extending
CassandraPersistentEntitySchemaCreator and CassandraSessionFactoryBean. Works fine so far.
Mark Paluch commented
It makes sense to start out with CQL generation and view descriptors in the first place. I'm not entirely sold on annotation-based schema creation. The query part allows more than just NOT NULL predicates. Stating queries that way is error-prone and functionality can be only verified when using schema creation.
Using views requires our CassandraTemplate methods to also accept a table name
Nate McCall commented
We have retro-actively marked Materialized Views as experimental. In order to keep users from hitting any of the (numerous) issues, I am asking that you avoid creating any implementations here until we can iron out the functionality. http://mail-archives.apache.org/mod_mbox/cassandra-user/201710.mbox/%[email protected]%3E