Merge branch 'cassandra-4.0' into cassandra-4.1

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

View File

@ -1,5 +1,6 @@
4.1.7
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

@ -520,7 +520,6 @@ class Shell(cmd.Cmd):
self.statement = StringIO()
self.lineno = 1
self.in_comment = False
self.prompt = ''
if stdin is None:
@ -896,29 +895,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

@ -165,7 +165,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]|$)|[/][*].*?[*][/])/ ;
@ -175,6 +177,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]+/ ;
@ -192,11 +200,6 @@ JUNK ::= /([ \t\r\f\v]+|(--|[/][/])[^\n\r]*([\n\r]|$)|[/][*].*?[*][/])/ ;
| "false"
;
<unclosedPgString>::= /\$\$(?:(?!\$\$).)*/ ;
<unclosedString> ::= /'([^']|'')*/ ;
<unclosedName> ::= /"([^"]|"")*/ ;
<unclosedComment> ::= /[/][*].*$/ ;
<term> ::= <stringLiteral>
| <integer>
| <float>

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";
''')