This is an automated email from the ASF dual-hosted git repository.

ycai pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 0373037  Add access and datacenters to unreserved keywords
0373037 is described below

commit 0373037a0db7e13548b0f302cad9414f00e58991
Author: Yifan Cai <[email protected]>
AuthorDate: Tue Feb 2 10:13:27 2021 -0800

    Add access and datacenters to unreserved keywords
    
    patch by Yifan Cai; reviewed by Benjamin Lerer for CASSANDRA-16398
---
 CHANGES.txt                                         |  1 +
 src/antlr/Parser.g                                  |  2 ++
 .../org/apache/cassandra/cql3/ReservedKeywords.java |  6 +++---
 .../cql3/validation/operations/CreateTest.java      | 21 +++++++++++++++++++++
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index ba23707..323ba0e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0-beta5
+ * Add access and datacenters to unreserved keywords (CASSANDRA-16398)
  * Fix nodetool ring, status output when DNS resolution or port printing are 
in use (CASSANDRA-16283)
  * Upgrade Jacoco to 0.8.6 (for Java 11 support) (CASSANDRA-16365)
  * Move excessive repair debug loggings to trace level (CASSANDRA-16406)
diff --git a/src/antlr/Parser.g b/src/antlr/Parser.g
index b0f1b94..3f6f43f 100644
--- a/src/antlr/Parser.g
+++ b/src/antlr/Parser.g
@@ -1893,5 +1893,7 @@ basic_unreserved_keyword returns [String str]
         | K_PER
         | K_PARTITION
         | K_GROUP
+        | K_DATACENTERS
+        | K_ACCESS
         ) { $str = $k.text; }
     ;
diff --git a/src/java/org/apache/cassandra/cql3/ReservedKeywords.java 
b/src/java/org/apache/cassandra/cql3/ReservedKeywords.java
index 30b1a6e..c5b2202 100644
--- a/src/java/org/apache/cassandra/cql3/ReservedKeywords.java
+++ b/src/java/org/apache/cassandra/cql3/ReservedKeywords.java
@@ -23,7 +23,7 @@ import java.util.Set;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableSet;
 
-class ReservedKeywords
+public final class ReservedKeywords
 {
     @VisibleForTesting
     static final String[] reservedKeywords = new String[]
@@ -91,9 +91,9 @@ class ReservedKeywords
                                                      "MBEAN",
                                                      "MBEANS"};
 
-    private static final Set<String> reservedSet = 
ImmutableSet.copyOf(reservedKeywords);
+    static final Set<String> reservedSet = 
ImmutableSet.copyOf(reservedKeywords);
 
-    static boolean isReserved(String text)
+    public static boolean isReserved(String text)
     {
         return reservedSet.contains(text.toUpperCase());
     }
diff --git 
a/test/unit/org/apache/cassandra/cql3/validation/operations/CreateTest.java 
b/test/unit/org/apache/cassandra/cql3/validation/operations/CreateTest.java
index b35b82f..10a4e87 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/CreateTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/CreateTest.java
@@ -19,15 +19,20 @@ package org.apache.cassandra.cql3.validation.operations;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Set;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 import org.junit.Test;
 
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.CqlLexer;
 import org.apache.cassandra.cql3.Duration;
+import org.apache.cassandra.cql3.ReservedKeywords;
 import org.apache.cassandra.db.Mutation;
 import org.apache.cassandra.db.partitions.Partition;
 import org.apache.cassandra.exceptions.ConfigurationException;
@@ -683,6 +688,22 @@ public class CreateTest extends CQLTester
                                             + " WITH compression = { 'class' : 
'SnappyCompressor', 'unknownOption' : 32 };");
     }
 
+    @Test
+    public void testUseUnreservedKeywordAsColumnName()
+    {
+        Set<String> unreservedKeywords = 
Arrays.stream(CqlLexer.class.getDeclaredFields())
+                                               .filter(f -> 
f.getName().startsWith("K_"))
+                                               .map(f -> 
f.getName().substring(2)) // remove the heading "K_"
+                                               .filter(name -> 
!ReservedKeywords.isReserved(name.toUpperCase()))
+                                               .collect(Collectors.toSet());
+        for (String colName : unreservedKeywords)
+        {
+            String format = "CREATE TABLE %%s (foo text PRIMARY KEY, %s 
text);";
+            createTable(KEYSPACE_PER_TEST, String.format(format, colName));
+            createTable(KEYSPACE_PER_TEST, String.format(format, 
colName.toLowerCase()));
+        }
+    }
+
     private void assertThrowsConfigurationException(String errorMsg, String 
createStmt)
     {
         try


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to