You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Chin Huang (Jira)" <ji...@apache.org> on 2022/08/22 04:53:00 UTC
[jira] [Updated] (AVRO-3612) Report specific location of incompatibility in record schema
[ https://issues.apache.org/jira/browse/AVRO-3612?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chin Huang updated AVRO-3612:
-----------------------------
Attachment: AVRO-3612.patch
> Report specific location of incompatibility in record schema
> ------------------------------------------------------------
>
> Key: AVRO-3612
> URL: https://issues.apache.org/jira/browse/AVRO-3612
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Affects Versions: 1.11.1
> Reporter: Chin Huang
> Priority: Major
> Attachments: AVRO-3612.patch
>
>
> Given a reader schema for a record with a field having a mandatory value:
> {code:json}
> {
> "type" : "record",
> "name" : "Account",
> "fields" : [ {
> "name" : "age",
> "type" : "int"
> } ]
> }
> {code}
> and a writer schema for a record with a field having a nullable value:
> {code:json}
> {
> "type" : "record",
> "name" : "Account",
> "fields" : [ {
> "name" : "age",
> "type" : [ "null", "int" ],
> "default" : null
> } ]
> }
> {code}
> invoking SchemaCompatibility.checkReaderWriterCompatibility(readerSchema, writerSchema) finds an incompatibility with message:
> {noformat}
> reader type: INT not compatible with writer type: NULL{noformat}
> and location:
> {noformat}
> /{noformat}
> However, I want it to instead tell me the specific location of the incompatibility in the record schema:
> {noformat}
> /fields/0/type/0
> {noformat}
> This failing unit test demonstrates the bug:
> {code:java}
> class SchemaCompatibilityTest {
> @Test
> void given_incompatibility_in_record_schema_then_found_incompatibility_location() {
> var mandatorySchema = SchemaBuilder.record("Account").fields()
> .name("age").type().intType().noDefault()
> .endRecord();
> var optionalSchema = SchemaBuilder.record("Account").fields()
> .optionalInt("age")
> .endRecord();
> var compatibility = SchemaCompatibility.checkReaderWriterCompatibility(
> mandatorySchema, optionalSchema);
> assertThat(compatibility.getType()).isEqualTo(SchemaCompatibilityType.INCOMPATIBLE);
> var incompatibility = compatibility.getResult().getIncompatibilities().get(0);
> assertThat(incompatibility.getMessage()).isEqualTo("reader type: INT not compatible with writer type: NULL");
> assertThat(incompatibility.getLocation()).isEqualTo("/fields/0/type/0");
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)