Skip to content

Commit

Permalink
AVRO-3801: change method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
clesaec authored and dkulp committed Jul 31, 2023
1 parent e81c752 commit ab6e1b8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lang/java/avro/src/main/java/org/apache/avro/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,19 @@ public static class Parser {

/**
* Adds the provided types to the set of defined, named types known to this
* parser.
* parser. deprecated: use addTypes(Iterable<Schema> types)
*/
@Deprecated
public Parser addTypes(Map<String, Schema> types) {
for (Schema s : types.values())
return this.addTypes(types.values());
}

/**
* Adds the provided types to the set of defined, named types known to this
* parser.
*/
public Parser addTypes(Iterable<Schema> types) {
for (Schema s : types)
names.add(s);
return this;
}
Expand Down
15 changes: 15 additions & 0 deletions lang/java/avro/src/test/java/org/apache/avro/TestSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,19 @@ void testContentAfterAvscInFile() throws Exception {
parser.setValidateDefaults(true);
assertThrows(SchemaParseException.class, () -> parser.parse(avscFile));
}

@Test
void add_types() {
String schemaRecord2 = "{\"type\":\"record\", \"name\":\"record2\", \"fields\": ["
+ " {\"name\":\"f1\", \"type\":\"record1\" }" + "]}";
// register schema1 in schema.
Schema schemaRecord1 = Schema.createRecord("record1", "doc", "", false);
Schema.Parser parser = new Schema.Parser().addTypes(Collections.singleton(schemaRecord1));

// parse schema for record2 that contains field for schema1.
final Schema schema = parser.parse(schemaRecord2);
final Field f1 = schema.getField("f1");
assertNotNull(f1);
assertEquals(schemaRecord1, f1.schema());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ Schema ImportSchema() : {
{
try (InputStream stream=findFile(importFile).openStream()){
Parser parser = new Schema.Parser();
parser.addTypes(names); // inherit names
parser.addTypes(names.values()); // inherit names
Schema value = parser.parse(stream);
names = parser.getTypes(); // update names
return value;
Expand Down

0 comments on commit ab6e1b8

Please sign in to comment.