Update Jmespath shape traversal codegen to support multi-select lists following projection expressions #3987
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.
Motivation and Context
Adds support for JMESPath multi-select lists following projection expressions such as
lists.structs[].[optionalInt, requiredInt]
(list projection followed by multi-select lists),lists.structs[<some filter condition>].[optionalInt, requiredInt]
(filter projection followed by multi-select lists), andmaps.*.[optionalInt, requiredInt]
(object projection followed by multi-select lists).Description
This PR adds support for the said functionality. Prior to the PR, the expressions above ended up the codegen either failing to generate code (for list projection) or generating the incorrect Rust code (for filter & object projection).
All the code changes except for
RustJmespathShapeTraversalGenerator.kt
are primarily adjusting the existing code based on the updates made toRustJmespathShapeTraversalGenerator.kt
.The gist of the code changes in
RustJmespathShapeTraversalGenerator.kt
is as follows:generateProjection
now supportsMultiSelectListExpression
on the right-hand side (RHS).MultiSelectListExpression
on RHS, themap
function applied to the result of the left-hand side of a projection expression (regardless of whether it's list, filter, or object projection) returned a typeOption<Vec<&T>>
, and themap
function body used the?
operator to return early as soon as it encountered a field value that wasNone
. That did not yield the desired behavior. Given the snippetlists.structs[].[optionalInt, requiredInt]
in theMotivation and Context
above for instance, themap
function used to look like this:This meant if the
optional_int
in aStruct
wasNone
, we lost the chance to access therequired_int
field when we should've. Instead, themap
function now looks like:This way, the
map
function body has a chance to access all the fields ofStruct
even when any of the optional fields in aStruct
isNone
.map
function above,generate*Projection
functions have adjusted their implementations (such as preserving the output type of the whole projection expression and performing additional flattening forOption
s).Note that the output type of the whole projection expression stays the same before and after this PR; it's just that the inner
map
function used by the projection expression has been tweaked.Testing
RustJmespathShapeTraversalGeneratorTest.kt
.Items[*].[A.Name, B.Name, C.Name, D.Name][]
generated the expected Rust code and behaved as expected.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.