Use Message.getReaderSchema() in Pulsar IO Sinks when possible #10557
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When you run a Sink and you call record.getSchema(), it does not return an accurate representation of the schema in case of a schema update.
For instance:
Modifications
With this change we leverage PIP-85 Message.getReaderSchema() API that returns the exact schema used for the Message, that is the schema that these pieces for information updated to the same "schemaVersion" of the Message represented by the Record:
I also fixing a problem in KeyValueSchema for atSchemaVersion(), the constructor of KeyValueSchema did not fill in the SchemaInfo data structure, resulting in NPEs.
Verifying this change
This change adds a new integration test and a unit test
Does this pull request potentially affect one of the following parts:
It affects Pulsar Sinks that implement Sink, in fact now Record.getSchema() will return accurate schema information.
Documentation
No need for docs, previous behaviour was unexpected, the new behaviour is what you expect.