Skip to content

fix(plugin-cassandra): browse, page and filter tables in CQL the plugin runs, and bind values by column type - #3164

Merged
datlechin merged 9 commits into
TableProApp:mainfrom
yordis:yordis/fix-cql-browse-offset
Sep 28, 2026
Merged

datlechin merged 9 commits into
TableProApp:mainfrom
yordis:yordis/fix-cql-browse-offset

Conversation

@yordis

@yordis yordis commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Opening any table on a Cassandra or ScyllaDB connection failed with line 1:NN : Syntax error. This PR started as marking both engines leading-rows-only; after review it reworks the fix so the Cassandra plugin builds and runs its own browse, and it fixes the defects the first version exposed.

Root cause

The Cassandra plugin lost its only OFFSET handling in #960 and never took over browse building, so the app's generic SQL builder wrote SELECT … LIMIT n OFFSET m. No CQL engine has OFFSET. The same builder also wrote ORDER BY and WHERE clauses CQL rejects, so the next sort or filter failed too.

The first version of this PR declared .leadingRowsOnly(maximumRows: 100_000), which means "the server returns at most N rows per statement", which is R2 SQL's ceiling. Cassandra has no ceiling, and the value leaked into table export and transfer (capped at 100,000 rows), into query tabs (LIMIT appended after ALLOW FILTERING, which is a syntax error), into Fetch All and COUNT(*), and into v0.76.0 users, who would have stayed broken. That ceiling is gone. PaginationCapability.leadingRowsOnly now takes an optional ceiling, and Cassandra and ScyllaDB declare .leadingRowsOnly(maximumRows: nil): they cannot skip rows, and they cap nothing.

Measured first

Probed on Cassandra 5.0.9, Cassandra 4.1.12 and ScyllaDB 2026.3.1 with cqlsh, and with the DataStax C driver 2.17.1 we ship:

  • There is no statement form that skips rows. The paging state can be replayed, but reaching row k means walking the pages before it (about 5ms per 1,000 rows on loopback).
  • ALLOW FILTERING must be the last clause. ORDER BY fails on every browse that does not pin the partition key. !=, IS NULL, OR, NOT IN, BETWEEN and ESCAPE do not exist. uuid literals are unquoted.
  • LIMIT does not bound COUNT(*) (CASSANDRA-8216). The plugin's "bounded" COUNT(*) … LIMIT 100001 was a full scan, and so was the app's automatic count.
  • cass_statement_bind_string into a non-text column returns CASS_ERROR_LIB_INVALID_VALUE_TYPE and leaves the slot unset. The driver ignored that result, so Save dropped every edited number, date, UUID and boolean while reporting success, and an update keyed on an int or uuid failed with Invalid unset value.

The fix

Plugin, registry-only. This reaches v0.76.0 users with a plugin release, since main and v0.76.0 both ship kit 33, and PluginKit does not change.

  • buildBrowseQuery and buildFilteredQuery return a readable browse statement. It is the CQL the plugin runs, behind a leading /* TablePro browse {…} */ comment that carries the offset, the limit and the filter values. It still runs as plain CQL anywhere else, and the statement gates read it as a SELECT. This is the pattern Spanner, DynamoDB and Etcd already use.
  • The plugin prepares that CQL and binds values by the prepared statement's own parameter types. It then walks the paging state past the offset, counting rows rather than pages, because ScyllaDB returns filtered pages short. Resume points are cached per exact statement, values and page size, so Next and Previous cost one read. Stop (cancelQuery) ends the walk between pages.
  • Filters render WHERE … ALLOW FILTERING with bind markers. Anything CQL cannot say is refused with a message naming it: the operators above, Match Any, and sort. It is never sent.
  • CassandraStatementBinder converts each value to its column's CQL type (int widths, float/double, boolean, uuid/timeuuid, timestamp, date, time, inet, blob, decimal, varint) and throws on a value that does not parse. Collections, tuples, UDTs and duration are refused by name. Row writes use it too.
  • LIKE patterns escape %, _ and \. ScyllaDB treats _ as a wildcard and honours backslash escapes; both were measured.
  • The same statement pasted into a query tab honours that tab's row cap and reports truncation. A browse streamed to a consumer that leaves stops its walk.
  • A count or a page that is cancelled stops being waited for: the driver polls cass_future_wait_timed and frees the future. The Swift task no longer sits in cass_future_wait for up to 30 seconds.
  • Resume points are keyed by keyspace too, and the last page's paging state is recorded, so the first Next is one read.
  • decimal and varint display as numbers instead of hex. A scale near the 32-bit limits is shown with an exponent instead of being expanded, and an exponent that cannot fit a scale is refused instead of trapping.
  • The default sort is suppressed (PluginDefaultSortProvider). fetchExactRowCount runs the CQL count, and the hidden count in fetchTableMetadata is gone.

