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

Add a Message.getSchema() in the client API #10438

Closed
vroyer opened this issue Apr 29, 2021 · 6 comments
Closed

Add a Message.getSchema() in the client API #10438

vroyer opened this issue Apr 29, 2021 · 6 comments
Assignees
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Milestone

Comments

@vroyer
Copy link
Contributor

vroyer commented Apr 29, 2021

When the schema is not known at compile time, a Consumer<GenericObject> should be able to get the message schema.

Currently, a Consumer<GenericRecord> can get the AVRO message and retreive its schema, but if the message is a KeyValue for example, there is no way to get the actual Schema.

The idea is to introduce a CompletableFuture<Schema<?>> getSchema() in the Message API, returning null by default.

The implementation classes (MessageImpl, TopicMessageImpl) could then fetch the Schema if available, and eventually keep it cached as a class member.

@vroyer vroyer added the type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages label Apr 29, 2021
@eolivelli
Copy link
Contributor

@congbobo184 here https://github.com/apache/pulsar/pull/9970/files#diff-955419b4b0ad976e96f9f7595989e79c391109aeaa304bd286a80fc6eb9360c7R324 you are adding MessageImpl#getSchema() with CompletableFuture

but why can't we use directly the schema instance that is cached inside the Message ?

@eolivelli
Copy link
Contributor

Related work:
Here in this existing test we have a Consumer with AUTO_CONSUME schema
the tests tests that it is possible to access the "current" AvroSchema using Schema.getNativeSchema()

org.apache.avro.Schema avroSchema = (org.apache.avro.Schema) impl.getSchema().getNativeSchema().get();

@eolivelli
Copy link
Contributor

The problem with AUTO_CONSUME and especially while dealing with multi-version schemas, is that Message.getSchema() should return the exact schema applied to the message, that is the schema identified by "topic" + "schemaVersion".

@eolivelli
Copy link
Contributor

As discussed at the community meeting I am going to send a PIP

@eolivelli
Copy link
Contributor

@eolivelli eolivelli self-assigned this May 5, 2021
@eolivelli eolivelli added this to the 2.8.0 milestone May 5, 2021
@codelipenghui
Copy link
Contributor

#10476 is merged, so close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

No branches or pull requests

3 participants