cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1086806 - in /cassandra/trunk: src/java/org/apache/cassandra/cql/ test/system/
Date Tue, 29 Mar 2011 23:41:44 GMT
Author: eevans
Date: Tue Mar 29 23:41:43 2011
New Revision: 1086806

URL: http://svn.apache.org/viewvc?rev=1086806&view=rev
Log:
CQL support for typed keys

Patch by eevans

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
    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/cql/UpdateStatement.java
    cassandra/trunk/test/system/test_cql.py

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g?rev=1086806&r1=1086805&r2=1086806&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g Tue Mar 29 23:41:43 2011
@@ -270,16 +270,18 @@ createKeyspaceStatement returns [CreateK
  */
 createColumnFamilyStatement returns [CreateColumnFamilyStatement expr]
     : K_CREATE K_COLUMNFAMILY name=( IDENT | STRING_LITERAL | INTEGER ) { $expr = new CreateColumnFamilyStatement($name.text);
}
-      ( '('
-          col1=term v1=createCfamColumnValidator { $expr.addColumn(col1, $v1.validator);
} ( ','
-          colN=term vN=createCfamColumnValidator { $expr.addColumn(colN, $vN.validator);
} )*
-      ')' )?
+      ( '(' createCfamColumns[expr] ( ',' createCfamColumns[expr] )* ')' )?
       ( K_WITH prop1=IDENT '=' arg1=createCfamKeywordArgument { $expr.addProperty($prop1.text,
$arg1.arg); }
           ( K_AND propN=IDENT '=' argN=createCfamKeywordArgument { $expr.addProperty($propN.text,
$argN.arg); } )*
       )?
       endStmnt
     ;
 
+createCfamColumns[CreateColumnFamilyStatement expr]
+    : n=term v=createCfamColumnValidator { $expr.addColumn(n, $v.validator); }
+    | K_KEY v=createCfamColumnValidator K_PRIMARY K_KEY { $expr.setKeyType($v.validator);
}
+    ;
+
 createCfamColumnValidator returns [String validator]
     : comparatorType { $validator = $comparatorType.text; }
     | STRING_LITERAL { $validator = $STRING_LITERAL.text; }
@@ -378,6 +380,7 @@ K_COLUMNFAMILY: C O L U M N F A M I L Y;
 K_INDEX:       I N D E X;
 K_ON:          O N;
 K_DROP:        D R O P;
+K_PRIMARY:     P R I M A R Y;
 
 // Case-insensitive alpha characters
 fragment A: ('a'|'A');

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=1086806&r1=1086805&r2=1086806&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java Tue
Mar 29 23:41:43 2011
@@ -87,6 +87,7 @@ public class CreateColumnFamilyStatement
     private final String name;
     private final Map<Term, String> columns = new HashMap<Term, String>();
     private final Map<String, String> properties = new HashMap<String, String>();
+    private String keyValidator;
     
     public CreateColumnFamilyStatement(String name)
     {
@@ -157,6 +158,11 @@ public class CreateColumnFamilyStatement
         columns.put(term, comparator);
     }
     
+    public void setKeyType(String validator)
+    {
+        this.keyValidator = validator;
+    }
+    
     /** Map a keyword to the corresponding value */
     public void addProperty(String name, String value)
     {
@@ -180,7 +186,7 @@ public class CreateColumnFamilyStatement
             {
                 ByteBuffer columnName = col.getKey().getByteBuffer(comparator);
                 String validatorClassName = comparators.containsKey(col.getValue()) ? comparators.get(col.getValue())
: col.getValue();
-                AbstractType validator = DatabaseDescriptor.getComparator(validatorClassName);
+                AbstractType<?> validator = DatabaseDescriptor.getComparator(validatorClassName);
                 columnDefs.put(columnName, new ColumnDefinition(columnName, validator, null,
null));
             }
             catch (ConfigurationException e)
@@ -212,6 +218,7 @@ public class CreateColumnFamilyStatement
             // RPC uses BytesType as the default validator/comparator but BytesType expects
hex for string terms, (not convenient).
             AbstractType<?> comparator = DatabaseDescriptor.getComparator(comparators.get(getPropertyString(KW_COMPARATOR,
"utf8")));
             String validator = getPropertyString(KW_DEFAULTVALIDATION, "utf8");
+            AbstractType<?> keyType = DatabaseDescriptor.getComparator(comparators.get((keyValidator
!= null) ? keyValidator : "utf8"));
 
             newCFMD = new CFMetaData(keyspace,
                                      name,
@@ -234,7 +241,8 @@ public class CreateColumnFamilyStatement
                    .memSize(getPropertyInt(KW_MEMTABLESIZEINMB, CFMetaData.DEFAULT_MEMTABLE_THROUGHPUT_IN_MB))
                    .memOps(getPropertyDouble(KW_MEMTABLEOPSINMILLIONS, CFMetaData.DEFAULT_MEMTABLE_OPERATIONS_IN_MILLIONS))
                    .mergeShardsChance(0.0)
-                   .columnMetadata(getColumns(comparator));
+                   .columnMetadata(getColumns(comparator))
+                   .keyValidator(keyType);
         }
         catch (ConfigurationException e)
         {

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=1086806&r1=1086805&r2=1086806&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/QueryProcessor.java Tue Mar 29 23:41:43
2011
@@ -51,7 +51,6 @@ import org.apache.cassandra.db.migration
 import org.apache.cassandra.db.migration.UpdateColumnFamily;
 import org.apache.cassandra.db.migration.avro.CfDef;
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.marshal.AsciiType;
 import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.dht.AbstractBounds;
 import org.apache.cassandra.dht.Bounds;
@@ -84,8 +83,8 @@ public class QueryProcessor
         
         assert select.getKeys().size() == 1;
         
-        ByteBuffer key = select.getKeys().get(0).getByteBuffer(AsciiType.instance);
         CFMetaData metadata = validateColumnFamily(keyspace, select.getColumnFamily(), false);
+        ByteBuffer key = select.getKeys().get(0).getByteBuffer(metadata.getKeyValidator());
         validateKey(key);
 
         // ...of a list of column names
@@ -135,8 +134,10 @@ public class QueryProcessor
     {
         List<org.apache.cassandra.db.Row> rows = null;
         
-        ByteBuffer startKey = (select.getKeyStart() != null) ? select.getKeyStart().getByteBuffer(AsciiType.instance)
: (new Term()).getByteBuffer();
-        ByteBuffer finishKey = (select.getKeyFinish() != null) ? select.getKeyFinish().getByteBuffer(AsciiType.instance)
: (new Term()).getByteBuffer();
+        AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace,
+                                                                   select.getColumnFamily()).getKeyValidator();
+        ByteBuffer startKey = (select.getKeyStart() != null) ? select.getKeyStart().getByteBuffer(keyType)
: (new Term()).getByteBuffer();
+        ByteBuffer finishKey = (select.getKeyFinish() != null) ? select.getKeyFinish().getByteBuffer(keyType)
: (new Term()).getByteBuffer();
         IPartitioner<?> p = StorageService.getPartitioner();
         AbstractBounds bounds = new Bounds(p.getToken(startKey), p.getToken(finishKey));
         
@@ -193,8 +194,9 @@ public class QueryProcessor
                                                 value));
         }
         