App.

  • PaginationCapability.resolved(pluginBuildsBrowse:) decides how the table pages.
    • A plugin that builds its own browse walks to any offset, so the table pages normally.
    • With an older installed Cassandra plugin that leaves the query to the app, the app writes LIMIT n with no OFFSET and reads the leading rows. That table opens instead of failing until the plugin is updated.
    • A real ceiling, R2 SQL's, holds whoever builds the query.
    • Export, table transfer, query tabs and Fetch All see no ceiling, and LeadingRowsStatement leaves user CQL alone.
  • exactRowCountIsBilledScan is renamed exactRowCountIsFullScan and set for Cassandra and ScyllaDB. Counts run only on request and only through the driver, never the host COUNT(*), which cannot express a CQL filter.
  • Two curated capabilities, supportsColumnSort and supportsMatchAnyFilters, are declared once in a shared Cassandra ingredient for both snapshots and carried over when the plugin registers.
    • The table grid gets no sort prototype, no header sort and no header-menu sort.
    • A CQL query result sorts the rows it holds instead of re-running with ORDER BY.
    • A restored or stale sort never reaches the query.
    • The filter bar offers Match all only, and Search All Rows is hidden.
    • A Match Any restored from before is written back as Match All before anything reads it, so the rows, Count Exactly and the cell filters agree.

Behaviour change, deliberate. Once the plugin builds queries, resolveTableEditability treats CQL editor results like the other plugin-browsed engines, so they are read-only. Rows are edited from the table tab. This has its own Changed entry.

Review

Codex reviewed the working tree and raised 10 findings: 2 P1 and 8 P2. All 10 are fixed:

  • The older installed plugin.
  • A resume key missing the keyspace.
  • The row cap on a pasted browse.
  • The stored Match Any.
  • LIKE wildcards.
  • Two decimal traps.
  • The terminal paging state.
  • Count cancellation.
  • Stream abort.

Codex's adversarial pass then raised 7 findings (2 critical, 4 high, 1 medium). All 7 are fixed:

  • Query-tab editability. A query tab on a SQL engine whose plugin builds its own browse never trusts a stored table name. The name came from an earlier result or an older build, and could send edits to a different table.
  • time keys. time shows every digit it holds. Truncated to milliseconds, a time primary key bound back as a different key.
  • Resume points. A browse from row 0 starts a fresh set, and recording a point drops the ones past it. Any non-SELECT statement clears them. A resumed walk the server refuses is retried once from the start.
  • Count Exactly on an older plugin. A driver that does not build its engine's queries is counted by the host's COUNT(*), as before. Only a driver that does build them is the sole count.
  • Cancellation. It now covers PREPARE, the moment before a request is sent, and the moment after it answers.
  • Disconnect. It stops a running walk.
  • Plugin probe cache. The query-building probe is cleared whenever a driver plugin registers or unregisters, so installing the new plugin takes effect without a restart.

A third Codex pass, against main, raised 2 findings. Both are fixed:

  • Text is bound with its byte length, so a value holding U+0000 is not cut short.
  • Resume points are keyed by a structured Hashable value, so two filters whose values join to the same text do not share one.

The review loop stops here.

A separate security review of the branch found nothing that meets the bar. The browse header and the statement gates both end the comment at the first */, every value is bound, and identifiers are quoted.

Verification

  • 693 unit test cases pass across the affected suites, and 338 more across every plugin row-write suite (MongoDB, Redis, Etcd, Elasticsearch, rewind, field absence), plus the TableProCore package tests (the full swift test passes). They cover:
    • The browse renderer: no OFFSET or ORDER BY, ALLOW FILTERING last, a comment terminator in a value, round-trip, every refusal.
    • The value parser for every bound type, plus varint and decimal round-trips.
    • Resume points.
    • Classification of a browse as a read.
    • Curated capabilities surviving plugin registration, and ScyllaDB parity.
    • Row count plan and exact-count routing.
    • Grid column prototype and header menu.
    • Coordinator sort gating for table and query tabs.
    • Default and restored sort.
    • Match Any normalization.
    • Query-tab editability on a plugin-browsed engine.
    • Count routing for new and older plugins.
    • time text round-trips.
    • Resume-point generations.
    • No-ceiling paging for export and LeadingRowsStatement.
  • A live harness built from the real plugin sources and the shipped libcassandra.a passed every check against Cassandra 5.0.9 and ScyllaDB 2026.3.1:
    • The 12 pages of a 12,000-row table match the unpaged read row for row, and the page past the end is handled.
    • Filters, including a uuid filter, IN and BETWEEN on a second page, and filtered and unfiltered counts.
    • On ScyllaDB, LIKE matching a literal _ and %.
    • All three refusals.
    • 16 typed writes read back exactly, and a uuid-keyed update lands.
    • Stop cancels a deep walk, and the connection answers afterwards.
    • Editing a row keyed by time 23:59:59.123456789 changes that row and creates no second one.
    • A text value holding NUL is written whole.
    • A composite-key two-row delete, and a new row on a taken key refused.
    • UDT, duration, tuple and float vector display.
    • 120,000 rows read whole.
    • IN with ORDER BY.
    • A BATCH run as one statement.
    • A bound read capped at 1.
    • An unbound insert on a taken key refused.
    • A deleted row restored.
  • Cassandra 4.1.12 passed the same checks except the paging ones, since its test table was empty.
  • CassandraDriver and the AllPlugins aggregate build. SwiftLint is clean on every changed file, and the docs, test-suite-attribute and iOS isolation checks pass.

