Skip to content

Conversation

@0marperez
Copy link
Contributor

Issue #

N/A

Description of changes

Adds support for Kotlin maps as JMESPath objects to the keys function

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@0marperez 0marperez added the no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly. label Feb 20, 2025
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@0marperez 0marperez marked this pull request as ready for review February 20, 2025 14:37
@0marperez 0marperez requested a review from a team as a code owner February 20, 2025 14:37
Comment on lines 527 to 528
// TODO: Support maps as objects throughout the visitor
// This visitor assumes JMESPath 'objects' will be classes. DDB assumes JMESPath 'objects' will be maps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a FIXME instead of a TODO? Do we have a backlog item we can link here (SDK-KT-x)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove note about DDB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it should be a FIXME because the JMESPath visitor has been assuming classes > maps so far and we have had no apparent problems. Other services use JMESPath but this is the first instance I've seen of maps being used as objects. It might be a DDB only quirk or an indication that we took the wrong approach to objects

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way it sounds like we need a backlog item for this, to at least investigate the discrepancy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once that investigation is done we can go back and modify/create a comment here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep

// This visitor assumes JMESPath 'objects' will be classes. DDB assumes JMESPath 'objects' will be maps

But change it to mention the discrepancy between the smithy spec and the JMESPath spec for this function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just think every TODO should have an associated backlog task, otherwise it never gets done

}
]
},
KeysFunctionPrimitivesIntegerEquals: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this integer primitives test removed?

Comment on lines 530 to 532
if (this.shape?.targetOrSelf(ctx.model)?.type == ShapeType.MAP) {
"${this.identifier}?.keys?.toList()"
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the map has keys that aren't strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks

// TODO: Support maps as objects throughout the visitor
// This visitor assumes JMESPath 'objects' will be classes. DDB assumes JMESPath 'objects' will be maps
private fun VisitedExpression.getKeys(): String =
if (this.shape?.targetOrSelf(ctx.model)?.type == ShapeType.MAP) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: unnecessary use of this

Comment on lines 25 to 30
@Test
fun testKeysFunctionPrimitivesIntegerEquals() = successTest(
fun testKeysFunctionMapStringEquals() = successTest(
GetFunctionKeysEqualsRequest { name = "test" },
WaitersTestClient::waitUntilKeysFunctionPrimitivesIntegerEquals,
GetFunctionKeysEqualsResponse { primitives = EntityPrimitives { } },
WaitersTestClient::waitUntilKeysFunctionMapStringEquals,
GetFunctionKeysEqualsResponse { maps = EntityMaps { strings = mapOf("key" to "value") } },
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why did we modify this test case instead of creating a new one? Is the previous behavior no longer valid?

Comment on lines 527 to 528
// TODO: Support maps as objects throughout the visitor
// This visitor assumes JMESPath 'objects' will be classes. DDB assumes JMESPath 'objects' will be maps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What does this comment mean? It seems like this visitor now assumes objects can be classes or maps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keys function assumes objects can be classes or maps. The rest of the visitor does not. Hence the comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our internal spec says:

Keys function - return a list of the keys in a map. This is the only supported function but is required for binding to key values.

Do we need to support classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JMESPath spec says

Returns an array containing the keys of the provided object

I guess we can get rid of support for classes if everyone else agrees

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I believe we should support classes and it's an oversight that we didn't support it before. I was just wondering what else is required. Since nothing seems to be required for this getKeys function anymore I think we should move the TODO up to the class level or wherever's more appropriate for the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the class with newer comments, let me know what you think

Comment on lines 527 to 528
// TODO: Support maps as objects throughout the visitor
// This visitor assumes JMESPath 'objects' will be classes. DDB assumes JMESPath 'objects' will be maps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: What's the remaining work to support maps as objects throughout the visitor?

Copy link
Contributor Author

@0marperez 0marperez Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to modify a decent chunk of the visitor. Anything that deals with objects

@github-actions

This comment has been minimized.

Smithy spec: https://smithy.io/2.0/additional-specs/rules-engine/parameters.html#smithy-rules-operationcontextparams-trait
JMESPath spec: https://jmespath.org/specification.html#keys
TODO: Proactively support JMESPath objects as Kotlin maps throughout thr entire visitor if more instances of this behavior start popping up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Proactively" and "if more instances of this behavior start popping up" are inconsistent. To be proactive we would need to identify any gaps and fix them now

@github-actions
Copy link

Affected Artifacts

No artifacts changed size

@0marperez 0marperez merged commit 80d395b into main Feb 25, 2025
16 checks passed
@0marperez 0marperez deleted the fix-acc-id-ep branch February 25, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog Indicates that a changelog entry isn't required for a pull request. Use sparingly.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants