Map Cassandra Materialized View with DSE's Java API
Asked Answered
T

2

8

I have a cassandra table with an associated materialized view.

The primary key is a single id of type uuid, and I have no sort key. Let's call it my_table_id. This table contains a related_id that I want to use to search.

Then I have a materialized view for that table defined as

PRIMARY KEY (related_id, my_table_id) WITH CLUSTERING ORDER BY (my_table_id ASC)

PS: I realise it's the wrong way to partition data in Cassandra, but unfortunately, this code was inherited.

I'm defining my table in my java code as:

@Table(table = "my_table")
public class MyTableType {
    @PartitionKey
    @Column("my_table_id")
    @Codec(MyIdCassandraConverter.class)
    CustomUUIDType myTableId;

    @Column("related_id")
    @Codec(MyRelatedIdCassandraConverter.class)
    MyRelatedId relatedId;

   (...)
}

Those two custom types are simply wrappers around UUIDs. Again, inherited.

My materialized view is defined as:

@MaterializedView(baseEntity = MyTableType.class, view = "my_table_by_related_id")
public class MyTableTypeByRelatedId {
    @PartitionKey
    @Column("related_id")
    @Codec(MyRelatedIdCassandraConverter.class)
    MyRelatedId relatedId;

    @ClusteringColumn
    @Column("my_table_id")
    @Codec(MyIdCassandraConverter.class)
    CustomUUIDType myTableId;
}

The code seems to be generated correctly, but when I start my Spring Boot application, I get:

Error:java: Cannot find base entity class 'mypackage.MyTableType' for view class 'mypackage.MyTableTypeByRelatedId' Error:java: Error while parsing: Cannot find base entity class 'mypackage.MyTableType' for view class 'mypackage.MyTableTypeByRelatedId'

There's some code generation going on, so it seems to be something's not generated correctly, but I can't quite figure out what.

The only mildly useful documentation I find is here and here, but none seems to offer help.

What am I doing wrong?

Thanksgiving answered 4/9, 2018 at 8:42 Comment(0)
T
1

Well, not much of an answer, because this was not much of a question, but someone having a similar problem might find it useful.

This specific problem was caused because I was looking at the wrong database, which of course didn't have the tables and views I created. I had a property override file I thought was set correctly, and that was my mistake.

Thanksgiving answered 5/9, 2018 at 15:2 Comment(0)
I
0

have you tried to add keyspace value on your @MaterializedView annotation?

@MaterializedView(keyspace = "xxxx", baseEntity = MyTableType.class, view = "my_table_by_related_id")
Implosive answered 4/9, 2018 at 9:57 Comment(3)
Yep. Tried it. That generally gives me a different error, but still doesn't work. Thx, thoughThanksgiving
I created a new table and materialized view, only with a couple of fields to test. With the keyspace, I get info.archinnov.achilles.exception.AchillesException: The table my_table defined on entity mypackage.MyTableType does not exist in Cassandra. It really doesn't make sense, since as you pointed out, it's in a keyspace, so that should be specified. But I get this errorThanksgiving
Where does the @MaterializedView annotation come from? Is it part of the DSE API or Spring Data Cassandra? I am not able to find such annotation in neither of those.Anopheles

© 2022 - 2024 — McMap. All rights reserved.