-        // FIXME: keys as ascii is not a Real Solution
-        ByteBuffer startKey = (!select.isKeyRange()) ? (new Term()).getByteBuffer() : select.getKeyStart().getByteBuffer(AsciiType.instance);
+        AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace,
+                                                                   select.getColumnFamily()).getKeyValidator();
+        ByteBuffer startKey = (!select.isKeyRange()) ? (new Term()).getByteBuffer() : select.getKeyStart().getByteBuffer(keyType);
         IndexClause thriftIndexClause = new IndexClause(expressions, startKey, select.getNumRecords());
         
         List<org.apache.cassandra.db.Row> rows;
@@ -235,8 +237,7 @@ public class QueryProcessor
                 cfamsSeen.add(update.getColumnFamily());
             }
             
-            // FIXME: keys as ascii is not a Real Solution
-            ByteBuffer key = update.getKey().getByteBuffer(AsciiType.instance);
+            ByteBuffer key = update.getKey().getByteBuffer(update.getKeyType(keyspace));
             validateKey(key);
             AbstractType<?> comparator = update.getComparator(keyspace);
             
@@ -594,11 +595,13 @@ public class QueryProcessor
                 clientState.hasColumnFamilyAccess(delete.getColumnFamily(), Permission.WRITE);
                 CFMetaData metadata = validateColumnFamily(keyspace, delete.getColumnFamily(),
false);
                 AbstractType<?> comparator = metadata.getComparatorFor(null);
