You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2013/05/01 19:03:39 UTC

[1/3] git commit: Disallow renaming columns one at a time when when the table don't have CQL3 metadata yet

Updated Branches:
  refs/heads/trunk 5dad16045 -> 591728100


Disallow renaming columns one at a time when when the table don't have CQL3 metadata yet

patch by slebresne; reviewed by iamaleksey for CASSANDRA-5531


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

Branch: refs/heads/trunk
Commit: 199cd0b785a73393f451f526930cb17f67706462
Parents: 60f09f0
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Wed May 1 16:23:40 2013 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Wed May 1 16:23:40 2013 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +
 pylib/cqlshlib/cql3handling.py                     |    6 +++-
 .../cql3/statements/AlterTableStatement.java       |   29 +++++++++++++++
 3 files changed, 36 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/199cd0b7/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index bfece4f..0045e04 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -16,6 +16,8 @@
  * Set isRunning flag later in binary protocol server (CASSANDRA-5467)
  * Fix use of CQL3 functions with descencind clustering order (CASSANDRA-5472)
  * Prevent repair when protocol version does not match (CASSANDRA-5523)
+ * Disallow renaming columns one at a time for thrift table in CQL3
+   (CASSANDRA-5531)
 Merged from 1.1
  * Add retry mechanism to OTC for non-droppable_verbs (CASSANDRA-5393)
  * Use allocator information to improve memtable memory usage estimate

http://git-wip-us.apache.org/repos/asf/cassandra/blob/199cd0b7/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py
index 00e2d0f..15f7c54 100644
--- a/pylib/cqlshlib/cql3handling.py
+++ b/pylib/cqlshlib/cql3handling.py
@@ -1469,7 +1469,7 @@ class CqlTableDef:
         cf.partition_key_validator = lookup_casstype(cf.key_validator)
         cf.comparator = lookup_casstype(cf.comparator)
         cf.default_validator = lookup_casstype(cf.default_validator)
-        cf.coldefs = coldefs
+        cf.coldefs = cf.filter_regular_coldefs(coldefs)
         cf.compact_storage = cf.is_compact_storage()
         cf.key_aliases = cf.get_key_aliases()
         cf.partition_key_components = cf.key_aliases
@@ -1478,6 +1478,10 @@ class CqlTableDef:
         cf.columns = cf.get_columns()
         return cf
 
+    def filter_regular_coldefs(self, cols):
+        return [ c for c in cols if c.get('type', 'regular') == 'regular' ]
+
+
     # not perfect, but good enough; please read CFDefinition constructor comments
     # returns False if we are dealing with a CQL3 table, True otherwise.
     # 'compact' here means 'needs WITH COMPACT STORAGE option for CREATE TABLE in CQL3'.

http://git-wip-us.apache.org/repos/asf/cassandra/blob/199cd0b7/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 b07a8a8..c6af2a0 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -22,6 +22,10 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Sets;
 
 import org.apache.cassandra.auth.Permission;
 import org.apache.cassandra.config.CFMetaData;
@@ -187,6 +191,12 @@ public class AlterTableStatement extends SchemaAlteringStatement
                 cfProps.applyToCFMetadata(cfm);
                 break;
             case RENAME:
+
+                if (cfm.getKeyAliases().size() < cfDef.keys.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.KEY_ALIAS, cfDef.keys.size()))
+                    throw new InvalidRequestException("When upgrading from Thrift, all the columns of the (composite) partition key must be renamed together.");
+                if (cfm.getColumnAliases().size() < cfDef.columns.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.COLUMN_ALIAS, cfDef.columns.size()))
+                    throw new InvalidRequestException("When upgrading from Thrift, all the columns of the (composite) clustering key must be renamed together.");
+
                 for (Map.Entry<ColumnIdentifier, ColumnIdentifier> entry : renames.entrySet())
                 {
                     CFDefinition.Name from = cfDef.get(entry.getKey());
@@ -219,6 +229,24 @@ public class AlterTableStatement extends SchemaAlteringStatement
         MigrationManager.announceColumnFamilyUpdate(cfm);
     }
 
