mirror of https://github.com/apache/cassandra
Allow unreserved keywords as user and identity names in USER and IDENTITY statements
patch by Maxim Muzafarov; reviewed by Dmitry Konstantinov for CASSANDRA-21510
This commit is contained in:
parent
8fc52f5d2f
commit
c4c3048b13
|
|
@ -1,4 +1,5 @@
|
||||||
6.0-alpha2
|
6.0-alpha2
|
||||||
|
* Allow unreserved keywords as user and identity names in USER and IDENTITY statements (CASSANDRA-21510)
|
||||||
* Reduce allocations in DefaultQueryOptions (CASSANDRA-21467)
|
* Reduce allocations in DefaultQueryOptions (CASSANDRA-21467)
|
||||||
* Coordinator load-shedding returns OverloadedException without setting streamId, misrouting query responses (CASSANDRA-21508)
|
* Coordinator load-shedding returns OverloadedException without setting streamId, misrouting query responses (CASSANDRA-21508)
|
||||||
* Reduce number of scheduledTasks on metric id release in ThreadLocalMetrics (CASSANDRA-21475)
|
* Reduce number of scheduledTasks on metric id release in ThreadLocalMetrics (CASSANDRA-21475)
|
||||||
|
|
|
||||||
|
|
@ -2363,12 +2363,14 @@ vector_type returns [CQL3Type.Raw vt]
|
||||||
username
|
username
|
||||||
: IDENT
|
: IDENT
|
||||||
| STRING_LITERAL
|
| STRING_LITERAL
|
||||||
|
| unreserved_keyword
|
||||||
| QUOTED_NAME { addRecognitionError("Quoted strings are are not supported for user names and USER is deprecated, please use ROLE");}
|
| QUOTED_NAME { addRecognitionError("Quoted strings are are not supported for user names and USER is deprecated, please use ROLE");}
|
||||||
;
|
;
|
||||||
|
|
||||||
identity
|
identity
|
||||||
: IDENT
|
: IDENT
|
||||||
| STRING_LITERAL
|
| STRING_LITERAL
|
||||||
|
| unreserved_keyword
|
||||||
| QUOTED_NAME { addRecognitionError("Quoted strings are are not supported for identity");}
|
| QUOTED_NAME { addRecognitionError("Quoted strings are are not supported for identity");}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,42 @@ public class ReservedKeywordsTest
|
||||||
asserts.assertAll();
|
asserts.assertAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Legacy USER and IDENTITY statements must accept unreserved keywords as names, just like
|
||||||
|
* role statements do ({@code roleName} accepts {@code unreserved_keyword}). Otherwise adding
|
||||||
|
* a new keyword to the grammar breaks existing deployments with a user or identity of that name.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testUnreservedKeywordsAsUserNameAndIdentity()
|
||||||
|
{
|
||||||
|
SoftAssertions asserts = new SoftAssertions();
|
||||||
|
for (var f : Cql_Lexer.class.getDeclaredFields())
|
||||||
|
{
|
||||||
|
if (!Modifier.isStatic(f.getModifiers())) continue;
|
||||||
|
if (!f.getName().startsWith("K_")) continue;
|
||||||
|
String keyword = f.getName().replaceFirst("K_", "");
|
||||||
|
if (ReservedKeywords.isReserved(keyword)) continue;
|
||||||
|
|
||||||
|
for (String statement : new String[]{ "DROP USER %s", "DROP IDENTITY %s" })
|
||||||
|
{
|
||||||
|
asserts.assertThat(parses(String.format(statement, keyword)))
|
||||||
|
.describedAs(String.format(statement, keyword))
|
||||||
|
.isTrue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
asserts.assertAll();
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isAllowed(String keyword)
|
private static boolean isAllowed(String keyword)
|
||||||
|
{
|
||||||
|
return parses(String.format("ALTER TABLE ks.t ADD %s TEXT", keyword));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean parses(String cql)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QueryProcessor.parseStatement(String.format("ALTER TABLE ks.t ADD %s TEXT", keyword));
|
QueryProcessor.parseStatement(cql);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (SyntaxException ignore)
|
catch (SyntaxException ignore)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue