CQL
CQL is translated statement by statement into SQL text and run on the shared SQL engine. The Cassandra wire keeps only the CQL catalog (keyspaces, tables, types) of its own; rows live in ordinary SQL tables. The statement list, system tables, type mapping, TTL columns, roles and tests are documented in Cassandra (CQL) implementation reference; this page describes the rewrite.
Translation path
(source: src/protocol/cassandra/exec.rs, execute_cql, run_sql, exec_select, exec_insert, exec_update, exec_delete, exec_create_table; src/protocol/cassandra/roles.rs, cql_authorize)
Reads of system, system_schema, system_virtual_schema and system_auth tables are answered by the wire before execute_cql and do not become SQL (source: src/protocol/cassandra/mod.rs, handle_query).
Naming and types
A CQL table ks.t is the SQL table ks__t (physical_table_name). CQL types map to SQL column types (text to TEXT, int to INT, timestamp to TIMESTAMPTZ and so on); collections, tuples, user-defined types and vectors are one TEXT column holding JSON. The full table is in the reference (source: src/protocol/cassandra/schema.rs, physical_table_name, type mapping; src/protocol/cassandra/collections.rs).
Statement rewrites
| CQL | SQL sent to the engine |
|---|---|
SELECT |
SELECT [DISTINCT] <expr> AS __c0, ... , <hidden columns> AS __h0, ... FROM ks__t WHERE ..., with ORDER BY and GROUP BY carried over |
INSERT |
INSERT INTO ks__t (...) VALUES (...) ON CONFLICT DO UPDATE SET <non-key columns> = EXCLUDED.<column>, or ON CONFLICT DO NOTHING when only key columns are given; an insert is always an upsert, as in Cassandra |
UPDATE |
INSERT ... ON CONFLICT DO UPDATE SET ..., so an update of a missing row creates it |
DELETE of a row |
DELETE FROM ks__t WHERE <key> |
DELETE of columns or elements |
UPDATE ks__t SET <column> = NULL or the rewritten collection value |
CREATE TABLE |
CREATE TABLE ks__t with mapped column types; the CQL definition is also written to the catalog under __catalog__:cqltable:
|
CREATE INDEX |
SQL index; an SAI index on a vector column is mirrored into the vector service instead |
TRUNCATE |
SQL truncate of ks__t
|
(source: src/protocol/cassandra/exec.rs, exec_select, exec_insert, exec_update, exec_delete, exec_create_table, exec_create_index, exec_truncate, persist_table, coll_assignment)
Details of the rewrite:
-
WHERE.parse_restrictionsreads=,!=,<,>,<=,>=,IN,CONTAINS,CONTAINS KEY,LIKEandIS NOT, on a column, a tuple of columns ortoken(...);check_select_filteringraises Cassandra'sALLOW FILTERINGand partition-key errors before any SQL runs;render_wherewrites the SQL condition (source:src/protocol/cassandra/schema.rs,Restriction,parse_restrictions;src/protocol/cassandra/exec.rs,check_select_filtering,check_restrictions,render_where,coll_where_sql). -
TTL.
USING TTLadds expiry columns on first use, and every read addslive_filter, which hides expired rows and cells (source:src/protocol/cassandra/exec.rs,ensure_ttl_columns,live_filter). -
Collections. An element operation reads the current JSON cell, changes it in the wire, and writes the whole cell back (source:
src/protocol/cassandra/exec.rs,read_collections,coll_assignment). -
Lightweight transactions.
IFconditions are checked by reading the row first, then running the write; the result row reports[applied](source:src/protocol/cassandra/exec.rs,check_lwt_conditions,record_lwt_check,applied_result). -
token(). Tables created by this version carry a hidden token column computed with Murmur3 at write time;token()reads it (source:src/protocol/cassandra/schema.rs,TOKEN_COL;src/protocol/cassandra/exec.rs,row_token;src/protocol/cassandra/token.rs,token_of).
Selector functions
count(*) and count(1), min, max, sum, avg, ttl(col), writetime(col), token(...), similarity_cosine, similarity_euclidean, similarity_dot_product, element selection m['k'], and AS aliases (source: src/protocol/cassandra/exec.rs, exec_select; src/protocol/cassandra/vector.rs, Similarity::from_function).
Work done in the wire after the SQL result returns: similarity functions are computed from hidden vector columns; ORDER BY col ANN OF [...] ranks every matching row exactly (no approximate index); PER PARTITION LIMIT trims rows per partition; paging slices the result (source: src/protocol/cassandra/exec.rs, exec_select, similarity_value).
Errors raised by the rewrite with Cassandra's wording: "Top-K queries can not be run with aggregation", "Use of ANN OF in an ORDER BY clause requires a LIMIT that is not greater than 1000", "PER PARTITION LIMIT must be strictly positive", "ORDER BY is only supported when the partition key is restricted by an EQ or an IN.", and "SELECT JSON is not supported by SynergyDB's CQL interface" (source: src/protocol/cassandra/exec.rs, exec_select).
Not supported
SELECT JSON, INSERT JSON, duration, user-defined functions and aggregates, materialized views and triggers. Other CREATE, DROP, ALTER, GRANT, REVOKE or LIST forms return "X Y is not supported by SynergyDB's CQL interface"; anything unrecognised returns a syntax error "no viable alternative" (source: src/protocol/cassandra/exec.rs, execute_cql, exec_insert, exec_select).
Reachability from SQL
Because rows are in ks__t SQL tables, SQL wires can query CQL data directly; the table name is the physical name, not ks.t (source: src/protocol/cassandra/schema.rs, physical_table_name). Not verified: no test reads CQL-written rows over a SQL wire. JSON-encoded collection columns and the hidden TTL and token columns are visible to SQL as ordinary columns (source: src/protocol/cassandra/exec.rs, ensure_ttl_columns; src/protocol/cassandra/schema.rs, TOKEN_COL).
Tests
Tested by the unit tests in src/protocol/cassandra/ (mod.rs 15, exec.rs 4, schema.rs 4, collections.rs 3, cql.rs 5, roles.rs 2, token.rs 1, vector.rs 1), including ttl_expires_cells_and_rows, keyspaces_are_separate_namespaces and test_sai_vector_index_mirrors_into_vector_service, and by the Cassandra 4.1 differential in the proof pack. tests/protocol_cassandra.rs runs SQL on the engine directly and does not exercise the CQL rewrite (source: the reference, Test coverage).