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>'])

?

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.

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?

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.

@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.

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