0
votes

I have a Cassandra UDT column that has about 10 attributes and now we are planning to add 3 more attributes to it. What is the query to add all the three attributes. I can add them one by one by executing 3 different queries like alter TYPE commentmetadata ADD columnname1 <type>;, alter TYPE commentmetadata ADD columnname2 <type>;, alter TYPE commentmetadata ADD columnname3 <type>;.

Can this is be done in a single query? Datastax documentation mentions that it can be done by something like this ALTER TYPE commentmetadata ADD (field_name cql_datatype[,...]) add fields by entering a field name followed by the data type in a comma separated list. I tried the following 3 queries but I am getting query error for all.

ALTER TYPE commentmetadata ADD columnname1 int, columnname2 int, columnname3 int;
ALTER TYPE commentmetadata ADD [columnname1 int, columnname2 int, columnname3 int]; 
ALTER TYPE commentmetadata ADD (columnname1 int, columnname2 int, columnname3 int);
1
what version of Cassandra?Alex Ott

1 Answers

0
votes

According to CQL grammar, this is not possible:

/**
 * ALTER TYPE <name> ALTER <field> TYPE <newtype>;
 * ALTER TYPE <name> ADD <field> <newtype>;
 * ALTER TYPE <name> RENAME <field> TO <newtype> AND ...;
 */
alterTypeStatement returns [AlterTypeStatement.Raw stmt]
    : K_ALTER K_TYPE name=userTypeName { $stmt = new AlterTypeStatement.Raw(name); }
      (
        K_ALTER   f=fident K_TYPE v=comparatorType { $stmt.alter(f, v); }

      | K_ADD     f=fident v=comparatorType        { $stmt.add(f, v); }

      | K_RENAME f1=fident K_TO toF1=fident        { $stmt.rename(f1, toF1); }
         ( K_AND fn=fident K_TO toFn=fident        { $stmt.rename(fn, toFn); } )*
      )
    ;

You can file a JIRA for Cassandra to add such functionality.

P.S. Can you point to page where it's written in the DataStax docs?