+    private static boolean renamesAllAliases(CFDefinition cfDef, Set<ColumnIdentifier> names, CFDefinition.Name.Kind kind, int expected)
+    {
+        int renamed = Sets.filter(names, isA(cfDef, kind)).size();
+        return renamed == 0 || renamed == expected;
+    }
+
+    private static Predicate<ColumnIdentifier> isA(final CFDefinition cfDef, final CFDefinition.Name.Kind kind)
+    {
+        return new Predicate<ColumnIdentifier>()
+        {
+            public boolean apply(ColumnIdentifier input)
+            {
+                CFDefinition.Name name = cfDef.get(input);
+                return name != null && name.kind == kind;
+            }
+        };
+    }
+
     private static List<ByteBuffer> rename(int pos, ColumnIdentifier newName, List<ByteBuffer> aliases)
     {
         if (pos < aliases.size())
@@ -229,6 +257,7 @@ public class AlterTableStatement extends SchemaAlteringStatement
         }
         else
         {
+            // We insert nulls temporarly, but have checked that all the aliases are renamed
             List<ByteBuffer> newList = new ArrayList<ByteBuffer>(pos + 1);
             for (int i = 0; i < pos; ++i)
                 newList.add(i < aliases.size() ? aliases.get(i) : null);


[3/3] git commit: Merge branch 'cassandra-1.2' into trunk

Posted by al...@apache.org.
Merge branch 'cassandra-1.2' into trunk

Conflicts:
	bin/cqlsh
	src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java


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

Branch: refs/heads/trunk
Commit: 5917281000bf51d10ffade5ac357f9cbf81daee6
Parents: 5dad160 24f6387
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed May 1 20:03:26 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Wed May 1 20:03:26 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt                                        |    3 +
 bin/cqlsh                                          |   41 +++++++++++++--
 pylib/cqlshlib/cql3handling.py                     |    6 ++-
 .../cql3/statements/AlterTableStatement.java       |   27 ++++++++++
 4 files changed, 71 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/59172810/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/59172810/bin/cqlsh
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/59172810/pylib/cqlshlib/cql3handling.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/59172810/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 945d202,c6af2a0..03e1b4b
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@@ -186,18 -191,81 +190,41 @@@ public class AlterTableStatement extend
                  cfProps.applyToCFMetadata(cfm);
                  break;
              case RENAME:
 -
 -                if (cfm.getKeyAliases().size() < cfDef.keys.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.KEY_ALIAS, cfDef.keys.size()))
++                if (cfm.partitionKeyColumns().size() < cfDef.keys.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.KEY_ALIAS, cfDef.keys.size()))
+                     throw new InvalidRequestException("When upgrading from Thrift, all the columns of the (composite) partition key must be renamed together.");
 -                if (cfm.getColumnAliases().size() < cfDef.columns.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.COLUMN_ALIAS, cfDef.columns.size()))
++                if (cfm.clusteringKeyColumns().size() < cfDef.columns.size() && !renamesAllAliases(cfDef, renames.keySet(), CFDefinition.Name.Kind.COLUMN_ALIAS, cfDef.columns.size()))
+                     throw new InvalidRequestException("When upgrading from Thrift, all the columns of the (composite) clustering key must be renamed together.");
+ 
                  for (Map.Entry<ColumnIdentifier, ColumnIdentifier> entry : renames.entrySet())
                  {
 -                    CFDefinition.Name from = cfDef.get(entry.getKey());
 +                    ColumnIdentifier from = entry.getKey();
                      ColumnIdentifier to = entry.getValue();
 -                    if (from == null)
 -                        throw new InvalidRequestException(String.format("Column %s was not found in table %s", entry.getKey(), columnFamily()));
 -
 -                    CFDefinition.Name exists = cfDef.get(to);
 -                    if (exists != null)
 -                        throw new InvalidRequestException(String.format("Cannot rename column %s in table %s to %s; another column of that name already exist", from, columnFamily(), to));
 -
 -                    switch (from.kind)
 -                    {
 -                        case KEY_ALIAS:
 -                            cfm.keyAliases(rename(from.position, to, cfm.getKeyAliases()));
 -                            break;
 -                        case COLUMN_ALIAS:
 -                            cfm.columnAliases(rename(from.position, to, cfm.getColumnAliases()));
 -                            break;
 -                        case VALUE_ALIAS:
 -                            cfm.valueAlias(to.key);
 -                            break;
 -                        case COLUMN_METADATA:
 -                            throw new InvalidRequestException(String.format("Cannot rename non PRIMARY KEY part %s", from));
 -                    }
 +                    cfm.renameColumn(from.key, from.toString(), to.key, to.toString());
                  }
                  break;
          }
  
 -        MigrationManager.announceColumnFamilyUpdate(cfm);
 +        MigrationManager.announceColumnFamilyUpdate(cfm, false);
      }
  
