Add access and datacenters to unreserved keywords

patch by Yifan Cai; reviewed by Benjamin Lerer for CASSANDRA-16398
This commit is contained in:
Yifan Cai 2021-02-02 10:13:27 -08:00
parent 7cf35988f2
commit 0373037a0d
4 changed files with 27 additions and 3 deletions

View File

@ -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)

View File

@ -1893,5 +1893,7 @@ basic_unreserved_keyword returns [String str]
| K_PER
| K_PARTITION
| K_GROUP
| K_DATACENTERS
| K_ACCESS
) { $str = $k.text; }
;

View File

@ -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());
}

View File

@ -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