Merge branch 'cassandra-5.0' into trunk

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

View File

@ -92,6 +92,7 @@ Merged from 5.0:
* 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

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

View File

@ -346,7 +346,6 @@ class Shell(cmd.Cmd):
self.statement = StringIO()
self.lineno = 1
self.in_comment = False
self.prompt = ''
if stdin is None:
@ -736,29 +735,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 = ruleset.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";
''')