Uploaded image for project: 'Cassandra'
  1. Cassandra
  2. CASSANDRA-11069

Materialised views require all collections to be selected.

    XMLWordPrintableJSON

    Details

    • Severity:
      Normal

      Description

      Running Cassandra 3.0.2

      Using the official example from:
      http://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views
      The only difference is that I have added a map column to the base table.

      CREATE TABLE scores
      (
        user TEXT,
        game TEXT,
        year INT,
        month INT,
        day INT,
        score INT,
        a_map map<int, text>,
        PRIMARY KEY (user, game, year, month, day)
      );
      
      CREATE MATERIALIZED VIEW alltimehigh AS
             SELECT user FROM scores
             WHERE game IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL
             PRIMARY KEY (game, score, user, year, month, day)
             WITH CLUSTERING ORDER BY (score desc);
      
      INSERT INTO scores (user, game, year, month, day, score) VALUES ('pcmanus', 'Coup', 2015, 06, 02, 2000);
      SELECT * FROM scores;
      SELECT * FROM alltimehigh;
      

      All of the above works perfectly fine. Until you insert a row where the 'a_map' column is not null.

      INSERT INTO scores (user, game, year, month, day, score, a_map) VALUES ('pcmanus_2', 'Coup', 2015, 06, 02, 2000, {1: 'text'});
      

      This results in:

      Traceback (most recent call last):
        File "/Users/vassil/apache-cassandra-3.0.2/bin/cqlsh.py", line 1258, in perform_simple_statement
          result = future.result()
        File "/Users/vassil/apache-cassandra-3.0.2/bin/../lib/cassandra-driver-internal-only-3.0.0-6af642d.zip/cassandra-driver-3.0.0-6af642d/cassandra/cluster.py", line 3122, in result
          raise self._final_exception
      WriteFailure: code=1500 [Replica(s) failed to execute write] message="Operation failed - received 0 responses and 1 failures" info={'failures': 1, 'received_responses': 0, 'required_responses': 1, 'consistency': 'ONE'}
      

      Selecting the base table and the materialised view is also interesting:

      SELECT * FROM scores;
      SELECT * FROM alltimehigh;
      

      The result is:

      cqlsh:tests> SELECT * FROM scores;
      
       user    | game | year | month | day | a_map | score
      ---------+------+------+-------+-----+-------+-------
       pcmanus | Coup | 2015 |     6 |   2 |  null |  2000
      
      (1 rows)
      cqlsh:tests> SELECT * FROM alltimehigh;
      
       game | score | user      | year | month | day
      ------+-------+-----------+------+-------+-----
       Coup |  2000 |   pcmanus | 2015 |     6 |   2
       Coup |  2000 | pcmanus_2 | 2015 |     6 |   2
      
      (2 rows)
      

      In the logs you can see:

      ERROR [SharedPool-Worker-2] 2016-01-26 03:25:27,456 Keyspace.java:484 - Unknown exception caught while attempting to update MaterializedView! tests.scores
      java.lang.IllegalStateException: [ColumnDefinition{name=a_map, type=org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type), kind=REGULAR, position=-1}] is not a subset of []
      	at org.apache.cassandra.db.Columns$Serializer.encodeBitmap(Columns.java:531) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Columns$Serializer.serializedSubsetSize(Columns.java:483) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedRowBodySize(UnfilteredSerializer.java:275) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:247) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:234) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:227) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredRowIteratorSerializer.serializedSize(UnfilteredRowIteratorSerializer.java:169) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.partitions.PartitionUpdate$PartitionUpdateSerializer.serializedSize(PartitionUpdate.java:683) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation$MutationSerializer.serializedSize(Mutation.java:354) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.commitlog.CommitLog.add(CommitLog.java:259) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:461) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:384) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation.apply(Mutation.java:210) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy.mutateMV(StorageProxy.java:703) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.view.ViewManager.pushViewReplicaUpdates(ViewManager.java:149) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:479) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:384) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation.apply(Mutation.java:205) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy$$Lambda$159/501076283.run(Unknown Source) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy$7.runMayThrow(StorageProxy.java:1275) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy$LocalMutationRunnable.run(StorageProxy.java:2412) [apache-cassandra-3.0.2.jar:3.0.2]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_45]
      	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) [apache-cassandra-3.0.2.jar:3.0.2]
      	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
      ERROR [SharedPool-Worker-2] 2016-01-26 03:25:27,457 StorageProxy.java:1281 - Failed to apply mutation locally : {}
      java.lang.IllegalStateException: [ColumnDefinition{name=a_map, type=org.apache.cassandra.db.marshal.MapType(org.apache.cassandra.db.marshal.Int32Type,org.apache.cassandra.db.marshal.UTF8Type), kind=REGULAR, position=-1}] is not a subset of []
      	at org.apache.cassandra.db.Columns$Serializer.encodeBitmap(Columns.java:531) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Columns$Serializer.serializedSubsetSize(Columns.java:483) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedRowBodySize(UnfilteredSerializer.java:275) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:247) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:234) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredSerializer.serializedSize(UnfilteredSerializer.java:227) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.rows.UnfilteredRowIteratorSerializer.serializedSize(UnfilteredRowIteratorSerializer.java:169) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.partitions.PartitionUpdate$PartitionUpdateSerializer.serializedSize(PartitionUpdate.java:683) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation$MutationSerializer.serializedSize(Mutation.java:354) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.commitlog.CommitLog.add(CommitLog.java:259) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:461) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:384) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation.apply(Mutation.java:210) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy.mutateMV(StorageProxy.java:703) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.view.ViewManager.pushViewReplicaUpdates(ViewManager.java:149) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:479) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Keyspace.apply(Keyspace.java:384) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.db.Mutation.apply(Mutation.java:205) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy$$Lambda$159/501076283.run(Unknown Source) ~[na:na]
      	at org.apache.cassandra.service.StorageProxy$7.runMayThrow(StorageProxy.java:1275) ~[apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.service.StorageProxy$LocalMutationRunnable.run(StorageProxy.java:2412) [apache-cassandra-3.0.2.jar:3.0.2]
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_45]
      	at org.apache.cassandra.concurrent.AbstractTracingAwareExecutorService$FutureTask.run(AbstractTracingAwareExecutorService.java:164) [apache-cassandra-3.0.2.jar:3.0.2]
      	at org.apache.cassandra.concurrent.SEPWorker.run(SEPWorker.java:105) [apache-cassandra-3.0.2.jar:3.0.2]
      	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_45]
      

      As the logs say, ColumnDefinition 'a_map' is not a subset of [] (which is all non-primary key columns of the materialised view. There are no such column in this example).

      And if you drop this materialised view and create a new one where the 'a_map' is being selected, it all works.

      cqlsh:tests> drop MATERIALIZED VIEW alltimehigh ;
      cqlsh:tests> CREATE MATERIALIZED VIEW alltimehigh AS
               ...        SELECT user, a_map FROM scores
               ...        WHERE game IS NOT NULL AND score IS NOT NULL AND user IS NOT NULL AND year IS NOT NULL AND month IS NOT NULL AND day IS NOT NULL
               ...        PRIMARY KEY (game, score, user, year, month, day)
               ...        WITH CLUSTERING ORDER BY (score desc);
      cqlsh:tests> INSERT INTO scores (user, game, year, month, day, score, a_map) VALUES ('pcmanus_2', 'Coup', 2015, 06, 02, 2000, {1: 'text'});
      cqlsh:tests> SELECT * FROM scores;
      
       user      | game | year | month | day | a_map       | score
      -----------+------+------+-------+-----+-------------+-------
         pcmanus | Coup | 2015 |     6 |   2 |        null |  2000
       pcmanus_2 | Coup | 2015 |     6 |   2 | {1: 'text'} |  2000
      
      (2 rows)
      cqlsh:tests> SELECT * FROM alltimehigh;
      
       game | score | user      | year | month | day | a_map
      ------+-------+-----------+------+-------+-----+-------------
       Coup |  2000 |   pcmanus | 2015 |     6 |   2 |        null
       Coup |  2000 | pcmanus_2 | 2015 |     6 |   2 | {1: 'text'}
      
      (2 rows)
      

      Is this a documented limitation or a bug? I was trying to find a documentation that says "all collection columns must be selected in a materialised view", but I could not find such a thing. I tested it with sets in addition to maps and it is pretty much the same.

        Attachments

          Activity

            People

            • Assignee:
              carlyeks Carl Yeksigian
              Reporter:
              vassil@leanplum.com Vassil Lunchev
              Authors:
              Carl Yeksigian
              Reviewers:
              T Jake Luciani
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: