feat: Implement %rowIndex environment variable#2573
Open
Conversation
…Each/forEachOrNull Add support for the %rowIndex environment variable as defined in the SQL on FHIR ViewDefinition spec. Within forEach and forEachOrNull iterations, %rowIndex resolves to the 0-based index of the current element. At the top level (no iteration), it evaluates to 0. Each nesting level maintains independent %rowIndex values. The implementation uses Spark's indexed transform(array, (elem, idx) ->) to track element positions during unnesting, threading the index through ProjectionContext into the FHIRPath evaluation as a supplied variable. Closes #2560 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
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
%rowIndexenvironment variable for ViewDefinitionforEachandforEachOrNulliterations, as defined in the SQL on FHIR ViewDefinition spec.%rowIndexprovides the 0-based index of the current element within the iterated collection. At the top level (no iteration), it evaluates to0. Each nesting level maintains independent values.transform(array, (element, index) -> ...)to track element positions during unnesting, threading the index throughProjectionContextinto FHIRPath evaluation as a supplied variable.Key changes
ColumnRepresentationtransformWithIndex()using Spark's indexed transformSingleResourceEvaluatorwithVariable()for creating evaluators with additional variablesProjectionContextrowIndexfield,withRowIndex(), and%rowIndexinjection inevalExpression()UnnestingSelectionevaluate()to use indexed transform, passing element index as%rowIndexTest coverage (8 test cases in
viewTests/rowindex.json)unionAllwith inherited/independent indices%rowIndexdefaults to0forEachandforEachOrNullwith%rowIndexforEachOrNullwith empty collection (null row)%rowIndex + 1)Test plan
%rowIndextests pass viaFhirViewExtraTestFhirViewExecutorTest+FhirViewBuilderUnitTesttests passCloses #2560
🤖 Generated with Claude Code