+     private static boolean renamesAllAliases(CFDefinition cfDef, Set<ColumnIdentifier> names, CFDefinition.Name.Kind kind, int expected)
+     {
+         int renamed = Sets.filter(names, isA(cfDef, kind)).size();
+         return renamed == 0 || renamed == expected;
+     }
+ 
+     private static Predicate<ColumnIdentifier> isA(final CFDefinition cfDef, final CFDefinition.Name.Kind kind)
+     {
+         return new Predicate<ColumnIdentifier>()
+         {
+             public boolean apply(ColumnIdentifier input)
+             {
+                 CFDefinition.Name name = cfDef.get(input);
+                 return name != null && name.kind == kind;
+             }
+         };
+     }
+ 
 -    private static List<ByteBuffer> rename(int pos, ColumnIdentifier newName, List<ByteBuffer> aliases)
 -    {
 -        if (pos < aliases.size())
 -        {
 -            List<ByteBuffer> newList = new ArrayList<ByteBuffer>(aliases);
 -            newList.set(pos, newName.key);
 -            return newList;
 -        }
 -        else
 -        {
 -            // We insert nulls temporarly, but have checked that all the aliases are renamed
 -            List<ByteBuffer> newList = new ArrayList<ByteBuffer>(pos + 1);
 -            for (int i = 0; i < pos; ++i)
 -                newList.add(i < aliases.size() ? aliases.get(i) : null);
 -            newList.add(newName.key);
 -            return newList;
 -        }
 -    }
 -
      public String toString()
      {
          return String.format("AlterTableStatement(name=%s, type=%s, column=%s, validator=%s)",


[2/3] git commit: cqlsh: add CLUSTERING ORDER BY support to DESCRIBE

Posted by al...@apache.org.
cqlsh: add CLUSTERING ORDER BY support to DESCRIBE

patch by Tyler Hobbs; reviewed by Aleksey Yeschenko for CASSANDRA-5528


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

Branch: refs/heads/trunk
Commit: 24f6387bcddc72856569e86a7b3e7a9da86d0037
Parents: 199cd0b
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed May 1 19:34:20 2013 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Wed May 1 19:42:55 2013 +0300

----------------------------------------------------------------------
 CHANGES.txt |    1 +
 bin/cqlsh   |   40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 36 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6387b/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 0045e04..7429401 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -18,6 +18,7 @@
  * Prevent repair when protocol version does not match (CASSANDRA-5523)
  * Disallow renaming columns one at a time for thrift table in CQL3
    (CASSANDRA-5531)
+ * cqlsh: add CLUSTERING ORDER BY support to DESCRIBE (CASSANDRA-5528)
 Merged from 1.1
  * Add retry mechanism to OTC for non-droppable_verbs (CASSANDRA-5393)
  * Use allocator information to improve memtable memory usage estimate

http://git-wip-us.apache.org/repos/asf/cassandra/blob/24f6387b/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 5292d5e..853e3fd 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -32,7 +32,7 @@ exit 1
 from __future__ import with_statement
 
 description = "CQL Shell for Apache Cassandra"
-version = "2.3.0"
+version = "3.0.0"
 
 from StringIO import StringIO
 from itertools import groupby
@@ -103,7 +103,7 @@ except ImportError, e:
 import cql.decoders
 from cql.cursor import _VOID_DESCRIPTION
 from cql.cqltypes import (cql_types, cql_typename, lookup_casstype, lookup_cqltype,
-                          CassandraType)
+                          CassandraType, ReversedType, CompositeType)
 
 # cqlsh should run correctly when run out of a Cassandra source tree,
 # out of an unpacked Cassandra tarball, and after a proper package install.
@@ -1308,7 +1308,13 @@ class Shell(cmd.Cmd):
         indexed_columns = []
         for col in layout.columns[1:]:
             colname = self.cql_protect_name(col.name)
-            out.write(",\n  %s %s" % (colname, col.cqltype.cql_parameterized_type()))
+            coltype = col.cqltype
+
+            # Reversed types only matter for clustering order, not column definitions
+            if issubclass(coltype, ReversedType):
+                coltype = coltype.subtypes[0]
+
+            out.write(",\n  %s %s" % (colname, coltype.cql_parameterized_type()))
             if col.index_name is not None:
                 indexed_columns.append(col)
 
@@ -1329,8 +1335,32 @@ class Shell(cmd.Cmd):
             out.write(' WITH COMPACT STORAGE')
             joiner = 'AND'
 
-        # TODO: this should display CLUSTERING ORDER BY information too.
-        # work out how to determine that from a layout.
+        # check if we need a CLUSTERING ORDER BY clause
+        if layout.column_aliases:
+            # get a list of clustering component types
+            if issubclass(layout.comparator, CompositeType):
+                clustering_types = layout.comparator.subtypes
+            else:
+                clustering_types = [layout.comparator]
+
+            # only write CLUSTERING ORDER clause of we have >= 1 DESC item
+            if any(issubclass(t, ReversedType) for t in clustering_types):
+                if layout.compact_storage:
+                    out.write(' AND\n ')
+                else:
+                    out.write(' WITH')
+                out.write(' CLUSTERING ORDER BY (')
+
+                clustering_names = self.cql_protect_names(layout.column_aliases)
+
+                inner = []
+                for colname, coltype in zip(clustering_names, clustering_types):
+                    ordering = "DESC" if issubclass(coltype, ReversedType) else "ASC"
+                    inner.append("%s %s" % (colname, ordering))
+                out.write(", ".join(inner))
+
+                out.write(")")
+                joiner = "AND"
 
         cf_opts = []
         compaction_strategy = trim_if_present(getattr(layout, 'compaction_strategy_class'),