Skip to content

Extend sanitiseRow to recurse into arrays of structs#2599

Merged
johngrimes merged 4 commits into
release/9.7.0from
issue/2592
May 22, 2026
Merged

Extend sanitiseRow to recurse into arrays of structs#2599
johngrimes merged 4 commits into
release/9.7.0from
issue/2592

Conversation

@piotrszul
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes fhirpath-lab-api: sanitiseRow does not recurse into arrays of structs #2592: sanitiseRow in SingleInstanceEvaluator fell through to the else branch for scala.collection.Seq values (Spark's representation of array fields), so synthetic fields like _fid and null-valued fields were never stripped from array-of-struct elements
  • Adds a new branch that iterates over Seq elements, recurses into any Row instances, and updates the parent field's ArrayType elementType to the sanitised element schema so Row.json() positional mapping stays correct
  • Adds three new unit tests covering the exact scenario from the issue (CodeableConcept.coding), schema propagation for arrays, and end-to-end JSON output

Test plan

  • SingleInstanceEvaluatorTest$SanitiseRowTests.sanitisesElementsInArrayOfStructs — verifies synthetic and null-valued fields are stripped from array-of-struct elements
  • SingleInstanceEvaluatorTest$SanitiseRowTests.updatesParentSchemaForSanitisedArrayOfStructs — verifies the parent ArrayType elementType is updated after sanitisation
  • SingleInstanceEvaluatorTest$RowToJsonTests.jsonCorrectlyRendersArrayOfStructsAfterSanitisation — verifies the JSON output excludes all synthetic and null-valued fields from array elements
  • All existing SingleInstanceEvaluatorTest tests continue to pass (35/35)

🤖 Generated with Claude Code

@piotrszul
Copy link
Copy Markdown
Collaborator Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@github-project-automation github-project-automation Bot moved this to Backlog in Pathling May 5, 2026
@piotrszul piotrszul moved this from Backlog to In progress in Pathling May 5, 2026
@johngrimes
Copy link
Copy Markdown
Member

@piotrszul Why does this PR include a change to the R library POM?

@johngrimes johngrimes added bug Something isn't working library-api Relating to the library API labels May 8, 2026
@johngrimes johngrimes changed the title fix: Extend sanitiseRow to recurse into arrays of structs Extend sanitiseRow to recurse into arrays of structs May 8, 2026
@johngrimes johngrimes self-assigned this May 8, 2026
@johngrimes
Copy link
Copy Markdown
Member

@piotrszul Are you finished with this?

It looks fine to me, should we merge to release/9.7.0?

piotrszul and others added 3 commits May 18, 2026 19:00
`sanitiseRow` only handled nested `Row` values but fell through for
`scala.collection.Seq` values (how Spark represents array fields), so
synthetic fields like `_fid` and null-valued fields leaked into the JSON
output whenever a FHIRPath expression returned a type containing an
array of structs (e.g. `CodeableConcept.coding`).

Adds a new branch that iterates over `Seq` elements, recursively
sanitises any `Row` elements, and updates the parent field's `ArrayType`
elementType to the sanitised element schema so that `Row.json()`
positional mapping remains correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pre-size the ArrayList with the known sequence length, remove a redundant
what-comment, and extract the shared coding row fixture into a helper to
eliminate copy-paste between two test classes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Locks in that sanitiseRow correctly renders JSON for an array of structs
where elements differ in which fields are null, and therefore have
different post-sanitisation schemas.
@piotrszul piotrszul changed the base branch from main to release/9.7.0 May 19, 2026 11:12
@piotrszul piotrszul requested a review from johngrimes May 19, 2026 11:12
Extract switch-based field dispatch and the array-of-struct branch
into separate helper methods so sanitiseRow itself stays simple and
the type-dispatch chain is expressed as a Java 21 switch expression.
Resolves SonarCloud java:S3776 and java:S6880 findings on
SingleInstanceEvaluator.
@sonarqubecloud
Copy link
Copy Markdown

@johngrimes johngrimes merged commit 4abfd46 into release/9.7.0 May 22, 2026
5 checks passed
@johngrimes johngrimes deleted the issue/2592 branch May 22, 2026 18:25
@github-project-automation github-project-automation Bot moved this from In progress to Done in Pathling May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working library-api Relating to the library API

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fhirpath-lab-api: sanitiseRow does not recurse into arrays of structs

2 participants