cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject [1/2] cassandra git commit: Cleanup uses of AlterTableStatementColumn
Date Thu, 01 Sep 2016 07:52:47 GMT
Repository: cassandra
Updated Branches:
  refs/heads/trunk 45f96c86e -> 5f3ad2880


Cleanup uses of AlterTableStatementColumn

patch by Sylvain Lebresne; reviewed by Dave Brosius for CASSANDRA-12567


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

Branch: refs/heads/trunk
Commit: 58abe8a808fc2d9f400c09b4a7cf96b93577bded
Parents: 8a3f0e1
Author: Sylvain Lebresne <sylvain@datastax.com>
Authored: Wed Aug 31 10:28:36 2016 +0200
Committer: Sylvain Lebresne <sylvain@datastax.com>
Committed: Thu Sep 1 09:50:30 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cql3/statements/AlterTableStatement.java    | 52 ++++++++------------
 .../statements/AlterTableStatementColumn.java   | 10 +++-
 3 files changed, 29 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/58abe8a8/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a0f6055..842f207 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.10
+ * Cleanup uses of AlterTableStatementColumn (CASSANDRA-12567)
  * Tracing payload is passed through newSession(..) (CASSANDRA-11706)
  * avoid deleting non existing sstable files and improve related log messages (CASSANDRA-12261)
  * json/yaml output format for nodetool compactionhistory (CASSANDRA-12486)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/58abe8a8/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 1d1cbc3..48666be 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -93,7 +93,6 @@ public class AlterTableStatement extends SchemaAlteringStatement
         CQL3Type.Raw dataType = null;
         boolean isStatic = false;
         CQL3Type validator = null;
-        ColumnDefinition.Raw rawColumnName = null;
 
         List<ViewDefinition> viewUpdates = null;
         Iterable<ViewDefinition> views = View.findAll(keyspace(), columnFamily());
@@ -101,21 +100,18 @@ public class AlterTableStatement extends SchemaAlteringStatement
         switch (oType)
         {
             case ADD:
+                if (cfm.isDense())
+                    throw new InvalidRequestException("Cannot add new column to a COMPACT
STORAGE table");
+
                 for (AlterTableStatementColumn colData : colNameList)
                 {
-                    rawColumnName = colData.getColumnName();
-                    if (rawColumnName != null)
-                    {
-                        columnName = rawColumnName.getIdentifier(cfm);
-                        def =  cfm.getColumnDefinition(columnName);
-                        dataType = colData.getColumnType();
-                        isStatic = colData.getStaticType();
-                        validator = dataType == null ? null : dataType.prepare(keyspace());
-                    }
+                    columnName = colData.getColumnName().getIdentifier(cfm);
+                    def = cfm.getColumnDefinition(columnName);
+                    dataType = colData.getColumnType();
+                    assert dataType != null;
+                    isStatic = colData.getStaticType();
+                    validator = dataType.prepare(keyspace());
 
-                    assert columnName != null;
-                    if (cfm.isDense())
-                        throw new InvalidRequestException("Cannot add new column to a COMPACT
STORAGE table");
 
                     if (isStatic)
                     {
@@ -189,16 +185,12 @@ public class AlterTableStatement extends SchemaAlteringStatement
                 break;
 
             case ALTER:
-                rawColumnName = colNameList.get(0).getColumnName();
-                if (rawColumnName != null)
-                {
-                    columnName = rawColumnName.getIdentifier(cfm);
-                    def = cfm.getColumnDefinition(columnName);
-                    dataType = colNameList.get(0).getColumnType();
-                    validator = dataType == null ? null : dataType.prepare(keyspace());
-                }
+                columnName = colNameList.get(0).getColumnName().getIdentifier(cfm);
+                def = cfm.getColumnDefinition(columnName);
+                dataType = colNameList.get(0).getColumnType();
+                assert dataType != null;
+                validator = dataType.prepare(keyspace());
 
-                assert columnName != null;
                 if (def == null)
                     throw new InvalidRequestException(String.format("Column %s was not found
in table %s", columnName, columnFamily()));
 
@@ -229,18 +221,14 @@ public class AlterTableStatement extends SchemaAlteringStatement
                 break;
 
             case DROP:
+                if (!cfm.isCQLTable())
+                    throw new InvalidRequestException("Cannot drop columns from a non-CQL3
table");
+
                 for (AlterTableStatementColumn colData : colNameList)
                 {
-                    columnName = null;
-                    rawColumnName = colData.getColumnName();
-                    if (rawColumnName != null)
-                    {
-                        columnName = rawColumnName.getIdentifier(cfm);
-                        def = cfm.getColumnDefinition(columnName);
-                    }
-                    assert columnName != null;
-                    if (!cfm.isCQLTable())
-                        throw new InvalidRequestException("Cannot drop columns from a non-CQL3
table");
+                    columnName = colData.getColumnName().getIdentifier(cfm);
+                    def = cfm.getColumnDefinition(columnName);
+
                     if (def == null)
                         throw new InvalidRequestException(String.format("Column %s was not
found in table %s", columnName, columnFamily()));
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/58abe8a8/src/java/org/apache/cassandra/cql3/statements/AlterTableStatementColumn.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatementColumn.java
b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatementColumn.java
index 480709f..7dea565 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatementColumn.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatementColumn.java
@@ -20,6 +20,11 @@ package org.apache.cassandra.cql3.statements;
 import org.apache.cassandra.config.ColumnDefinition;
 import org.apache.cassandra.cql3.CQL3Type;
 
+/**
+ * Stores a column name and optionally type for an Alter Table statement definition.
+ *
+ * This is used by AlterTableStatement to store the added, altered or dropped columns.
+ */
 public class AlterTableStatementColumn
 {
     private final CQL3Type.Raw dataType;
@@ -28,14 +33,15 @@ public class AlterTableStatementColumn
 
     public AlterTableStatementColumn(ColumnDefinition.Raw colName, CQL3Type.Raw dataType,
boolean isStatic)
     {
-        this.dataType = dataType;
+        assert colName != null;
+        this.dataType = dataType; // will be null when dropping columns, and never null otherwise
(for ADD and ALTER).
         this.colName = colName;
         this.isStatic = isStatic;
     }
 
     public AlterTableStatementColumn(ColumnDefinition.Raw colName, CQL3Type.Raw dataType)
     {
-        this(colName, dataType,false );
+        this(colName, dataType, false);
     }
 
     public AlterTableStatementColumn(ColumnDefinition.Raw colName)


Mime
View raw message