-
Notifications
You must be signed in to change notification settings - Fork 475
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
Conversation
37d9352
to
d4dbddd
Compare
d4dbddd
to
9a59c02
Compare
72d4956
to
78a42a0
Compare
Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBTimeWindowResponse.cs
Show resolved
Hide resolved
Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBTimeWindowResponse.cs
Show resolved
Hide resolved
Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBTimeWindowResponse.cs
Outdated
Show resolved
Hide resolved
b1c92b9
to
5498aa3
Compare
|
||
namespace Amazon.Lambda.Serialization.SystemTextJson.Converters | ||
{ | ||
public class LongToStringJsonConverter : JsonConverter<string> |
There was a problem hiding this comment.
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 ofstring
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 theJsonConverter
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.
There was a problem hiding this comment.
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.
8726a45
to
5a89c48
Compare
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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))] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
fd1ed95
to
c749f88
Compare
…son.Serialization.JsonConverter) for non-NetStandard 2.0 target(s) for handling Kinesis and DynamoDB TimeWindowEvent State property.
…s when processing streams for KinesisEvent.
c749f88
to
2dd31a1
Compare
Issue #, if available:
#1538
#1553
Description of changes:
Tumbling Window Events for Kinesis & Dynamo #1538 (commit 78a42a0): Added support for
DynamoDBTimeWindowEvent
andKinesisTimeWindowEvent
.For Java functions, we recommend using a Map<String, String> to represent the state.
. So in the code change,Dictionary<string, string>
type was used. However, Newtonsoft Json deserializer throws error while converting int/long value tostring
key value. Hence, newJsonConverter
was also added inAmazon.Lambda.Serialization.SystemTextJson
(googled around for logic submitted by community).Partial batch failure support with Amazon.Lambda.KinesisEvents #1553 (commit b1c92b9): Added new
StreamsEventResponse
class for reporting batch item failures when processing streams forKinesisEvent
.Reference:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.