Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
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" "IDENTITY" ("IF" "NOT" "EXISTS")? <stringLiteral>
"TO" "ROLE" <rolename>
;
<dropIdentityStatement> ::= "DROP" "IDENTITY" ("IF" "EXISTS")? <stringLiteral>
;
'''

# END SYNTAX/COMPLETION RULE DEFINITIONS

CqlRuleSet.append_rules(syntax_rules)
71 changes: 71 additions & 0 deletions pylib/cqlshlib/test/test_identity_mappings_completion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# 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 test_identity_autocomplete_add(self):
self.trycompletions('ADD I', immediate='DENTITY ')

def test_exists_autocomplete_add(self):
self.trycompletions('ADD IDENTITY IF ', immediate='NOT EXISTS ')
self.trycompletions('ADD IDENTITY IF NOT ', immediate='EXISTS ')

def test_expect_str_literal_autocomplete_add(self):
self.trycompletions('ADD IDENTITY ',
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 test_TO_autocomplete_add(self):
self.trycompletions("ADD IDENTITY '[email protected]' ", immediate='TO ROLE ')
self.trycompletions("ADD IDENTITY '[email protected]' T", immediate='O ROLE ')

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

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

def test_complete_user_full_statement_add(self):
self.trycompletions("ADD IDENTITY IF NOT EXISTS '[email protected]' TO ROLE data_engineer ",
Copy link
Contributor

Choose a reason for hiding this comment

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

Test the same without "IF NOT EXISTS" maybe?

Copy link
Author

Choose a reason for hiding this comment

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

Good idea - test passing with addition. Can find here:

self.trycompletions("ADD IDENTITY '[email protected]' TO ROLE data_engineer ",

choices=[';'])

def test_autocomplete_drop(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', 'IDENTITY'])

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

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

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