Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Right Click on Counter Table - "Update Counters", “Initialise Counter” and another right click to "Reset All Counters" #700

Open
millerjp opened this issue Jan 11, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request right click
Milestone

Comments

@millerjp
Copy link
Contributor

millerjp commented Jan 11, 2025

1 - Right click on a counter table and generate the CQL to increment or decrement selected counter columns by an inputted number (see below for examples)

2 - Right click on counter table and generate CQL to reset ALL counters using the "Delete and Initialize" approach below.
Note: the reason we are only doing the reset ALL counter values as opposed to only resetting individual counter columns is if the user only wants to reset a specific counter value in a table with multiple counter columns its more complex. We will handle this later as another Right Click action.

We need to display a warning when resetting counter values:

⚠️ WARNING: Counter Reset Operation

Resetting counters in a multi-client environment carries risks:
- The reset operation is not atomic
- Other clients may increment/decrement the counter during reset
- The final counter value may be incorrect if concurrent updates occur
- Once reset, there is no way to recover the previous value

Are you sure you want to proceed with resetting this counter?

3 - Right click on a counter table and generate the CQL to initialise a counter or counters. Basically this is just an insert + or - 1 with the PK values (let the user choose the value and the + or -)


Note that counters have several important limitations:

  • Counter columns cannot be part of the primary key
  • All non-counter columns must be part of the primary key
  • Counters cannot be indexed
  • USING TIMESTAMP or USING TTL are not supported
  • Once deleted, counter values should not be reused
  • Counters cannot be set to a specific value directly

Creating Counter Tables

Single Counter Table

CREATE TABLE page_views (
    page_id uuid PRIMARY KEY,
    views counter
);

Multiple Counters Table

CREATE TABLE content_stats (
    content_id uuid PRIMARY KEY,
    likes counter,
    shares counter,
    comments counter
);

Basic Counter Operations

Incrementing by 1

UPDATE page_views 
SET views = views + 1 
WHERE page_id = 123e4567-e89b-12d3-a456-426614174000;

Incrementing by specific amount

UPDATE content_stats 
SET likes = likes + 5,
    shares = shares + 3 
WHERE content_id = 123e4567-e89b-12d3-a456-426614174000;

Decrementing counters

UPDATE content_stats 
SET likes = likes - 2,
    comments = comments - 1 
WHERE content_id = 123e4567-e89b-12d3-a456-426614174000;

Complex Counter Examples

Composite Primary Key with Counter

CREATE TABLE user_activity (
    user_id uuid,
    activity_date date,
    activity_type text,
    count counter,
    PRIMARY KEY ((user_id, activity_date), activity_type)
);

UPDATE user_activity 
SET count = count + 1 
WHERE user_id = 123e4567-e89b-12d3-a456-426614174000 
AND activity_date = '2025-01-11' 
AND activity_type = 'login';

Resetting Counters

Method 1: Delete and Initialize

DELETE FROM page_views 
WHERE page_id = 123e4567-e89b-12d3-a456-426614174000;

UPDATE page_views 
SET views = views + 0 
WHERE page_id = 123e4567-e89b-12d3-a456-426614174000;

Method 2: Subtract Current Value

UPDATE content_stats 
SET likes = likes - 42 
WHERE content_id = 123e4567-e89b-12d3-a456-426614174000;
@millerjp millerjp added enhancement New feature or request right click labels Jan 11, 2025
@millerjp millerjp added this to the RightClick milestone Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Modify Counter Values" and another right click to "Reset All Counters Value" [feat]: Right Click on Counter Table - "Generate Modify Counter Values statment" and another right click to "Generate Reset All Counters Values statement" Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Generate Modify Counter Values statment" and another right click to "Generate Reset All Counters Values statement" [feat]: Right Click on Counter Table - "Generate Modify Counter Values statement" and another right click to "Generate Reset All Counters Values statement" Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Generate Modify Counter Values statement" and another right click to "Generate Reset All Counters Values statement" [feat]: Right Click on Counter Table - "Modify Counter Values statement" and another right click to "Reset All Counters Values" Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Modify Counter Values statement" and another right click to "Reset All Counters Values" [feat]: Right Click on Counter Table - "Modify Counters" and another right click to "Reset All Counters" Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Modify Counters" and another right click to "Reset All Counters" [feat]: Right Click on Counter Table - "Update Counters" and another right click to "Reset All Counters" Jan 11, 2025
@millerjp millerjp changed the title [feat]: Right Click on Counter Table - "Update Counters" and another right click to "Reset All Counters" [feat]: Right Click on Counter Table - "Update Counters", “Initialise Counter” and another right click to "Reset All Counters" Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request right click
Projects
None yet
Development

No branches or pull requests

2 participants