(cql3) allow updating column_alias types
patch by Pavel Yaskevich; reviewed by Sylvain Lebresne for CASSANDRA-4041


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/bc2dea8b
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/bc2dea8b
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/bc2dea8b

Branch: refs/heads/trunk
Commit: bc2dea8b67e783514f42d148541043c3d9fed1f3
Parents: 8a3bb80
Author: Pavel Yaskevich <xe...@apache.org>
Authored: Wed Jun 27 14:58:38 2012 +0300
Committer: Pavel Yaskevich <xe...@apache.org>
Committed: Thu Jun 28 15:56:20 2012 +0300

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../cql3/statements/AlterTableStatement.java       |   13 ++++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/bc2dea8b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8918dee..aa03655 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -21,6 +21,7 @@
    (CASSANDRA-4365)
  * add strategy_options to the KSMetaData.toString() output (CASSANDRA-4248)
  * (cql3) fix range queries containing unqueried results (CASSANDRA-4372)
+ * (cql3) allow updating column_alias types (CASSANDRA-4041)
 Merged from 1.0:
  * Set gc_grace on index CF to 0 (CASSANDRA-4314)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/bc2dea8b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 67b7dd7..6523a90 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -18,19 +18,16 @@
  */
 package org.apache.cassandra.cql3.statements;
 
-import java.io.IOException;
 import java.util.*;
 
 import org.apache.cassandra.cql3.*;
 import org.apache.cassandra.config.*;
-import org.apache.cassandra.io.compress.CompressionParameters;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.CompositeType;
 import org.apache.cassandra.db.marshal.CounterColumnType;
 import org.apache.cassandra.service.MigrationManager;
-import org.apache.cassandra.thrift.CfDef;
-import org.apache.cassandra.thrift.ColumnDef;
 import org.apache.cassandra.thrift.InvalidRequestException;
+
 import static 
org.apache.cassandra.thrift.ThriftValidation.validateColumnFamily;
 
 public class AlterTableStatement extends SchemaAlteringStatement
@@ -98,7 +95,13 @@ public class AlterTableStatement extends 
SchemaAlteringStatement
                         cfm.keyValidator(newType);
                         break;
                     case COLUMN_ALIAS:
-                        throw new 
InvalidRequestException(String.format("Cannot alter PRIMARY KEY part %s", 
columnName));
+                        assert cfDef.isComposite;
+
+                        List<AbstractType<?>> newTypes = new 
ArrayList<AbstractType<?>>(((CompositeType) cfm.comparator).types);
+                        newTypes.set(name.position, 
CFPropDefs.parseType(validator));
+
+                        cfm.comparator = CompositeType.getInstance(newTypes);
+                        break;
                     case VALUE_ALIAS:
                         cfm.defaultValidator(CFPropDefs.parseType(validator));
                         break;

Reply via email to