[Bug] Incompatible schema when having Avro schema without nullable string fields
- Dominant language
- Java
- Stars
- 15.3k
- Forks
- 3.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 160
Description
### Search before asking
- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.
### Version
Using Pulsar 2.9.1.
### Minimal reproduce step
Here is the project with the minimal reproducible example that leads to this problem: https://github.com/trojczak/pulsar-avro-schema-problem
Steps to reproduce:
1. Create topics and schemas from `README.md`. Use `Person.avsc` from the given repo as a schema for the topic.
2. Try to run `PersonFunction` class using `LocalRunner` from `PersonFunctionTest`.
3. See:
```
Caused by: org.apache.pulsar.client.api.PulsarClientException$IncompatibleSchemaException: {"errorMsg":"org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException: org.apache.avro.SchemaValidationException: Unable to read schema:
{
"type" : "record",
"name" : "Person",
"namespace" : "pl.trojczak.pocs.model",
"fields" : [ {
"name" : "birthYear",
"type" : "int"
}, {
"name" : "name",
"type" : [ "null", "string" ],
"default" : null
} ]
}
using schema:
{
"type" : "record",
"name" : "Person",
"namespace" : "pl.trojczak.pocs.model",
"fields" : [ {
"name" : "name",
"type" : "string"
}, {
"name" : "birthYear",
"type" : "int"
} ]
}
```
### What did you expect to see?
I expect to have a way for the `Person.avsc` schema to work with the given function.
### What did you see instead?
I get the following exception:
```
Caused by: org.apache.pulsar.client.api.PulsarClientException$IncompatibleSchemaException: {"errorMsg":"org.apache.pulsar.broker.service.schema.exceptions.IncompatibleSchemaException: org.apache.avro.SchemaValidationException: Unable to read schema:
{
"type" : "record",
"name" : "Person",
"namespace" : "pl.trojczak.pocs.model",
"fields" : [ {
"name" : "birthYear",
"type" : "int"
}, {
"name" : "name",
"type" : [ "null", "string" ],
"default" : null
} ]
}
using schema:
{
"type" : "record",
"name" : "Person",
"namespace" : "pl.trojczak.pocs.model",
"fields" : [ {
"name" : "name",
"type" : "string"
}, {
"name" : "birthYear",
"type" : "int"
} ]
}
```
### Anything else?
_No response_
### Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Contributor guide
Research direction
Start with the README.md, Person.avsc, PersonFunction, and PersonFunctionTest in the linked minimal reproduction. Run the LocalRunner scenario to reproduce the IncompatibleSchemaException, then trace Pulsar's schema compatibility handling for the displayed nullable and non-nullable Avro fields. Done means the reproduced Person schema works with the function without that exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100