cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1159474 - in /cassandra/trunk: ./ contrib/ interface/thrift/gen-java/org/apache/cassandra/thrift/ src/java/org/apache/cassandra/config/ src/java/org/apache/cassandra/cql/ src/java/org/apache/cassandra/gms/ src/java/org/apache/cassandra/thr...
Date Fri, 19 Aug 2011 01:59:23 GMT
Author: jbellis
Date: Fri Aug 19 01:59:22 2011
New Revision: 1159474

URL: http://svn.apache.org/viewvc?rev=1159474&view=rev
Log:
merge from 0.8

Modified:
    cassandra/trunk/   (props changed)
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/contrib/   (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java 
 (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java   (props
changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java
  (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java
  (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java
  (props changed)
    cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
    cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
    cassandra/trunk/src/java/org/apache/cassandra/gms/VersionedValue.java
    cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java
    cassandra/trunk/test/system/test_cql.py
    cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java

Propchange: cassandra/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7:1026516-1151306
 /cassandra/branches/cassandra-0.7.0:1053690-1055654
-/cassandra/branches/cassandra-0.8:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0:1125021-1130369
 /cassandra/branches/cassandra-0.8.1:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3:1051699-1053689

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Fri Aug 19 01:59:22 2011
@@ -49,6 +49,10 @@
    (rows containing nothing but expired tombstones) (CASSANDRA-3039)
  * work around native memory leak in com.sun.management.GarbageCollectorMXBean
    (CASSANDRA-2868)
+ * validate that column names in column_metadata are not equal to key_alias
+   on create/update of the ColumnFamily and CQL 'ALTER' statement (CASSANDRA-3036)
+ * return an InvalidRequestException if an indexed column is assigned
+   a value larger than 64KB (CASSANDRA-3057)
 
 
 0.8.4

Propchange: cassandra/trunk/contrib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/contrib:922689-1052356,1052358-1053452,1053454,1053456-1068009
 /cassandra/branches/cassandra-0.7/contrib:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/contrib:1053690-1055654
-/cassandra/branches/cassandra-0.8/contrib:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/contrib:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/contrib:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/contrib:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/contrib:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 19 01:59:22 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1090934-1125013,1125019-1158856
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1090934-1125013,1125019-1159473
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1051699-1053689

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/CFMetaData.java Fri Aug 19 01:59:22
2011
@@ -680,13 +680,16 @@ public final class CFMetaData
 
     public AbstractType getValueValidator(ByteBuffer column)
     {
-        AbstractType validator = defaultValidator;
-        ColumnDefinition columnDefinition = column_metadata.get(column);
-        if (columnDefinition != null)
-            validator = columnDefinition.getValidator();
-        return validator;
+        return getValueValidator(column_metadata.get(column));
     }
-    
+
+    public AbstractType getValueValidator(ColumnDefinition columnDefinition)
+    {
+        return columnDefinition == null
+               ? defaultValidator
+               : columnDefinition.getValidator();
+    }
+
     /** applies implicit defaults to cf definition. useful in updates */
     public static void applyImplicitDefaults(org.apache.cassandra.thrift.CfDef cf_def) 
     {

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/AlterTableStatement.java Fri Aug 19
01:59:22 2011
@@ -65,10 +65,15 @@ public class AlterTableStatement
         switch (oType)
         {
             case ADD:
+                if (cfDef.key_alias != null && cfDef.key_alias.equals(columnName))
+                    throw new InvalidRequestException("Invalid column name: "
+                                                      + this.columnName
+                                                      + ", because it equals to key_alias.");
+
                 cfDef.column_metadata.add(new ColumnDefinition(columnName,
-                                                                       TypeParser.parse(validator),
-                                                                       null,
-                                                                       null).deflate());
+                                                               TypeParser.parse(validator),
+                                                               null,
+                                                               null).deflate());
                 break;
 
             case ALTER:

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java Fri
Aug 19 01:59:22 2011
@@ -163,6 +163,28 @@ public class CreateColumnFamilyStatement
             throw new InvalidRequestException("You must specify a PRIMARY KEY");
         else if (keyValidator.size() > 1)
             throw new InvalidRequestException("You may only specify one PRIMARY KEY");
+
+        AbstractType<?> comparator;
+
+        try
+        {
+            comparator = getComparator();
+        }
+        catch (ConfigurationException e)
+        {
+            throw new InvalidRequestException(e.toString());
+        }
+
+        for (Map.Entry<Term, String> column : columns.entrySet())
+        {
+            ByteBuffer name = column.getKey().getByteBuffer(comparator);
+
+            if (keyAlias != null && keyAlias.equals(name))
+                throw new InvalidRequestException("Invalid column name: "
+                                                  + column.getKey().getText()
+                                                  + ", because it equals to the key_alias.");
+
+        }
     }
     
     /** Map a column name to a validator for its value */
@@ -209,7 +231,7 @@ public class CreateColumnFamilyStatement
         {
             try
             {
-                ByteBuffer columnName = col.getKey().getByteBuffer(comparator);
+                ByteBuffer columnName = comparator.fromString(col.getKey().getText());
                 String validatorClassName = comparators.containsKey(col.getValue()) ? comparators.get(col.getValue())
: col.getValue();
                 AbstractType<?> validator = TypeParser.parse(validatorClassName);
                 columnDefs.put(columnName, new ColumnDefinition(columnName, validator, null,
null));
@@ -224,7 +246,26 @@ public class CreateColumnFamilyStatement
         
         return columnDefs;
     }
-    
+
+    /* If not comparator/validator is not specified, default to text (BytesType is the wrong
default for CQL
+     * since it uses hex terms).  If the value specified is not found in the comparators
map, assume the user
+     * knows what they are doing (a custom comparator/validator for example), and pass it
on as-is.
+     */
+
+    private AbstractType<?> getComparator() throws ConfigurationException
+    {
+        return TypeParser.parse((comparators.get(getPropertyString(KW_COMPARATOR, "text"))
!= null)
+                                  ? comparators.get(getPropertyString(KW_COMPARATOR, "text"))
+                                  : getPropertyString(KW_COMPARATOR, "text"));
+    }
+
+    private AbstractType<?> getValidator() throws ConfigurationException
+    {
+        return TypeParser.parse((comparators.get(getPropertyString(KW_DEFAULTVALIDATION,
"text")) != null)
+                                  ? comparators.get(getPropertyString(KW_DEFAULTVALIDATION,
"text"))
+                                  : getPropertyString(KW_DEFAULTVALIDATION, "text"));
+    }
+
     /**
      * Returns a CFMetaData instance based on the parameters parsed from this
      * <code>CREATE</code> statement, or defaults where applicable.
@@ -240,17 +281,7 @@ public class CreateColumnFamilyStatement
         CFMetaData newCFMD;
         try
         {
-            /* If not comparator/validator is not specified, default to text (BytesType is
the wrong default for CQL
-             * since it uses hex terms).  If the value specified is not found in the comparators
map, assume the user
-             * knows what they are doing (a custom comparator/validator for example), and
pass it on as-is.
-             */
-            String comparatorString = (comparators.get(getPropertyString(KW_COMPARATOR, "text"))
!= null)
-                                      ? comparators.get(getPropertyString(KW_COMPARATOR,
"text"))
-                                      : getPropertyString(KW_COMPARATOR, "text");
-            String validatorString = (comparators.get(getPropertyString(KW_DEFAULTVALIDATION,
"text")) != null)
-                                     ? comparators.get(getPropertyString(KW_DEFAULTVALIDATION,
"text"))
-                                     : getPropertyString(KW_DEFAULTVALIDATION, "text");
-            AbstractType<?> comparator = TypeParser.parse(comparatorString);
+            AbstractType<?> comparator = getComparator();
 
             newCFMD = new CFMetaData(keyspace,
                                      name,
@@ -264,7 +295,7 @@ public class CreateColumnFamilyStatement
                    .readRepairChance(getPropertyDouble(KW_READREPAIRCHANCE, CFMetaData.DEFAULT_READ_REPAIR_CHANCE))
                    .replicateOnWrite(getPropertyBoolean(KW_REPLICATEONWRITE, CFMetaData.DEFAULT_REPLICATE_ON_WRITE))
                    .gcGraceSeconds(getPropertyInt(KW_GCGRACESECONDS, CFMetaData.DEFAULT_GC_GRACE_SECONDS))
-                   .defaultValidator(TypeParser.parse(validatorString))
+                   .defaultValidator(getValidator())
                    .minCompactionThreshold(getPropertyInt(KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD))
                    .maxCompactionThreshold(getPropertyInt(KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD))
                    .rowCacheSavePeriod(getPropertyInt(KW_ROWCACHESAVEPERIODSECS, CFMetaData.DEFAULT_ROW_CACHE_SAVE_PERIOD_IN_SECONDS))

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Fri Aug 19 01:59:22
2011
@@ -845,8 +845,6 @@ public class QueryProcessor
             case ALTER_TABLE:
                 AlterTableStatement alterTable = (AlterTableStatement) statement.statement;
 
-                System.out.println(alterTable);
-
                 validateColumnFamily(keyspace, alterTable.columnFamily);
                 clientState.hasColumnFamilyAccess(alterTable.columnFamily, Permission.WRITE);
                 validateSchemaAgreement();

Modified: cassandra/trunk/src/java/org/apache/cassandra/gms/VersionedValue.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/gms/VersionedValue.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/gms/VersionedValue.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/gms/VersionedValue.java Fri Aug 19 01:59:22
2011
@@ -160,7 +160,7 @@ public class VersionedValue implements C
 
         public VersionedValue rpcaddress(InetAddress endpoint)
         {
-            return new VersionedValue(endpoint.toString());
+            return new VersionedValue(endpoint.getHostAddress());
         }
 
         public VersionedValue releaseVersion()

Modified: cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/thrift/ThriftValidation.java Fri Aug 19
01:59:22 2011
@@ -410,9 +410,11 @@ public class ThriftValidation
             throw new InvalidRequestException("Column value is required");
         if (!column.isSetTimestamp())
             throw new InvalidRequestException("Column timestamp is required");
+
+        ColumnDefinition columnDef = metadata.getColumnDefinition(column.name);
         try
         {
-            AbstractType validator = metadata.getValueValidator(column.name);
+            AbstractType validator = metadata.getValueValidator(columnDef);
             if (validator != null)
                 validator.validate(column.value);
         }
@@ -426,6 +428,14 @@ public class ThriftValidation
                                                             metadata.cfName,
                                                             (isSubColumn ? metadata.subcolumnComparator
: metadata.comparator).getString(column.name)));
         }
+
+        // Indexed column values cannot be larger than 64K.  See CASSANDRA-3057 for more
details
+        if (columnDef != null && columnDef.getIndexType() != null && column.value.remaining()
> FBUtilities.MAX_UNSIGNED_SHORT)
+            throw new InvalidRequestException(String.format("Can't index column value of
size %d for index %s in CF %s of KS %s",
+                                                            column.value.remaining(),
+                                                            columnDef.getIndexName(),
+                                                            metadata.cfName,
+                                                            metadata.ksName));
     }
 
     /**
@@ -553,22 +563,6 @@ public class ThriftValidation
                 }
             }
 
-            if (cf_def.key_alias != null)
-            {
-                if (!cf_def.key_alias.hasRemaining())
-                    throw new InvalidRequestException("key_alias may not be empty");
-                try
-                {
-                    // it's hard to use a key in a select statement if we can't type it.
-                    // for now let's keep it simple and require ascii.
-                    AsciiType.instance.validate(cf_def.key_alias);
-                }
-                catch (MarshalException e)
-                {
-                    throw new InvalidRequestException("Key aliases must be ascii");
-                }
-            }
-
             ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
             if (cfType == null)
                 throw new InvalidRequestException("invalid column type " + cf_def.column_type);
@@ -586,6 +580,18 @@ public class ThriftValidation
                                     ? TypeParser.parse(cf_def.comparator_type)
                                     : TypeParser.parse(cf_def.subcomparator_type);
 
+            if (cf_def.key_alias != null)
+            {
+                // check if any of the columns has name equal to the cf.key_alias
+                for (ColumnDef columnDef : cf_def.column_metadata)
+                {
+                    if (cf_def.key_alias.equals(columnDef.name))
+                        throw new InvalidRequestException("Invalid column name: "
+                                                          + AsciiType.instance.compose(cf_def.key_alias)
+                                                          + ", because it equals to the key_alias.");
+                }
+            }
+
             // initialize a set of names NOT in the CF under consideration
             Set<String> indexNames = new HashSet<String>();
             for (ColumnFamilyStore cfs : ColumnFamilyStore.all())

Modified: cassandra/trunk/test/system/test_cql.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_cql.py?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_cql.py (original)
+++ cassandra/trunk/test/system/test_cql.py Fri Aug 19 01:59:22 2011
@@ -477,6 +477,9 @@ class TestCql(ThriftTester):
         # Missing primary key
         assert_raises(cql.ProgrammingError, cursor.execute, "CREATE COLUMNFAMILY NewCf2")
 
+        # column name should not match key alias
+        assert_raises(cql.ProgrammingError, cursor.execute, "CREATE COLUMNFAMILY NewCf2 (id
'utf8' primary key, id int)")
+
         # Too many primary keys
         assert_raises(cql.ProgrammingError,
                       cursor.execute,
@@ -1140,7 +1143,7 @@ class TestCql(ThriftTester):
         cursor.execute("USE AlterTableKS;")
 
         cursor.execute("""
-            CREATE COLUMNFAMILY NewCf1 (KEY varint PRIMARY KEY) WITH default_validation =
ascii;
+            CREATE COLUMNFAMILY NewCf1 (id_key varint PRIMARY KEY) WITH default_validation
= ascii;
         """)
 
         # TODO: temporary (until this can be done with CQL).
@@ -1204,6 +1207,12 @@ class TestCql(ThriftTester):
         assert_raises(cql.ProgrammingError,
                       cursor.execute,
                       "ALTER COLUMNFAMILY NewCf1 DROP name")
+
+        # should raise error when column name equals key alias
+        assert_raises(cql.ProgrammingError,
+                      cursor.execute,
+                      "ALTER COLUMNFAMILY NewCf1 ADD id_key utf8")
+
     
     def test_counter_column_support(self):
         "update statement should be able to work with counter columns"

Modified: cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java?rev=1159474&r1=1159473&r2=1159474&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java Fri Aug
19 01:59:22 2011
@@ -21,9 +21,24 @@ package org.apache.cassandra.thrift;
  */
 
 
+import java.nio.ByteBuffer;
+
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.marshal.AsciiType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+
 import org.junit.Test;
 
 import org.apache.cassandra.CleanupHelper;
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.marshal.AsciiType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.utils.FBUtilities;
+
+import java.util.concurrent.Callable;
 
 public class ThriftValidationTest extends CleanupHelper
 {
@@ -38,4 +53,95 @@ public class ThriftValidationTest extend
     {
         ThriftValidation.validateColumnFamily("Keyspace1", "Counter1", true);
     }
+
+    @Test
+    public void testColumnValueSizeForIndexedColumn() throws ConfigurationException, InvalidRequestException
+    {
+        CfDef cfDef = CFMetaData.convertToThrift(DatabaseDescriptor.getCFMetaData("Keyspace1",
"Standard1"));
+        ByteBuffer columnName = AsciiType.instance.fromString("indexed");
+
+        // add an indexed column definition
+        cfDef.addToColumn_metadata(new ColumnDef(columnName, UTF8Type.class.getCanonicalName())
+                                                 .setIndex_type(IndexType.KEYS)
+                                                 .setIndex_name("indexed_col"));
+
+        CFMetaData metaData = CFMetaData.fromThrift(cfDef);
+
+        Column column = new Column(columnName)
+                            .setValue(new byte[FBUtilities.MAX_UNSIGNED_SHORT + 1])
+                            .setTimestamp(System.currentTimeMillis());
+
+        boolean gotException = false;
+
+        try
+        {
+            // this run should throw an exception
+            ThriftValidation.validateColumnData(metaData, column, false);
+        }
+        catch (InvalidRequestException e)
+        {
+            gotException = true;
+        }
+
+        assert gotException : "expected InvalidRequestException but not received.";
+
+        // change value to be less than unsigned short size
+        column.setValue(new byte[12]);
+
+        gotException = false; // reset flag
+
+        try
+        {
+            // this run should run clean
+            ThriftValidation.validateColumnData(metaData, column, false);
+        }
+        catch (InvalidRequestException e)
+        {
+            gotException = true;
+        }
+
+        assert !gotException : "got unexpected InvalidRequestException";
+    }
+
+    @Test
+    public void testColumnNameEqualToKeyAlias()
+    {
+        CFMetaData metaData = DatabaseDescriptor.getCFMetaData("Keyspace1", "Standard1");
+        CfDef newMetadata = CFMetaData.convertToThrift(metaData);
+
+        boolean gotException = false;
+
+        // add a key_alias = "id"
+        newMetadata.setKey_alias(AsciiType.instance.decompose("id"));
+
+        // should not throw IRE here
+        try
+        {
+            ThriftValidation.validateCfDef(newMetadata, metaData);
+        }
+        catch (InvalidRequestException e)
+        {
+            gotException = true;
+        }
+
+        assert !gotException : "got unexpected InvalidRequestException";
+
+        // add a column with name = "id"
+        newMetadata.addToColumn_metadata(new ColumnDef(UTF8Type.instance.decompose("id"),
+                                                       "org.apache.cassandra.db.marshal.UTF8Type"));
+
+
+        gotException = false;
+
+        try
+        {
+            ThriftValidation.validateCfDef(newMetadata, metaData);
+        }
+        catch (InvalidRequestException e)
+        {
+            gotException = true;
+        }
+
+        assert gotException : "expected InvalidRequestException but not received.";
+    }
 }



Mime
View raw message