feat: Implement %rowIndex environment variable#2573
Open
piotrszul wants to merge 6 commits intorelease/9.6.0from
Open
feat: Implement %rowIndex environment variable#2573piotrszul wants to merge 6 commits intorelease/9.6.0from
piotrszul wants to merge 6 commits intorelease/9.6.0from
Conversation
Member
|
…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>
…eat clause Adds support for %rowIndex within the repeat directive, producing a global 0-based traversal-order index across all depth levels of the flattened recursive tree. Each repeat directive scopes its own counter independently from enclosing or nested forEach/forEachOrNull/repeat directives. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rning Replace lazy ThreadLocal initialization with eager init and readObject() to eliminate a race condition when the instance is shared across threads via Spark's addReferenceObj(). Suppress S5164 (ThreadLocal.remove()) with documentation explaining why removal is unnecessary. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nt values Split RowCounter into separate read (RowCounterGet) and increment (RowCounterIncrement) operations so that multiple references to %rowIndex within the same repeat element all read the same value. Previously each reference independently called getAndIncrement(), causing N references to consume N counter values per element instead of one. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
RowCounter (getAndIncrement per evaluation) is superseded by the RowCounterGet + RowCounterIncrement split. Remove the old expression, its ValueFunctions helper, the getAndIncrement method, and the four encoder-level tests that exercised it. The equivalent behavior is now tested via ViewDefinition-level tests in rowindex.json. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover the 13 new lines flagged by SonarCloud as uncovered: all methods on RowIndexCounter (get, increment, reset, serialization) and the three ValueFunctions entry points (rowCounterGet, rowCounterIncrement, resetCounter) exercised via a Spark dataset test in both codegen and interpreted modes. 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
Implement
%rowIndexenvironment variable for ViewDefinition iterations, 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.forEach / forEachOrNull support
Uses Spark's indexed
transform(array, (element, index) -> ...)to track element positions during unnesting, threading the index throughProjectionContextinto FHIRPath evaluation as a supplied variable.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%rowIndexrepeat support
Implements
%rowIndexforrepeatclauses using aRowIndexCounterthat assigns monotonically increasing indices across breadth-first iteration levels, resetting per resource. This required new encoder-level support for injecting index values during repeat expansion.RowIndexCounterValueFunctionswithRowIndex()UDF that pairs each element with its assigned indexExpressions.scalarepeatWithRowIndex()that threadsRowIndexCounterthrough the repeat expansion loopRepeatSelectionrepeatWithRowIndex()and pass index intoProjectionContextExpressionsBothModesTestrepeatWithRowIndex()covering linear chains, branching trees, and counter resetTest coverage (15 test cases in
viewTests/rowindex.json)forEach / forEachOrNull (8 tests):
unionAllwith inherited/independent indices%rowIndexdefaults to0forEachandforEachOrNullwith%rowIndexforEachwith independent%rowIndexvaluesforEachOrNullwith empty collection (null row)%rowIndex + 1)repeat (7 tests):
%rowIndexforEach(independent indices)forEach(independent indices)Test plan
%rowIndextests pass viaFhirViewExtraTestFhirViewExecutorTest+FhirViewBuilderUnitTesttests passExpressionsBothModesTestunit tests pass for repeat index logic@SuppressWarningsannotationCloses #2560
🤖 Generated with Claude Code