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

patrickjp93 avatar image
patrickjp93 asked ·

Cassandra InvalidQueryException on Materialized View — PRIMARY KEY part found in SET part

Aren't Materialized Views supposed to provide a Read-optimizing layer over top of the ALLOW FILTERING mechanism? Because the following seems like it fits the Cassandra criteria, but I'm getting exceptions complaining that an update statement is affecting a Primary Key, which should only be on tables, not Mat Views.

I've made a table with a 1-column Primary Key

cqlSession.execute(createTable(NAME).ifNotExists()
    .withPartitionKey(PKEY, DataTypes.TEXT)
    .withColumn(C1, DataTypes.TEXT)
    .withColumn(C2, DataTypes.TEXT)
    .withColumn(C3, DataTypes.TEXT)
    .build());
cqlSession.execute(createMaterializedView(MAT_NAME).ifNotExists()
    .selectFrom(NAME)
    .columns(PKEY, C1, C2, C3)
    .whereColumn(PKEY).isNotNull()
    .whereColumn(C1).isNotNull()
    .withPartitionKey(PKEY)
    .withClusteringColumn(C1)
    .build());
PreparedStatement ps = session.prepare(
    update(NAME).setColumn(C2, QueryBuilder.bindMarker())
        .whereColumn(C1).isEqualTo(QueryBuilder.bindMarker())
        .whereColumn(C2).isEqualTo(QueryBuilder.bindMarker())
        .ifExists()
        .build());

"ps" is throwing the exception. By my reading of the Cassandra Driver Spec, this is incorrect. Can someone point shed some light on this?

Java driver 4.11.0

native protocol 1.5.0

datastax cassandra version 4.1.10

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 examples you posted are too vague for me to work out what you want to achieve. It would be great if you could update the original question body with a description in plain English of the base table and what the materialised view is supposed to be.

It doesn't make sense why you're using the same columns in the primary key so you need to provide more background information.

Please provide the full error message + full stack trace too. 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.