CQL
Cassandra-compatible native protocol syntax and MTS extensions.
Reference
CQL syntax reference
CQL is the default native-protocol mode. Existing Cassandra-compatible drivers can connect to the MTS native protocol endpoint and use CQL syntax plus admitted MTS extensions.
Session and namespace
SHOW SESSION;
SET mts.dialect = 'cql';
CREATE KEYSPACE IF NOT EXISTS app
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE app;
Tables and scalar data
CREATE TABLE IF NOT EXISTS app.events (
tenant text,
id text,
status text,
created_at bigint,
body text,
doc document,
embedding vector<float, 2>,
PRIMARY KEY (tenant, id)
);
INSERT INTO app.events (tenant, id, status, created_at, body, doc, embedding)
VALUES (
'tenant-alpha',
'e1',
'open',
1700000000,
'refund policy changed',
fromJson('{"category":"returns","priority":"high"}'),
[0.0, 0.1]
);
SELECT tenant, id, status, body
FROM app.events
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET status = 'closed'
WHERE tenant = 'tenant-alpha' AND id = 'e1';
DELETE FROM app.events
WHERE tenant = 'tenant-alpha' AND id = 'e1';
CQL prepared statements
prepared = session.prepare(
"SELECT tenant, id, body FROM app.events WHERE tenant = ? AND id = ?"
)
rows = session.execute(prepared, ("tenant-alpha", "e1"))
Scalar and ordered access paths
CREATE INDEX events_tenant_status_time_idx
ON app.events (tenant, status, created_at)
USING 'sis'
WITH OPTIONS = {
'family':'scalar_ordered_composite',
'order':'tenant ASC, status ASC, created_at DESC'
};
WAIT FOR INDEX events_tenant_status_time_idx QUERYABLE TIMEOUT '60 seconds';
SELECT id, status, created_at
FROM app.events
WHERE tenant = 'tenant-alpha'
AND status = 'open'
ORDER BY created_at DESC
LIMIT 50;
Raw text, trigram, and regex-like access paths
CREATE ACCESS PATH events_body_trigram
ON app.events
USING TRIGRAM_TEXT_SIS(body)
WITH (
case_mode = 'ascii_insensitive_v1',
normalization_contract = 'raw_utf8_bytes_v1',
regex_dialect = 'mts_regex_v1'
);
WAIT FOR ACCESS PATH events_body_trigram QUERYABLE TIMEOUT '60 seconds';
SELECT id, body
FROM app.events
WHERE tenant = 'tenant-alpha'
AND body LIKE '%refund%'
LIMIT 20;
Full-text and BM25-style retrieval
CREATE INDEX events_body_fulltext_idx
ON app.events (body AS body)
USING 'sis'
WITH OPTIONS = {
'mode':'FULLTEXT',
'analyzer':'english_v1',
'positions':'true',
'max_indexed_value_bytes':'256'
};
WAIT FOR INDEX events_body_fulltext_idx QUERYABLE TIMEOUT '60 seconds';
SELECT id, body
FROM app.events
WHERE tenant = 'tenant-alpha'
AND body MATCH 'refund policy'
LIMIT 20;
Vector search
CREATE INDEX events_embedding_idx
ON app.events (embedding)
USING 'sis'
WITH OPTIONS = {'search_mode':'exact','budget':'64'};
WAIT FOR INDEX events_embedding_idx QUERYABLE TIMEOUT '60 seconds';
SELECT id, body
FROM app.events
WHERE tenant = 'tenant-alpha'
ORDER BY embedding ANN OF [0.0, 0.1]
WITH (topk = 10)
LIMIT 10;
Document selectors
CREATE INDEX events_doc_category_idx
ON app.events (doc_get_text(doc, '$.category'))
USING 'sis'
WITH OPTIONS = {'family':'auto'};
WAIT FOR INDEX events_doc_category_idx QUERYABLE TIMEOUT '60 seconds';
SELECT id, doc_get_text(doc, '$.category') AS category
FROM app.events
WHERE tenant = 'tenant-alpha'
AND doc_get_text(doc, '$.category') = 'returns'
LIMIT 20;
Supported document projection and predicate helper families include:
| Helper family | Predicate use |
|---|---|
doc_get_text, doc_get_int, doc_get_bigint, doc_get_number | Equality, IN, and bounded ranges when a matching queryable selector exists. |
doc_get_boolean / doc_get_bool | Equality and IN. |
doc_get_vector | ORDER BY doc_get_vector(...) ANN OF ... with a queryable vector selector. |
doc_path_state, doc_is_null, doc_contains_path | Explicit value/null/missing/mismatch/path-existence state checks. |
doc_jsonpath_match, doc_contains | Bounded fixed-shape JSONPath and exact-containment subsets. |
Document mutation functions
Document mutations are UPDATE assignment helpers, not SELECT helpers.
UPDATE app.events
SET doc = DOC_SET(doc, '$.priority', 'critical', true)
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET doc = DOC_DELETE(doc, '$.deprecated')
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET doc = DOC_MERGE_PATCH(doc, fromJson('{"category":"returns","tags":["vip"]}'))
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET doc = DOC_INC(doc, '$.retry_count', 1)
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET doc = DOC_ARRAY_APPEND(doc, '$.tags', 'urgent')
WHERE tenant = 'tenant-alpha' AND id = 'e1';
UPDATE app.events
SET doc = DOC_ARRAY_REMOVE(doc, '$.tags', 'stale')
WHERE tenant = 'tenant-alpha' AND id = 'e1';
Transactions and batches
BEGIN TRANSACTION;
INSERT INTO app.events (tenant, id, status, created_at, body)
VALUES ('tenant-alpha', 'e2', 'open', 1700000100, 'inside txn');
UPDATE app.events
SET status = 'review'
WHERE tenant = 'tenant-alpha' AND id = 'e2';
COMMIT;
BEGIN BATCH
INSERT INTO app.events (tenant, id, status, created_at, body)
VALUES ('tenant-alpha', 'e3', 'open', 1700000200, 'batch one');
INSERT INTO app.events (tenant, id, status, created_at, body)
VALUES ('tenant-alpha', 'e4', 'open', 1700000300, 'batch two');
APPLY BATCH;
CQL diagnostics
EXPLAIN (FORMAT JSON) ADMIT
SELECT id, body
FROM app.events
WHERE tenant = 'tenant-alpha'
AND body MATCH 'refund policy'
LIMIT 10;
ADVISE ACCESS PATH FOR
SELECT id, body
FROM app.events
WHERE tenant = 'tenant-alpha'
AND body MATCH 'refund policy'
LIMIT 10;