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

ALTER TABLE: mixing counter and non-counter columns in one table

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Normal
    • Resolution: Fixed
    • 4.0-rc2, 4.0
    • CQL/Semantics
    • None

    Description

      CREATE TABLE does not allow mixing counter and non-counter columns in the same table. However, this can be done with ALTER TABLE:

      • ALTER TABLE can add non-counter columns to a table with counter columns;
      • ALTER TABLE can add counter columns to a table with non-counter columns.

      Tested in cassandra-4.0-rc1 (also in cassandra-4.0-beta2):

      CREATE TABLE test1 (
        id UUID,
        my_counter COUNTER,
        PRIMARY KEY ((id))
      );
      
      ALTER TABLE test1 ADD my_text TEXT;
      
      UPDATE test1 
      SET my_counter = my_counter + 10,
          my_text = 'Test 1' 
      WHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;
      
      SELECT * FROM test1;
      
       id                                   | my_counter | my_text
      --------------------------------------+------------+---------
       5069cc15-4300-4595-ae77-381c3af5dc5e |         10 |  Test 1
      
      CREATE TABLE test2 (
        id UUID,
        my_text TEXT,
        PRIMARY KEY ((id))
      );
      
      ALTER TABLE test2 ADD my_counter COUNTER;
      
      UPDATE test2 
      SET my_counter = my_counter + 20,
          my_text = 'Test 2' 
      WHERE id = 5069cc15-4300-4595-ae77-381c3af5dc5e;
      
      SELECT * FROM test2;
      
       id                                   | my_counter | my_text
      --------------------------------------+------------+---------
       5069cc15-4300-4595-ae77-381c3af5dc5e |         20 |  Test 2
      
      CREATE TABLE test3 (
        id UUID,
        my_counter COUNTER,
        my_text TEXT,
        PRIMARY KEY ((id))
      );
      
      InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot mix counter and non counter columns in the same table"
      

      Attachments

        Activity

          People

            aholmber Adam Holmberg
            ArtemChebotko Artem Chebotko
            Adam Holmberg
            Benjamin Lerer, Ekaterina Dimitrova
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: