Skip to content

Conversation

shalnisundram
Copy link

Add support for keyword autocompletion following ADD and DROP in cqlsh.

This change adds the IdentityStatement grammars needed in cql3handling.py in order to support keyword suggestions upon for identity assignments and drops. Accompanying test suite included.

See original CASSANDRA-20021 JIRA ticket for commit history and example functionality.

patch by Shalni Sundram

Copy link
Contributor

@sarankk sarankk left a comment

Choose a reason for hiding this comment

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

Thanks Shalni for the patch.



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


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.

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.

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 ",

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.

@bbotella
Copy link
Contributor

bbotella commented Oct 3, 2025

And thanks for the contribution @shalnisundram! These UX improvements are a huge benefit that enhance usability and discoverability of everything Cassandra has to offer.

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

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

Looking good so far. I left a few additional comments

Copy link
Contributor

@frankgh frankgh left a comment

Choose a reason for hiding this comment

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

+1 thanks for the fix!

@bbotella
Copy link
Contributor

bbotella commented Oct 8, 2025

+1 pending on CI. Thanks!

@frankgh
Copy link
Contributor

frankgh commented Oct 13, 2025

Closed via accdaae

@frankgh frankgh closed this Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants