Repository navigation
fix(plugin-cassandra): browse, page and filter tables in CQL the plugin runs, and bind values by column type - #3164
Merged
Conversation
…s not have Signed-off-by: Yordis Prieto <[email protected]>
# Conflicts: # CHANGELOG.md
…in runs, and bind values by column type
…type, read whole results, and split CQL batches correctly
…unapplied inserts, and hand plugins changes in edit order
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md # TablePro/Resources/Localizable.xcstrings
4 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
OFFSEThandling in #960 and never took over browse building, so the app's generic SQL builder wroteSELECT … LIMIT n OFFSET m. No CQL engine hasOFFSET. The same builder also wroteORDER BYandWHEREclauses 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 (LIMITappended afterALLOW FILTERING, which is a syntax error), into Fetch All andCOUNT(*), and into v0.76.0 users, who would have stayed broken. That ceiling is gone.PaginationCapability.leadingRowsOnlynow 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:
ALLOW FILTERINGmust be the last clause.ORDER BYfails on every browse that does not pin the partition key.!=,IS NULL,OR,NOT IN,BETWEENandESCAPEdo not exist. uuid literals are unquoted.LIMITdoes not boundCOUNT(*)(CASSANDRA-8216). The plugin's "bounded"COUNT(*) … LIMIT 100001was a full scan, and so was the app's automatic count.cass_statement_bind_stringinto a non-text column returnsCASS_ERROR_LIB_INVALID_VALUE_TYPEand 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 withInvalid 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.
buildBrowseQueryandbuildFilteredQueryreturn 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 aSELECT. This is the pattern Spanner, DynamoDB and Etcd already use.cancelQuery) ends the walk between pages.WHERE … ALLOW FILTERINGwith bind markers. Anything CQL cannot say is refused with a message naming it: the operators above, Match Any, and sort. It is never sent.CassandraStatementBinderconverts 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 anddurationare refused by name. Row writes use it too.LIKEpatterns escape%,_and\. ScyllaDB treats_as a wildcard and honours backslash escapes; both were measured.cass_future_wait_timedand frees the future. The Swift task no longer sits incass_future_waitfor up to 30 seconds.decimalandvarintdisplay 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.PluginDefaultSortProvider).fetchExactRowCountruns the CQL count, and the hidden count infetchTableMetadatais gone.App.
PaginationCapability.resolved(pluginBuildsBrowse:)decides how the table pages.LIMIT nwith noOFFSETand reads the leading rows. That table opens instead of failing until the plugin is updated.LeadingRowsStatementleaves user CQL alone.exactRowCountIsBilledScanis renamedexactRowCountIsFullScanand set for Cassandra and ScyllaDB. Counts run only on request and only through the driver, never the hostCOUNT(*), which cannot express a CQL filter.supportsColumnSortandsupportsMatchAnyFilters, are declared once in a shared Cassandra ingredient for both snapshots and carried over when the plugin registers.ORDER BY.Behaviour change, deliberate. Once the plugin builds queries,
resolveTableEditabilitytreats 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:
LIKEwildcards.Codex's adversarial pass then raised 7 findings (2 critical, 4 high, 1 medium). All 7 are fixed:
timekeys.timeshows every digit it holds. Truncated to milliseconds, atimeprimary key bound back as a different key.SELECTstatement clears them. A resumed walk the server refuses is retried once from the start.COUNT(*), as before. Only a driver that does build them is the sole count.A third Codex pass, against
main, raised 2 findings. Both are fixed:Hashablevalue, 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
swift testpasses). They cover:ALLOW FILTERINGlast, a comment terminator in a value, round-trip, every refusal.timetext round-trips.LeadingRowsStatement.libcassandra.apassed every check against Cassandra 5.0.9 and ScyllaDB 2026.3.1:INandBETWEENon a second page, and filtered and unfiltered counts.LIKEmatching a literal_and%.time23:59:59.123456789changes that row and creates no second one.duration, tuple and float vector display.INwithORDER BY.BATCHrun as one statement.CassandraDriverand theAllPluginsaggregate 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.
generateRowWrites), one statement per row named by its whole primary key.ORand parenthesised groups, which CQL rejects. It now sends oneDELETEeach.INSERT … IF NOT EXISTS, and[applied] = falseis reported as "a row with this primary key already exists". Before, it silently replaced the existing row.now(),uuid()and the other CQL time functions are written as calls.{field: value}.durationshows in Cassandra's own spelling (1d2h); it used to read as NULL.().vectorshows as a list of numbers. The measured class name isVectorType(…FloatType , 2), with a space before the comma.executepages 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,INwithORDER BY, falls back to unpaged. A capped read streams and stops at the cap.StructureObjectEditMatrix.cassandraoffers adding and dropping a column only. Nullable and Comment are gone, since CQL has neither.schemaOperationRefusalnames anything else.USING 'class'; it used to paste the options map.frozen<map<text, int>>whole.BATCH. A new grammar-only fact,.cqlBatches(no PluginKit change), and aCQLBatchTrackerkeep aBEGIN [UNLOGGED|COUNTER] BATCH … APPLY BATCHwhole in the editor, in run-statement-at-cursor and in SQL import. The classifier tiers a batch by its worst inner statement.caseswallowing the next statement.;inside a string runs as one statement on all three servers.cassandra.mdxnow says UDFs and UDAs appear under Functions.sequence), the waySQLStatementGeneratoralready reads them.PendingChangesswap-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:
generateIdentityPreservingInsert.INSERT … IF NOT EXISTSon a taken key is refused.