feat(sof): sync upstream tests, implement %rowIndex, MongoDB conformance parity#178
Open
smunini wants to merge 2 commits into
Open
feat(sof): sync upstream tests, implement %rowIndex, MongoDB conformance parity#178smunini wants to merge 2 commits into
smunini wants to merge 2 commits into
Conversation
…nce parity Sync the SQL-on-FHIR v2 conformance fixtures from the relocated upstream (FHIR/sql-on-fhir.js) verbatim — including the new row_index.json — implement the %rowIndex environment variable across every SOF execution engine, and bring the MongoDB in-DB runner to full conformance parity with SQLite/PostgreSQL. Test fixtures - Resync all 22 fixtures byte-for-byte from upstream main + add row_index.json. - README documents the upstream source and verbatim-sync policy. - Make the in-memory runners tolerate a missing top-level fhirVersion (constant_types.json dropped it) and compare rows order-insensitively, matching the upstream compliance runner. %rowIndex - Primary engine (run_view_definition): default 0; per-iteration index threaded through forEach/forEachOrNull (enumerate) and repeat (pre-order flatten). S3 (in-process) and Elasticsearch inherit this. All 144 in-memory fixtures pass. - In-DB SQLite/PostgreSQL compiler: json_each.key / WITH ORDINALITY for forEach, a pre-order ord_path ranked with DENSE_RANK in the repeat CTE. - Fix second-precision (HH:MM:SS) and full-precision time boundary in the in-DB emitter (surfaced by the synced fn_boundary data). - Drop the obsolete row_index KNOWN_SKIPS; raise SQLite/PG PASS_FLOOR 124 -> 132. MongoDB in-DB runner: 59 -> 132 (parity) - Array-guarded [n]/.first(); three-valued comparison (null, not false). - unionAll via $facet; where()/extension via $filter with a scoped $$var; join() and collection columns via $reduce; date/time/dateTime/decimal boundary. - repeat: via a server-side-JS $function pre-order traversal + $unwind. - Coerce serde_json arbitrary_precision number wrappers (stored as objects by bson::to_bson) to real numbers in comparison/arithmetic/boundary, preserving the wrapper's digit-string for decimal-boundary precision. - Flattened trailing-[N] forEach (contact.telecom[0]) compiles to a single full-path unnest flattened before indexing. - New testcontainers suite crates/rest/tests/sof_conformance_mongodb.rs (floor 132); the remaining 12 failures are the structural gaps shared with SQLite/PG (nested/sibling repeat, unionAll nested in another select). Note: repeat: on MongoDB requires server-side JavaScript ($function).
The synced constant_types.json drops the top-level `fhirVersion` field (upstream treats absence as "all versions"). Two more test parsers still required it and panicked on parse — `test_base64_binary_constant.rs` (loads constant_types.json directly) and, defensively, `run_foreach_tests.rs`. Make their `fhirVersion` optional like the other conformance runners.
Code reviewOne documentation discrepancy found. Checked for bugs and CLAUDE.md compliance. README floor out of sync with test fileFile: hfs/crates/sof/tests/sql-on-fhir-v2/README.md Lines 32 to 34 in 908b2d6 The README describes the MongoDB conformance suite as having floor 59 and lists
But the same PR sets Suggested fix: replace lines 32–34 with: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
Brings the SQL-on-FHIR implementation up to date with the relocated upstream test suite and closes the
%rowIndexgap that showed red on https://sql-on-fhir.org/extra/impls.html, then brings the MongoDB in-DB runner to full conformance parity with SQLite/PostgreSQL.Three threads, delivered together because they're interdependent:
1. Sync the upstream conformance fixtures
FHIR/sql-on-fhir.js. Resynced all 22 fixtures verbatim + added the newrow_index.json(9 cases).crates/sof/tests/sql-on-fhir-v2/README.mddocuments the upstream source + verbatim-sync policy.fhirVersion(constant_types.jsondropped it) and compare rows order-insensitively, matching the upstream compliance runner.2. Implement
%rowIndexacross every SOF enginerun_view_definition, used by sof-cli/sof-server, S3 in-process, ES): per-iteration index forforEach/forEachOrNull/repeat; 144/144 in-memory fixtures pass.json_each.key/WITH ORDINALITYforforEach; pre-orderord_path+DENSE_RANKin the repeat CTE. Verified against real Postgres via testcontainers.highBoundary()/lowBoundary()in the in-DB emitter (surfaced by the syncedfn_boundarydata).row_indexKNOWN_SKIPS; raised SQLite/PGPASS_FLOOR124 → 132.3. MongoDB in-DB runner: 59 → 132 (parity)
New
crates/rest/tests/sof_conformance_mongodb.rs(testcontainers, floor 132). Emitter work:[n]/.first(); three-valued comparison (null, notfalse).unionAllvia$facet;where()/extension()via$filterwith a scoped$$var;join()+ collection columns via$reduce; date/time/dateTime/decimal boundary.repeat:via a server-side-JS$functionpre-order traversal +$unwind.arbitrary_precisionnumber wrappers (whichbson::to_bsonstores as objects) to real numbers in comparison/arithmetic/boundary, preserving the digit-string for decimal-boundary precision.[N]forEach(contact.telecom[0]) → single full-path unnest, flattened before indexing.The 12 remaining MongoDB failures are the identical structural gaps SQLite/PG also fail (nested/sibling
repeat,unionAllnested inside anotherselect).Verification
cargo fmt; clippy clean under CI flagsNote
repeat:on MongoDB relies on server-side JavaScript ($function) — enabled by default, but disabled in some hardened/Atlas configs, whererepeat:views would fail at runtime. Everything else uses native aggregation operators.