-
+                AbstractType<?> keyType = DatabaseDescriptor.getCFMetaData(keyspace,
+                                                                           delete.getColumnFamily()).getKeyValidator();
+                
                 List<RowMutation> rowMutations = new ArrayList<RowMutation>();
                 for (Term key : delete.getKeys())
                 {
-                    RowMutation rm = new RowMutation(keyspace, key.getByteBuffer(AsciiType.instance));
+                    RowMutation rm = new RowMutation(keyspace, key.getByteBuffer(keyType));
                     if (delete.getColumns().size() < 1)     // No columns, delete the
row
                         rm.delete(new QueryPath(delete.getColumnFamily()), System.currentTimeMillis());
                     else    // Delete specific columns

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/UpdateStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/UpdateStatement.java?rev=1086806&r1=1086805&r2=1086806&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/UpdateStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/UpdateStatement.java Tue Mar 29 23:41:43
2011
@@ -114,12 +114,17 @@ public class UpdateStatement
                              cLevel);
     }
     
-    public AbstractType getComparator(String keyspace)
+    public AbstractType<?> getKeyType(String keyspace)
+    {
+        return DatabaseDescriptor.getCFMetaData(keyspace, columnFamily).getKeyValidator();
+    }
+    
+    public AbstractType<?> getComparator(String keyspace)
     {
         return DatabaseDescriptor.getComparator(keyspace, columnFamily);
     }
     
-    public AbstractType getValueValidator(String keyspace, ByteBuffer column)
+    public AbstractType<?> getValueValidator(String keyspace, ByteBuffer column)
     {
         return DatabaseDescriptor.getValueValidator(keyspace, columnFamily, column);
     }

Modified: cassandra/trunk/test/system/test_cql.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_cql.py?rev=1086806&r1=1086805&r2=1086806&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_cql.py (original)
+++ cassandra/trunk/test/system/test_cql.py Tue Mar 29 23:41:43 2011
@@ -40,36 +40,36 @@ def uuid1bytes_to_millis(uuidbytes):
 
 def load_sample(dbconn):
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardString1 WITH comparator = ascii
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardString1 (KEY utf8 PRIMARY KEY)
+            WITH comparator = ascii AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardUtf82 WITH comparator = utf8
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardUtf82 (KEY utf8 PRIMARY KEY)
+            WITH comparator = utf8 AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardLongA WITH comparator = long
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardLongA (KEY utf8 PRIMARY KEY)
+            WITH comparator = long AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardIntegerA WITH comparator = int
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardIntegerA (KEY utf8 PRIMARY KEY)
+            WITH comparator = int AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardUUID WITH comparator = uuid
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardUUID (KEY utf8 PRIMARY KEY)
+            WITH comparator = uuid AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardTimeUUID WITH comparator = timeuuid
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY StandardTimeUUID (KEY utf8 PRIMARY KEY)
+            WITH comparator = timeuuid AND default_validation = ascii;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY StandardTimeUUIDValues WITH comparator = ascii
-            AND default_validation = timeuuid;
+        CREATE COLUMNFAMILY StandardTimeUUIDValues (KEY utf8 PRIMARY KEY)
+            WITH comparator = ascii AND default_validation = timeuuid;
     """)
     dbconn.execute("""
-        CREATE COLUMNFAMILY IndexedA ('birthdate' long) WITH comparator = ascii
-            AND default_validation = ascii;
+        CREATE COLUMNFAMILY IndexedA (KEY utf8 PRIMARY KEY, 'birthdate' long)
+            WITH comparator = ascii AND default_validation = ascii;
     """)
     dbconn.execute("CREATE INDEX ON IndexedA ('birthdate');")
     



Mime
View raw message