Merge branch 'cassandra-4.1' into cassandra-5.0

This commit is contained in:
Stefan Miklosovic 2024-09-24 14:17:08 +02:00
commit e9ea2772dd
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
4 changed files with 35 additions and 25 deletions

View File

@ -10,6 +10,7 @@
* Add java.base/java.lang.reflect among opens for jvm11-client.options (CASSANDRA-19780)
Merged from 4.1:
Merged from 4.0:
* Fix text containing "/*" being interpreted as multiline comment in cqlsh (CASSANDRA-17667)
* Fix indexing of a frozen collection that is the clustering key and reversed (CASSANDRA-19889)
* Emit error when altering a table with non-frozen UDTs with nested non-frozen collections the same way as done upon table creation (CASSANDRA-19925)
* Safer handling of out-of-range tokens (CASSANDRA-13704)

View File

@ -173,7 +173,9 @@ syntax_rules = r'''
<CQL_Statement> ::= [statements]=<statementBody> ";"
;
# the order of these terminal productions is significant:
# The order of these terminal productions is significant. The input string is matched to the rule
# specified first in the grammar.
<endline> ::= /\n/ ;
JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
@ -183,6 +185,12 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
<quotedStringLiteral> ::= /'([^']|'')*'/ ;
<pgStringLiteral> ::= /\$\$(?:(?!\$\$).)*\$\$/;
<quotedName> ::= /"([^"]|"")*"/ ;
<unclosedPgString>::= /\$\$(?:(?!\$\$).)*/ ;
<unclosedString> ::= /'([^']|'')*/ ;
<unclosedName> ::= /"([^"]|"")*/ ;
<unclosedComment> ::= /[/][*].*$/ ;
<float> ::= /-?[0-9]+\.[0-9]+/ ;
<uuid> ::= /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ ;
<blobLiteral> ::= /0x[0-9a-f]+/ ;
@ -200,11 +208,6 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
| "false"
;
<unclosedPgString>::= /\$\$(?:(?!\$\$).)*/ ;
<unclosedString> ::= /'([^']|'')*/ ;
<unclosedName> ::= /"([^"]|"")*/ ;
<unclosedComment> ::= /[/][*].*$/ ;
<term> ::= <stringLiteral>
| <integer>
| <float>

View File

@ -433,7 +433,6 @@ class Shell(cmd.Cmd):
self.statement = StringIO()
self.lineno = 1
self.in_comment = False
self.prompt = ''
if stdin is None:
@ -816,29 +815,11 @@ class Shell(cmd.Cmd):
self.reset_statement()
print('')
def strip_comment_blocks(self, statementtext):
comment_block_in_literal_string = re.search('["].*[/][*].*[*][/].*["]', statementtext)
if not comment_block_in_literal_string:
result = re.sub('[/][*].*[*][/]', "", statementtext)
if '*/' in result and '/*' not in result and not self.in_comment:
raise SyntaxError("Encountered comment block terminator without being in comment block")
if '/*' in result:
result = re.sub('[/][*].*', "", result)
self.in_comment = True
if '*/' in result:
result = re.sub('.*[*][/]', "", result)
self.in_comment = False
if self.in_comment and not re.findall('[/][*]|[*][/]', statementtext):
result = ''
return result
return statementtext
def onecmd(self, statementtext):
"""
Returns true if the statement is complete and was handled (meaning it
can be reset).
"""
statementtext = self.strip_comment_blocks(statementtext)
try:
statements, endtoken_escaped = cqlruleset.cql_split_statements(statementtext)
except pylexotron.LexingError as e:

View File

@ -771,6 +771,31 @@ class TestCqlParsing(TestCase):
('"/*MyTable*/"', 'quotedName'),
(';', 'endtoken')])
parsed = parse_cqlsh_statements('''
INSERT into a (key,c1,c2) VALUES ('aKey','v1*/','/v2/*/v3');
''')
self.assertSequenceEqual(tokens_with_types(parsed),
[('INSERT', 'reserved_identifier'),
('into', 'reserved_identifier'),
('a', 'identifier'),
('(', 'op'),
('key', 'identifier'),
(',', 'op'),
('c1', 'identifier'),
(',', 'op'),
('c2', 'identifier'),
(')', 'op'),
('VALUES', 'identifier'),
('(', 'op'),
("'aKey'", 'quotedStringLiteral'),
(',', 'op'),
("'v1*/'", 'quotedStringLiteral'),
(',', 'op'),
("'/v2/*/v3'", 'quotedStringLiteral'),
(')', 'op'),
(';', 'endtoken')])
parse_cqlsh_statements('''
*/ SELECT FROM "MyTable";
''')