-
Notifications
You must be signed in to change notification settings - Fork 3.8k
CASSANDRA-21127: Added user facing docs for accord #4572
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
base: trunk
Are you sure you want to change the base?
Conversation
|
I used AI to help write these docs, and had it create test cases for each example to make sure it actually works. While doing this it found a lot of nice UX or issues; below is the state that it created Accord Future Syntax and Semantic FeaturesThis document tracks CQL transaction syntax and semantic features that are documented or desired but not yet implemented in the current version of Cassandra. These features may be added in future releases. Arithmetic Expressions with Row ReferencesIssue: Row Reference Arithmetic in UPDATE SET ClausesStatus: Not implemented Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
UPDATE users SET balance = user_data.balance - 50 WHERE id = ?;
COMMIT TRANSACTIONError Message: Current Workaround: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
IF user_data.balance > 50 THEN
UPDATE users SET balance = balance - 50 WHERE id = ?;
END IF
COMMIT TRANSACTIONImpact:
Comparing Two Row ReferencesIssue: Comparison Between Two LET VariablesStatus: Not implemented Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET account = (SELECT balance FROM accounts WHERE id = ?);
LET limit = (SELECT max_balance FROM limits WHERE type = 'standard');
IF account.balance < limit.max_balance THEN
UPDATE accounts SET balance = balance + 10 WHERE id = ?;
END IF
COMMIT TRANSACTIONCurrent Workaround: -- Application code:
-- double maxBalance = 1000.00; // Retrieved from limits table
BEGIN TRANSACTION
LET account = (SELECT balance FROM accounts WHERE id = ?);
IF account.balance < ? THEN -- Pass maxBalance
UPDATE accounts SET balance = balance + 10 WHERE id = ?;
END IF
COMMIT TRANSACTIONImpact:
Range Updates and DeletesIssue: Updates or Deletes without Full Primary KeyStatus: Not implemented Description: Example of Unsupported Syntax: BEGIN TRANSACTION
-- Attempting to update all sessions for a user
UPDATE user_sessions
SET status = 'invalidated'
WHERE user_id = ?; -- Missing session_id (clustering key)
COMMIT TRANSACTIONCurrent Workaround: -- Step 1: Query active sessions (outside transaction or in previous step)
-- SELECT session_id FROM user_sessions WHERE user_id = ?;
-- Step 2: Transaction with specific updates
BEGIN TRANSACTION
UPDATE users SET status = 'deactivated' WHERE id = ?;
-- Update known sessions individually
UPDATE user_sessions SET status = 'invalidated' WHERE user_id = ? AND session_id = ?;
UPDATE user_sessions SET status = 'invalidated' WHERE user_id = ? AND session_id = ?;
COMMIT TRANSACTIONImpact:
Arithmetic Expressions with Row References in SELECTIssue: Row Reference Arithmetic in SELECT Return ValuesStatus: Not implemented Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
UPDATE users SET balance = balance - 50 WHERE id = ?;
SELECT user_data.balance, user_data.balance - 50;
COMMIT TRANSACTIONError Message: Current Workaround: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
UPDATE users SET balance = balance - 50 WHERE id = ?;
SELECT user_data.balance;
COMMIT TRANSACTIONImpact:
SELECT with Row Data References PositioningIssue: SELECT with Row References Must Precede ModificationsStatus: Grammar limitation Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
UPDATE users SET balance = balance - 50 WHERE id = ?;
SELECT user_data.balance; -- Error: SELECT with row references after UPDATE
COMMIT TRANSACTIONError Message: Current Workaround: -- Option 1: SELECT before UPDATE
BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
SELECT user_data.balance; -- SELECT before UPDATE
UPDATE users SET balance = balance - 50 WHERE id = ?;
COMMIT TRANSACTION
-- Option 2: Query after transaction commits
BEGIN TRANSACTION
UPDATE users SET balance = balance - 50 WHERE id = ?;
COMMIT TRANSACTION
-- Then query outside transaction:
SELECT balance FROM users WHERE id = ?;Grammar Structure: The grammar does NOT allow SELECT statements after modification statements, even if they are full SELECT statements with FROM clauses. The SELECT position is fixed in the grammar structure. Impact:
Computed LET AssignmentsIssue: LET Assignments with Computed ValuesStatus: Not implemented Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
LET new_balance = user_data.balance - 50; -- Error: computed assignment
LET discount_rate = CASE user_data.tier
WHEN 'gold' THEN 0.10
ELSE 0.0 END; -- Error: CASE expression
UPDATE users SET balance = new_balance WHERE id = ?;
COMMIT TRANSACTIONCurrent Workaround: BEGIN TRANSACTION
LET user_data = (SELECT balance, tier FROM users WHERE id = ?);
-- Compute in the UPDATE statement instead
IF user_data.balance >= 50 THEN
UPDATE users SET balance = balance - 50 WHERE id = ?;
END IF
COMMIT TRANSACTIONImpact:
SELECT After Modification StatementsIssue: SELECT Must Precede All ModificationsStatus: Grammar restriction Description: Example of Unsupported Syntax: BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
UPDATE users SET balance = balance - 50 WHERE id = ?;
-- Error: SELECT after UPDATE not allowed
SELECT user_data.balance, 'Update successful' as message;
COMMIT TRANSACTIONCurrent Workaround: -- Option 1: SELECT before modifications
BEGIN TRANSACTION
LET user_data = (SELECT balance FROM users WHERE id = ?);
SELECT user_data.balance; -- Before UPDATE
UPDATE users SET balance = balance - 50 WHERE id = ?;
COMMIT TRANSACTION
-- Option 2: Query after transaction
BEGIN TRANSACTION
UPDATE users SET balance = balance - 50 WHERE id = ?;
COMMIT TRANSACTION
-- Then query outside:
SELECT balance FROM users WHERE id = ?;Impact:
IN and OR Operators in IF ConditionsIssue: IN and OR Not Supported in Transaction ConditionsStatus: Not implemented Description: Example of Unsupported Syntax (IN): BEGIN TRANSACTION
LET order = (SELECT status FROM orders WHERE order_id = ?);
IF order.status IN ('PENDING', 'PAID') THEN
UPDATE orders SET status = 'CANCELLED' WHERE order_id = ?;
END IF
COMMIT TRANSACTIONError Message: Example of Unsupported Syntax (OR): BEGIN TRANSACTION
LET order = (SELECT status FROM orders WHERE order_id = ?);
IF order.status = 'PENDING' OR order.status = 'PAID' THEN
UPDATE orders SET status = 'CANCELLED' WHERE order_id = ?;
END IF
COMMIT TRANSACTIONError Message: Current Workaround: -- Schema uses integer status codes: 10=PENDING, 20=PAID, 30=SHIPPED, etc.
BEGIN TRANSACTION
LET order = (SELECT status_code FROM orders WHERE order_id = ?);
-- Use range comparison instead of IN/OR
-- status_code <= 20 means PENDING or PAID
IF order.status_code <= 20 THEN
UPDATE orders SET status_code = 99 WHERE order_id = ?; -- 99=CANCELLED
END IF
COMMIT TRANSACTIONImpact:
Grammar Reference: txnConditions returns [List<ConditionStatement.Raw> conditions]
: txnColumnCondition[conditions] ( K_AND txnColumnCondition[conditions] )*
;Code Reference: // TODO: Support for IN, CONTAINS, CONTAINS KEYSummary of LimitationsRow Reference Arithmetic LimitationsWhat Works:
What Doesn't Work:
Parser Status: Future EnhancementsThese features may be added in future Cassandra versions:
Testing NotesAll examples in the Cassandra documentation (doc/modules/cassandra/pages/developing/cql/transactions*.adoc) should only show syntax that currently works. Examples using unsupported syntax have been removed and documented here for future reference. Test classes validating documentation examples:
|
No description provided.