UI automation: not added. The flows need a live Cassandra server, and the UI test runner has none. The grid, coordinator and filter-bar gating is covered by unit tests instead.

Also fixed here (found while investigating)

Each of these was verified against the code and, where it could be, on the live servers.

  • Row writes. The Cassandra plugin writes grid saves itself (generateRowWrites), one statement per row named by its whole primary key.
    • Deleting several rows used OR and parenthesised groups, which CQL rejects. It now sends one DELETE each.
    • Add Row is INSERT … IF NOT EXISTS, and [applied] = false is reported as "a row with this primary key already exists". Before, it silently replaced the existing row.
    • Changing a primary key cell, or setting a default CQL doesn't have, is refused by name. now(), uuid() and the other CQL time functions are written as calls.
  • Display.
    • User-defined types show as {field: value}.
    • duration shows in Cassandra's own spelling (1d2h); it used to read as NULL.
    • Tuples show their elements; they used to show ().
    • A float vector shows as a list of numbers. The measured class name is VectorType(…FloatType , 2), with a space before the comma.
    • Any other custom type shows as hex instead of garbled text.
  • Whole results. execute pages through every row instead of silently keeping the first 100,000 (120,000 rows came back in 0.4s). A read the server won't page, IN with ORDER BY, falls back to unpaged. A capped read streams and stops at the cap.
  • Structure tab.
    • A measured StructureObjectEditMatrix.cassandra offers adding and dropping a column only. Nullable and Comment are gone, since CQL has neither.
    • The plugin's flags now match the curated snapshot (no index editing), and schemaOperationRefusal names anything else.
    • ScyllaDB lists functions, aggregates and triggers like Cassandra.
  • DDL that runs.
    • Trigger source is USING 'class'; it used to paste the options map.
    • Function signatures keep frozen<map<text, int>> whole.
    • Keyspace, function, argument and trigger names are quoted.
  • CQL BATCH. A new grammar-only fact, .cqlBatches (no PluginKit change), and a CQLBatchTracker keep a BEGIN [UNLOGGED|COUNTER] BATCH … APPLY BATCH whole in the editor, in run-statement-at-cursor and in SQL import. The classifier tiers a batch by its worst inner statement.
    • This also fixes a column named case swallowing the next statement.
    • Measured: a batch with a ; inside a string runs as one statement on all three servers.
  • Smaller fixes.
    • The SSL hint no longer sends Astra users (who can't connect) to TLS settings.
    • cassandra.mdx now says UDFs and UDAs appear under Functions.
    • The iOS widget maps the five icons its asset catalog already had (ScyllaDB, libSQL, Teradata, Trino, Cloudflare R2 SQL), and the shared map gains ScyllaDB.
    • On a plugin-browsed engine, a table tab resolves its own table instead of the selected tab's.
    • Every plugin engine: the host now hands plugins their row changes in edit order (by sequence), the way SQLStatementGenerator already reads them. PendingChanges swap-removes an undone change, so array order was not edit order. A delete followed by a new row on the same key could run backwards on MongoDB, Redis, DynamoDB and the rest.

Codex reviewed this second batch (its first review of this code) and raised 4 findings. All 4 are fixed:

  • A bound read honours its row cap.
  • Undoing a delete writes the row back through generateIdentityPreservingInsert.
  • An unbound INSERT … IF NOT EXISTS on a taken key is refused.
  • Plugins receive changes in edit order.

@datlechin datlechin changed the title fix(plugin-cassandra): browse tables without an OFFSET, which CQL does not have fix(plugin-cassandra): browse, page and filter tables in CQL the plugin runs, and bind values by column type Sep 28, 2026
@datlechin
datlechin merged commit d3740f8 into TableProApp:main Sep 28, 2026
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.

2 participants