cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1080772 - in /cassandra/trunk/src/java/org/apache/cassandra/cql: Cql.g CreateColumnFamilyStatement.java CreateKeyspaceStatement.java
Date Fri, 11 Mar 2011 21:57:04 GMT
Author: eevans
Date: Fri Mar 11 21:57:04 2011
New Revision: 1080772

URL: http://svn.apache.org/viewvc?rev=1080772&view=rev
Log:
more flexible keyspace/column family specifications

Patch by eevans for CASSANDRA-2027

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/CreateKeyspaceStatement.java

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=1080772&r1=1080771&r2=1080772&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/Cql.g Fri Mar 11 21:57:04 2011
@@ -95,7 +95,7 @@ selectStatement returns [SelectStatement
           ( s1=selectExpression                 { expression = s1; }
           | K_COUNT '(' s2=selectExpression ')' { expression = s2; isCountOp = true; }
           )
-          K_FROM columnFamily=IDENT
+          K_FROM columnFamily=( IDENT | STRING_LITERAL | INTEGER )
           ( K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text);
} )?
           ( K_WHERE whereClause )?
           ( K_LIMIT rows=INTEGER { numRecords = Integer.parseInt($rows.text); } )?
@@ -167,7 +167,7 @@ updateStatement returns [UpdateStatement
           ConsistencyLevel cLevel = null;
           Map<Term, Term> columns = new HashMap<Term, Term>();
       }
-      K_UPDATE columnFamily=IDENT
+      K_UPDATE columnFamily=( IDENT | STRING_LITERAL | INTEGER )
           (K_USING K_CONSISTENCY K_LEVEL { cLevel = ConsistencyLevel.valueOf($K_LEVEL.text);
})?
           K_SET termPair[columns] (',' termPair[columns])*
           K_WHERE K_KEY '=' key=term endStmnt
@@ -194,7 +194,7 @@ deleteStatement returns [DeleteStatement
       }
       K_DELETE
           ( cols=termList { columnsList = $cols.items; })?
-          K_FROM columnFamily=IDENT ( K_USING K_CONSISTENCY K_LEVEL )?
+          K_FROM columnFamily=( IDENT | STRING_LITERAL | INTEGER ) ( K_USING K_CONSISTENCY
K_LEVEL )?
           K_WHERE ( K_KEY '=' key=term           { keyList = Collections.singletonList(key);
}
                   | K_KEY K_IN '(' keys=termList { keyList = $keys.items; } ')'
                   )?
@@ -208,7 +208,7 @@ createKeyspaceStatement returns [CreateK
     : {
           Map<String, String> attrs = new HashMap<String, String>();
       }
-      K_CREATE K_KEYSPACE keyspace=IDENT
+      K_CREATE K_KEYSPACE keyspace=( IDENT | STRING_LITERAL | INTEGER )
           K_WITH  a1=( COMPIDENT | IDENT ) '=' v1=( STRING_LITERAL | INTEGER ) { attrs.put($a1.text,
$v1.text); }
           ( K_AND aN=( COMPIDENT | IDENT ) '=' vN=( STRING_LITERAL | INTEGER ) { attrs.put($aN.text,
$vN.text); } )*
           endStmnt
@@ -225,7 +225,8 @@ createKeyspaceStatement returns [CreateK
  * ) WITH comparator = <type> [AND ...];
  */
 createColumnFamilyStatement returns [CreateColumnFamilyStatement expr]
-    : K_CREATE K_COLUMNFAMILY name=IDENT { $expr = new CreateColumnFamilyStatement($name.text);
} ( '('
+    : 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);
} )*
       ')' )?
@@ -247,18 +248,18 @@ createCfamKeywordArgument returns [Strin
 
 /** CREATE INDEX [indexName] ON columnFamily (columnName); */
 createIndexStatement returns [CreateIndexStatement expr]
-    : K_CREATE K_INDEX (idxName=IDENT)? K_ON cf=IDENT '(' columnName=term ')' endStmnt
+    : K_CREATE K_INDEX (idxName=IDENT)? K_ON cf=( IDENT | STRING_LITERAL | INTEGER ) '('
columnName=term ')' endStmnt
       { $expr = new CreateIndexStatement($idxName.text, $cf.text, columnName); }
     ;
 
 /** DROP KEYSPACE <KSP>; */
 dropKeyspaceStatement returns [String ksp]
-    : K_DROP K_KEYSPACE IDENT endStmnt { $ksp = $IDENT.text; }
+    : K_DROP K_KEYSPACE name=( IDENT | STRING_LITERAL | INTEGER ) endStmnt { $ksp = $name.text;
}
     ;
 
 /** DROP COLUMNFAMILY <CF>; */
 dropColumnFamilyStatement returns [String cfam]
-    : K_DROP K_COLUMNFAMILY IDENT endStmnt { $cfam = $IDENT.text; }
+    : K_DROP K_COLUMNFAMILY name=( IDENT | STRING_LITERAL | INTEGER ) endStmnt { $cfam =
$name.text; }
     ;
 
 comparatorType
@@ -288,7 +289,7 @@ relation returns [Relation rel]
 
 // TRUNCATE <CF>;
 truncateStatement returns [String cfam]
-    : K_TRUNCATE columnFamily=IDENT { $cfam = $columnFamily.text; } endStmnt
+    : K_TRUNCATE columnFamily=( IDENT | STRING_LITERAL | INTEGER ) { $cfam = $columnFamily.text;
} endStmnt
     ;
 
 endStmnt

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=1080772&r1=1080771&r2=1080772&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java Fri
Mar 11 21:57:04 2011
@@ -96,6 +96,10 @@ public class CreateColumnFamilyStatement
     /** Perform validation of parsed params */
     private void validate() throws InvalidRequestException
     {
+        // Column family name
+        if (!name.matches("\\w+"))
+            throw new InvalidRequestException(String.format("\"%s\" is not a valid column
family name", name));
+        
         // Catch the case where someone passed a kwarg that is not recognized.
         Set<String> keywordsFound = new HashSet<String>(properties.keySet());
         keywordsFound.removeAll(keywords);

Modified: cassandra/trunk/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java?rev=1080772&r1=1080771&r2=1080772&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cql/CreateKeyspaceStatement.java Fri Mar
11 21:57:04 2011
@@ -34,7 +34,11 @@ public class CreateKeyspaceStatement
      * @throws InvalidRequestException if arguments are missing or unacceptable
      */
     public void validate() throws InvalidRequestException
-    {   
+    {
+        // keyspace name
+        if (!name.matches("\\w+"))
+            throw new InvalidRequestException(String.format("\"%s\" is not a valid keyspace
name", name));
+        
         // required
         if (!attrs.containsKey("strategy_class"))
             throw new InvalidRequestException("missing required argument \"strategy_class\"");



Mime
View raw message