Skip to content

Commit

Permalink
[SchemaTranslator] handle self-referential avro aliases (#881)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg-builder authored Jan 11, 2023
1 parent 3844dbb commit 5b93e9e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ and what APIs have changed, if applicable.

## [Unreleased]

## [29.41.5] - 2023-01-11
Handle Avro self-referential aliases in Avro to Proto schema translation.

## [29.41.4] - 2023-01-09
change the innitialize size of resolvedProperties to 0 in order to save memory pre-allocated

Expand Down Expand Up @@ -5432,7 +5435,8 @@ patch operations can re-use these classes for generating patch messages.

## [0.14.1]

[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.41.4...master
[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.41.5...master
[29.41.5]: https://github.com/linkedin/rest.li/compare/v29.41.4...v29.41.5
[29.41.4]: https://github.com/linkedin/rest.li/compare/v29.41.3...v29.41.4
[29.41.3]: https://github.com/linkedin/rest.li/compare/v29.41.2...v29.41.3
[29.41.2]: https://github.com/linkedin/rest.li/compare/v29.41.1...v29.41.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,11 @@ public Object[][] fromAvroSchemaData()
// Translated union member property contains default value.
"{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : [ { \"name\" : \"result\", \"type\" : [ { \"type\" : \"record\", \"name\" : \"fooResult\", \"fields\" : [ { \"name\" : \"success\", \"type\" : [ \"string\", \"null\" ], \"doc\" : \"Success message\", \"default\" : \"Union with aliases.\" }, { \"name\" : \"failure\", \"type\" : [ \"null\", \"string\" ], \"doc\" : \"Failure message\", \"default\" : null }, { \"name\" : \"fieldDiscriminator\", \"type\" : { \"type\" : \"enum\", \"name\" : \"fooResultDiscriminator\", \"symbols\" : [ \"success\", \"failure\" ] }, \"doc\" : \"Contains the name of the field that has its value set.\" } ] }, \"null\" ], \"default\" : { \"fieldDiscriminator\" : \"success\", \"success\" : \"Union with aliases.\", \"failure\" : null } } ] }",
"{ \"type\" : \"record\", \"name\" : \"foo\", \"fields\" : [ { \"name\" : \"result\", \"type\" : { \"type\" : \"record\", \"name\" : \"fooResult\", \"fields\" : [ { \"name\" : \"success\", \"type\" : \"string\", \"doc\" : \"Success message\", \"default\" : \"Union with aliases.\", \"optional\" : true }, { \"name\" : \"failure\", \"type\" : \"string\", \"doc\" : \"Failure message\", \"optional\" : true }, { \"name\" : \"fieldDiscriminator\", \"type\" : { \"type\" : \"enum\", \"name\" : \"fooResultDiscriminator\", \"symbols\" : [ \"success\", \"failure\" ] }, \"doc\" : \"Contains the name of the field that has its value set.\" } ] }, \"default\" : { \"success\" : \"Union with aliases.\", \"fieldDiscriminator\" : \"success\" }, \"optional\" : true } ] }"
},
{
// Avro schema with self-referential alias
"{ \"type\" : \"record\", \"namespace\" : \"com.linkedin\", \"name\" : \"Foo\", \"fields\" : [ { \"name\" : \"bar\", \"type\" : \"int\" } ], \"aliases\" : [\"com.linkedin.Foo\"] }",
"{ \"type\" : \"record\", \"namespace\" : \"com.linkedin\", \"name\" : \"Foo\", \"fields\" : [ { \"name\" : \"bar\", \"type\" : \"int\" } ], \"aliases\" : [\"com.linkedin.Foo\"] }"
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;

Expand Down Expand Up @@ -129,7 +130,12 @@ protected boolean bindNameToSchema(Name name, List<Name> aliasNames, NamedDataSc
{
for (Name aliasName : aliasNames)
{
ok &= bindNameToSchema(aliasName, schema);
// Avro allows for self referential aliases (where the alias is the same as the FQN).
// There is no need to bind a self-referential alias to itself.
if (!Objects.equals(aliasName.getFullName(), name.getFullName()))
{
ok &= bindNameToSchema(aliasName, schema);
}
}
}
return ok;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=29.41.4
version=29.41.5
group=com.linkedin.pegasus
org.gradle.configureondemand=true
org.gradle.parallel=true
Expand Down

0 comments on commit 5b93e9e

Please sign in to comment.