You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/05/18 12:40:52 UTC
[GitHub] [pulsar] BewareMyPower opened a new issue, #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
BewareMyPower opened a new issue, #15655:
URL: https://github.com/apache/pulsar/issues/15655
### What issue do you find in Pulsar docs?
Currently Pulsar docs only shows a simple way to create Avro schema. See https://pulsar.apache.org/docs/next/schema-understand#usage.
Given the following `User` class:
```java
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class User {
String name;
int age;
}
```
We can create an producer with Avro schema like:
```java
client.newProducer(Schema.AVRO(User.class))
```
However, if the class has a nullable field with a default value like:
```java
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class User {
@AvroDefault("\"user\"")
String name;
int age;
}
```
We must create the Avro schema via a `SchemaDefinition` and disable the `alwaysAllowNull` field like:
```java
SchemaDefinition schemaDefinition = SchemaDefinition.builder().withPojo(User.class).withAlwaysAllowNull(false).build();
client.newProducer(Schema.AVRO(schemaDefinition))
```
Otherwise, the schema info would be invalid. Run following test to reproduce:
```java
@Test
public void test() throws Exception {
var topic = "test-topic";
try (var client = PulsarClient.builder().serviceUrl(brokerUrl.toString()).build()) {
client.newProducer(Schema.AVRO(User.class))
.topic(topic)
.create();
client.newProducer(Schema.AVRO(User.class))
.topic(topic)
.create();
}
}
```
The 2nd creation of the producer will fail with following error messages:
```
2022-05-18T20:37:42,013 - ERROR - [mock-pulsar-bk-OrderedExecutor-0-0:ServerCnx@1292] - Try add schema failed, remote address /127.0.0.1:62344, topic persistent://public/default/test-topic, producerId 1
java.util.concurrent.CompletionException: org.apache.avro.AvroTypeException: Invalid default for field name: "user" not a ["null","string"]
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:315) ~[?:?]
...
```
### What is your suggestion?
1. Add examples about how to create Avro schema with a `SchemaDefinition`.
2. Note that this way must be used **when the class has a nullable field with a default value**.
### Do you have any references?
https://pulsar.apache.org/docs/next/schema-understand#usage
### Would you like to fix this issue?
Yes
### Note
- [X] I have researched my question.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #15655:
URL: https://github.com/apache/pulsar/issues/15655#issuecomment-1159340263
The issue had no activity for 30 days, mark with Stale label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] BewareMyPower commented on issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on issue #15655:
URL: https://github.com/apache/pulsar/issues/15655#issuecomment-1130028557
In addition, the description of **Changes allowed** column in [Schema compatibility check strategy](https://pulsar.apache.org/docs/next/schema-evolution-compatibility#schema-compatibility-check-strategy) is wrong.
Optional fields, which are decorated with `@AvroDefault` annotation, can be added or deleted for all strategies other than `ALWAYS_INCOMPATIBLE`. The description "Modify optional fields" is confused and ambiguous and should be removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] momo-jun commented on issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
Posted by GitBox <gi...@apache.org>.
momo-jun commented on issue #15655:
URL: https://github.com/apache/pulsar/issues/15655#issuecomment-1330305156
@congbobo184 @liangyepianzhou can you pls take a look at this issue of schema docs? I guess it has been addressed in. Any chance we can take care of it through [this doc improvement PR](https://github.com/apache/pulsar/pull/18434)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] github-actions[bot] commented on issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #15655:
URL: https://github.com/apache/pulsar/issues/15655#issuecomment-1368146186
The issue had no activity for 30 days, mark with Stale label.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [pulsar] congbobo184 closed issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
Posted by GitBox <gi...@apache.org>.
congbobo184 closed issue #15655: [Doc] SchemaDefinition must be used to create Avro schema in a certain case
URL: https://github.com/apache/pulsar/issues/15655
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org