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

DESCRIBE KEYSPACE / MATERIALIZED VIEW generates invalid CQL for views

    XMLWordPrintableJSON

Details

    • Correctness
    • Low
    • Low Hanging Fruit
    • User Report
    • All
    • None
    • Hide

      Updated the test to use the new describe ouptut and verified by dropping and re-using the output (from describe materialized view statement).

      Show
      Updated the test to use the new describe ouptut and verified by dropping and re-using the output (from describe materialized view statement).

    Description

      Materialized views do not allow default_time_to_live option in CQL (see CASSANDRA-12868).

      But, if the MV was created without this option, DESCRIBE KEYSPACE / MATERIALIZED VIEW command generates CQL that includes it.

      E.g.

      CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};
      
      USE test;
      
      CREATE TABLE test_table(
        id text,
        date text,
        col1 text,
        col2 text,
        PRIMARY KEY(id,date)
      ) WITH default_time_to_live = 60 AND CLUSTERING ORDER BY (date DESC);
      
      CREATE MATERIALIZED VIEW test_view AS
      SELECT id, date, col1
      FROM test_table
      WHERE id IS NOT NULL AND date IS NOT NULL
      PRIMARY KEY(id, date);

      It is OK. 

      DESCRIBE MATERIALIZED VIEW test_view; 

      returns the same CQL + all default options:

      CREATE MATERIALIZED VIEW test.test_view AS
          SELECT id, date, col1
          FROM test.test_table
          WHERE id IS NOT NULL AND date IS NOT NULL
          PRIMARY KEY (id, date)
       WITH CLUSTERING ORDER BY (date ASC)
          AND additional_write_policy = '99p'
          AND bloom_filter_fp_chance = 0.01
          AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
          AND cdc = false
          AND comment = ''
          AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
          AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
          AND crc_check_chance = 1.0
          AND default_time_to_live = 0
          AND extensions = {}
          AND gc_grace_seconds = 864000
          AND max_index_interval = 2048
          AND memtable_flush_period_in_ms = 0
          AND min_index_interval = 128
          AND read_repair = 'BLOCKING'
          AND speculative_retry = '99p';
      

      Note the 'default_time_to_live = 0' clause! If this veiw is dropped, re-creating it using DESCRIBE output would fail with 

      Cannot set default_time_to_live for a materialized view. Data in a materialized view always expire at the same time than the corresponding data in the parent table.

      Additional Information for newcomers:

      The code writting the table parameters is in TableParams.appendCqlTo and is called through TableMetadata.appendTableOptions. Those method will need to have a new parameter specifying if the call is for a table or a materialized view.
      Some unit test need to be adapted in DescribeStatementTest

      Attachments

        Activity

          People

            smiklosovic Stefan Miklosovic
            taiga-elephant Oleg Zhovtanyuk
            Stefan Miklosovic
            Benjamin Lerer, Brandon Williams
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 10m
                10m