Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pylib/cqlshlib/cql3handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def dequote_value(cqlword):
| <createFunctionStatement>
| <createAggregateStatement>
| <createTriggerStatement>
| <addIdentityStatement>
| <dropKeyspaceStatement>
| <dropColumnFamilyStatement>
| <dropIndexStatement>
Expand All @@ -294,6 +295,7 @@ def dequote_value(cqlword):
| <dropFunctionStatement>
| <dropAggregateStatement>
| <dropTriggerStatement>
| <dropIdentityStatement>
| <alterTableStatement>
| <alterKeyspaceStatement>
| <alterUserTypeStatement>
Expand Down Expand Up @@ -1749,6 +1751,7 @@ def rolename_completer(ctxt, cass):
"ON" cf=<columnFamilyName>
;
'''

explain_completion('createTriggerStatement', 'class', '\'fully qualified class name\'')


Expand All @@ -1765,6 +1768,14 @@ def drop_trigger_completer(ctxt, cass):
return list(map(maybe_escape_name, names))


syntax_rules += r'''
<addIdentityStatement> ::= "ADD" "USER" ("IF" "NOT" "EXISTS")? <stringLiteral>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the statement is ADD IDENTITY IF NOT EXISTS '<identity>' TO ROLE '<role>' similarly for drop statement.

Copy link
Author

@shalnisundram shalnisundram Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Changes also reflected in test file
Let me know if a grammar should be expressed specifically for identity instead of using stringliteral

"TO" "ROLE" <rolename>
;
<dropIdentityStatement> ::= "DROP" "USER" ("IF" "EXISTS")? <stringLiteral>
;
'''

# END SYNTAX/COMPLETION RULE DEFINITIONS

CqlRuleSet.append_rules(syntax_rules)
72 changes: 72 additions & 0 deletions pylib/cqlshlib/test/test_identity_mappings_completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .test_cqlsh_completion import CqlshCompletionCase


class TestIdentityMappingsCompletion(CqlshCompletionCase):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I like the fact that we are splitting it into a new test file, I see that the pattern is to have them all consolidated in test_cqlsh_completion.py (that would have helped catching the DROP completion test duplication).

I think we should add these tests there to follow the existing pattern, and maybe start a conversation on the dev slack (or Mailing list?) about splitting the completion tests (right now, a python file of 1242 lines and counting).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree here with Bernardo. We should probably try to consolidate the testing logic in test_cqlsh_completion.py. I think some existing autocompletion test scenarios will fail in test_cqlsh_completion.py.

I don't think we need a mailing list discussion for this change, I think it's pretty straightforward to make the change in test_cqlsh_completion.py, and we shouldn't really think too much about it.

Copy link
Author

@shalnisundram shalnisundram Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK - identity mapping test file deleted in latest commit. Tests consolidated into test_cqlsh_completion.py. New tests are TestCqlshCompletion:test_complete_in_add_identity and TestCqlshCompletion: test_complete_in_drop_identity. Fixes made to other existing tests in this file to account for IDENTITY addition.


"""
Autcomplete Tests for ADD and DROP Identity Mappings for @cql3handling.py
"""

def add_test_user_autocomplete(self):
self.trycompletions('ADD U', immediate='SER ')


def add_test_exists_autocomplete(self):
self.trycompletions('ADD USER IF ', immediate='NOT EXISTS ')
self.trycompletions('ADD USER IF NOT ', immediate='EXISTS ')

def test_expect_str_literal_add_autocomplete(self):
self.trycompletions('ADD USER ',
choices=['<pgStringLiteral>', '<quotedStringLiteral>', 'IF'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.trycompletions('ADD IDENTITY IF NOT EXISTS',
            choices=['<pgStringLiteral>', '<quotedStringLiteral>'])

?

Copy link
Author

@shalnisundram shalnisundram Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pgStringLiteral and quotedStringLiteral are choices that autocomplete upon TAB after IDENTITY. This is for the user to check the type for their string when defining an IDENTITY.
This test can now be found in test_cqlsh_completion.py test_complete_in_add_identity, on line 1224.


def add_test_to_autocomplete(self):
self.trycompletions("ADD USER '[email protected]' ", immediate='TO ')
self.trycompletions("ADD USER '[email protected]' T", immediate='O ')

def add_test_role_autocomplete(self):
self.trycompletions("ADD USER '[email protected]' TO ", immediate='ROLE ')
self.trycompletions("ADD USER '[email protected]' TO R", immediate='OLE ')

def add_test_rolename_autocomplete(self):
self.trycompletions("ADD USER '[email protected]' TO ROLE ",
choices=['<identifier>', '<quotedName>'],
other_choices_ok=True)

def add_test_complete_user_full_statement(self):
self.trycompletions("ADD USER IF NOT EXISTS '[email protected]' TO ROLE data_engineer ",
choices=[';'])

def drop_test_autocomplete(self):
self.trycompletions('DROP ',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah! This is the same we are testing here
https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/test/test_cqlsh_completion.py#L615-L618

I wonder then why that one is not failing. I think we should consolidate those.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

choices=['AGGREGATE', 'COLUMNFAMILY', 'FUNCTION',
'INDEX', 'KEYSPACE', 'ROLE', 'TABLE',
'TRIGGER', 'TYPE', 'USER', 'MATERIALIZED'])

def drop_test_user_autcomplete(self):
self.trycompletions('DROP USER ',
choices=['<pgStringLiteral>', '<quotedStringLiteral>', 'IF'])

def drop_test_exists(self):
self.trycompletions('DROP USER IF ', immediate='EXISTS ')
self.trycompletions('DROP USER IF EXISTS ',
choices=['<pgStringLiteral>', '<quotedStringLiteral>'])

def test_complete_drop_user_statement_end(self):
self.trycompletions("DROP USER '[email protected]' ", choices=[';'])
self.trycompletions("DROP USER IF EXISTS '[email protected]' ", choices=[';'])