-
Notifications
You must be signed in to change notification settings - Fork 65
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
fix: implement processMap function to MAP structured data #99
base: master
Are you sure you want to change the base?
Conversation
@peacecwz Happy to merge this! Would you mind adding some unit tests? |
@jcustenborder Actually no but I can add some unit tests for the function. I'll update the PR quickly |
@jcustenborder I added test for processMap Is that okay for that? |
@jcustenborder btw If this PR will be merged can you also make a release it? Because I'm using my private artifact. I couldn't run Jenkins pipeline. It uploaded the artifact manually to S3 and deploy it as well but I would like to deploy with confluent-kafka CLI as officially |
@jcustenborder Hey can you check the PR? |
}); | ||
} | ||
|
||
input.put("_headers", headers); |
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 just tested this code because we are running into a similar problem.
It appears to add the extracted values to the new struct field _headers
which you are setting here, creating a nested structure.
So
".header.mappings": "time:INT64:d,time:INT64:h,time:INT64:m"
becomes
"value": {
"_headers" : {
"d" : 1669852804800000000,
"h" : 1669852804800000000,
"m" : 1669852804800000000
}
}
I would have expected a flat structure here (and interestingly also the test you added shows a flat structure).
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.
The test actually doesn't test this correctly.
To have the same behaviour as for Structs (i,e, adding the new fields to the root), this should be:
input.put("_headers", headers); | |
input.putAll(headers); |
Could you fix same issue on the (If not.. I will try to implement
|
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.
See my suggestions to fix the test, because it doesn't test anything now.
And I'd also prefer the transformation to behave similar with Maps (JSON) as with Structs (AVRO), so add the field to the root of the object.
}); | ||
} | ||
|
||
input.put("_headers", headers); |
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.
The test actually doesn't test this correctly.
To have the same behaviour as for Structs (i,e, adding the new fields to the root), this should be:
input.put("_headers", headers); | |
input.putAll(headers); |
@@ -71,4 +68,44 @@ public void apply() throws IOException { | |||
assertStruct(expectedStruct, (Struct) actualRecord.value()); | |||
} | |||
|
|||
@Test | |||
public void applyWithMap() throws IOException { | |||
this.transformation = new HeaderToField.Key<>(); |
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.transformation = new HeaderToField.Key<>(); | |
this.transformation = new HeaderToField.Value<>(); |
ConnectHeaders inputHeaders = new ConnectHeaders(); | ||
inputHeaders.addString("applicationId", "testing"); | ||
|
||
Schema inputSchema = SchemaBuilder.map(SchemaBuilder.STRING_SCHEMA, SchemaBuilder.OPTIONAL_STRING_SCHEMA) |
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.
Schema inputSchema = SchemaBuilder.map(SchemaBuilder.STRING_SCHEMA, SchemaBuilder.OPTIONAL_STRING_SCHEMA) | |
Map<String, Object> inputSchema = new HashMap<>(); | |
value.put("firstName", "example"); | |
value.put("lastName", "user"); |
|
||
SinkRecord actualRecord = this.transformation.apply(inputRecord); | ||
assertNotNull(actualRecord, "record should not be null."); | ||
assertEquals(expectedSchema.parameters().size(), 3); |
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.
assertEquals(expectedSchema.parameters().size(), 3); | |
assertEquals("testing", ((Map<String, String>)actualRecord.value()).get("applicationId")); |
@peacecwz see peacecwz#1 |
Hi @jcustenborder,
Maybe you saw If you are using HeaderToField as transforms and your data struct is Map, the plugin is throwing error like "MAP is unsupported ..." I implemented processMap function and I tried to use it and It works well. Maybe you want to merge it as contribution