-
Notifications
You must be signed in to change notification settings - Fork 134
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
[FLINK-34996][Connectors/Kafka] Use UserCodeCL to instantiate Deserializer #89
base: main
Are you sure you want to change the base?
Conversation
Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html) |
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.
Can we somehow add a test for this? I'm not too fond of single line changes without actually adding a test
@MartijnVisser Thanks for the quick response. There are existing tests covering this class and exactly this line of code and I also verified it pass. I'm happy to add more tests to ensure the user code class loader is being used. ![]() |
I don't think that's correct, because if there were existing tests I would have expected those to fail because of your change. |
@MartijnVisser True. I added a couple of tests that would fail without my change. Hope it looks good now. Please let me know if anything else is needed. |
@MartijnVisser May I have your advice on the use of public void open(InitializationContext context) throws Exception {
final ClassLoader userCodeClassLoader = context.getUserCodeClassLoader().asClassLoader();
try (TemporaryClassLoaderContext ignored =
TemporaryClassLoaderContext.of(userCodeClassLoader)) {
serializer =
InstantiationUtil.instantiate(
serializerClass.getName(),
Serializer.class,
userCodeClassLoader);
if (serializer instanceof Configurable) {
((Configurable) serializer).configure(config);
} else {
serializer.configure(config, isKey);
}
} catch (Exception e) {
throw new IOException("Failed to instantiate the serializer of class " + serializer, e);
}
} |
...or-kafka/src/test/java/org/apache/flink/connector/kafka/sink/KafkaSerializerWrapperTest.java
Outdated
Show resolved
Hide resolved
2631db7
to
e308757
Compare
@MartijnVisser I also fix a few style errors, please let me know if it is good now or any other change to make. Thanks for your review. |
...nector-kafka/src/main/java/org/apache/flink/connector/kafka/sink/KafkaSerializerWrapper.java
Outdated
Show resolved
Hide resolved
...ache/flink/connector/kafka/source/reader/deserializer/KafkaValueOnlyDeserializerWrapper.java
Outdated
Show resolved
Hide resolved
...or-kafka/src/test/java/org/apache/flink/connector/kafka/sink/KafkaSerializerWrapperTest.java
Show resolved
Hide resolved
Thanks @hugogu for the PR! I have added some comments, please have a look. Do you know why the CI is failing? |
Looks good, thanks @hugogu for quick update! Hopefully the CI is green this time 🤞 |
…also correct serializer.
…initialization and remove mockito.
…erialization wrappers.
1f24b62
to
b288080
Compare
@morazow Thanks for your approval. I have just rebased this PR to include the build fix made in main branch. Hopefully the build would success this time. I also noticed that v3.1 branch, may I know if this fix can be included? Shall I raise another PR for that? Not quite sure about the release procedure yet. |
Is there any other suggestions or problems I can fix before getting this PR merged please? |
So that when connector-kafka installed into Flink Libs, it can work with a Customer Deserializer class defines in User Code.
This is useful with work with Spring Kafka JsonDeserializer. JsonDeserializer is a generic class and can't be used to build a KafkaSource directly because the Generic Type information required would lost.
A typical use case of JsonDeserializer looks like following
This fix is to make above sample use pattern work when connector-kafka installed into Flink Libs rather than included in user jar.