Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for DynamoDBTimeWindowEvent, KinesisTimeWindowEvent and StreamsEventResponse (for KinesisEvent). #1559

Merged
merged 3 commits into from
Sep 1, 2023

Conversation

ashishdhingra
Copy link
Contributor

@ashishdhingra ashishdhingra commented Aug 1, 2023

Issue #, if available:
#1538
#1553

Description of changes:

Reference:


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

@ashishdhingra ashishdhingra marked this pull request as draft August 1, 2023 23:05
@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch from 37d9352 to d4dbddd Compare August 2, 2023 21:07
@ashishdhingra ashishdhingra changed the title Added support for KinesisTimeWindowEvent. Added support for DynamoDBTimeWindowEvent and KinesisTimeWindowEvent. Aug 2, 2023
@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch from d4dbddd to 9a59c02 Compare August 2, 2023 21:15
@ashishdhingra ashishdhingra marked this pull request as ready for review August 2, 2023 21:15
@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch 2 times, most recently from 72d4956 to 78a42a0 Compare August 3, 2023 17:01
@philasmar philasmar self-requested a review August 3, 2023 17:31
@ashishdhingra ashishdhingra changed the title Added support for DynamoDBTimeWindowEvent and KinesisTimeWindowEvent. Added support for DynamoDBTimeWindowEvent, KinesisTimeWindowEvent and StreamsEventResponse (for KinesisEvent). Aug 3, 2023

namespace Amazon.Lambda.Serialization.SystemTextJson.Converters
{
public class LongToStringJsonConverter : JsonConverter<string>
Copy link
Member

Choose a reason for hiding this comment

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

This converter makes me nervous. It will run for every string value that is serialized. Since this is just for the State property for Kinesis we shouldn't add this to the global list of converters we run.

I suggest we:

  • Change the converter to use Dictionary<string, string> instead of string as the generic and then implement for a Dictionary.
  • Rename it to DictionaryLongToStringJsonConverter
  • Instead of adding the converter to the global list decorate the State attributes in the Kinesis POCOs with the JsonConverter attribute. That way this converter is only used on the scenarios where we know the special scenario exists.
  • Update the documentation on the Kinesis POCOs informing users that they are only compatible with the serializers using System.Text.json unless you intend to also write the equivalent for Newtonsoft.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done for most part. I don't think we need to update the documentation (for last point) since it should work.

@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch from 8726a45 to 5a89c48 Compare August 24, 2023 16:50
public override void Write(Utf8JsonWriter writer, Dictionary<string, string> value, JsonSerializerOptions options)
{
// Use the built-in serializer, because it can handle dictionaries with string keys.
JsonSerializer.Serialize(writer, value, options);
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this write the value as a string but given the context of this converter shouldn't it be written as a long?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would. I still haven’t received response from Lambda team. My hunch is that the reason there is a note to use Map<string, string> for Java is that sometimes the state might contain string values. In such case, we would not be sure on whether to convert it to long or string. That’s the reason I’m handling token type string as well in ExtractValue. Please advise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, got response from Lambda team that State field could have values represented as strings and in some cases long.

using System.Collections.Generic;
using System.Runtime.Serialization;

#if !NETSTANDARD2_0
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using the ! operator just say NETCOREAPP_3_1 like every else in our libraries. Pretty soon we will need to do a sweep across all of our libraries to change all references of NETCOREAPP_3_1 to NETCOREAPP3_1_OR_GREATER and it will be easier if we are consistent with are preprocessor usage. I don't want to do that work because I need to double check the .NET SDK version running in the build system to ensure it is new enough that it has the GREATER preprocessor symbols.

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 have changed it to NETCOREAPP3_1_OR_GREATER (else it was failing test case) since test case was having this conditional compilation check. Tested locally.

using System;
using System.Collections.Generic;

#if !NETSTANDARD2_0
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using the ! operator just say NETCOREAPP_3_1 like every else in our libraries. Pretty soon we will need to do a sweep across all of our libraries to change all references of NETCOREAPP_3_1 to NETCOREAPP3_1_OR_GREATER and it will be easier if we are consistent with are preprocessor usage. I don't want to do that work because I need to double check the .NET SDK version running in the build system to ensure it is new enough that it has the GREATER preprocessor symbols.

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 have changed it to NETCOREAPP3_1_OR_GREATER (else it was failing test case) since test case was having this conditional compilation check. Tested locally.

/// <summary>
/// State being built up to this invoke in the time window.
/// </summary>
#if !NETSTANDARD2_0
Copy link
Member

Choose a reason for hiding this comment

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

Instead of using the ! operator just say NETCOREAPP_3_1 like every else in our libraries. Pretty soon we will need to do a sweep across all of our libraries to change all references of NETCOREAPP_3_1 to NETCOREAPP3_1_OR_GREATER and it will be easier if we are consistent with are preprocessor usage. I don't want to do that work because I need to double check the .NET SDK version running in the build system to ensure it is new enough that it has the GREATER preprocessor symbols.

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 have changed it to NETCOREAPP3_1_OR_GREATER (else it was failing test case) since test case was having this conditional compilation check. Tested locally.

[System.Text.Json.Serialization.JsonPropertyName("state")]
#endif
#if !NETSTANDARD2_0
[JsonConverter(typeof(DictionaryLongToStringJsonConverter))]
Copy link
Member

Choose a reason for hiding this comment

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

This can be combined with the previous NETCOREAPP_3_1 condition block.

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 have changed it to NETCOREAPP3_1_OR_GREATER (else it was failing test case) since test case was having this conditional compilation check. Tested locally.

Copy link
Contributor

@philasmar philasmar left a comment

Choose a reason for hiding this comment

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

Approved, assuming you will address Norm's comments.

@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch 2 times, most recently from fd1ed95 to c749f88 Compare August 30, 2023 21:09
…son.Serialization.JsonConverter) for non-NetStandard 2.0 target(s) for handling Kinesis and DynamoDB TimeWindowEvent State property.
@ashishdhingra ashishdhingra force-pushed the user/ashdhin/KinesisTimeWindowEvent branch from c749f88 to 2dd31a1 Compare August 31, 2023 17:02
@ashishdhingra ashishdhingra merged commit 5737503 into dev Sep 1, 2023
3 checks passed
@ashishdhingra ashishdhingra deleted the user/ashdhin/KinesisTimeWindowEvent branch September 1, 2023 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants