Last active
November 18, 2020 11:52
-
-
Save Schm1tz1/3229c6dc2e5bf1539da5e26840e11607 to your computer and use it in GitHub Desktop.
How to handle nested AVRO Schemas: Union, several Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void nestedSchemaTest() throws IOException, NoSuchAlgorithmException { | |
Schema.Parser parser = new Schema.Parser(); | |
// nested schemas as union | |
parser.parse(new File("schemaUnion.avsc")); | |
// load dependent first, then "derived" schema | |
parser.parse(new File("schema1.avsc")); | |
parser.parse(new File("schema2.avsc")); | |
System.out.println(parser.getTypes()); | |
System.out.println(parser.getTypes().get("person").toString(true)); | |
System.out.println(parser.getTypes().get("person2").toString(true)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "record", | |
"name": "Address2", | |
"fields": [ | |
{ | |
"name": "streetaddress", | |
"type": "string" | |
}, | |
{ | |
"name": "city", | |
"type": "string" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "record", | |
"name": "person2", | |
"fields": [ | |
{ | |
"name": "firstname", | |
"type": "string" | |
}, | |
{ | |
"name": "lastname", | |
"type": "string" | |
}, | |
{ | |
"name": "address", | |
"type": "Address2" | |
} | |
] | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"type": "record", | |
"name": "Address", | |
"fields": [ | |
{ | |
"name": "streetaddress", | |
"type": "string" | |
}, | |
{ | |
"name": "city", | |
"type": "string" | |
} | |
] | |
}, | |
{ | |
"type": "record", | |
"name": "person", | |
"fields": [ | |
{ | |
"name": "firstname", | |
"type": "string" | |
}, | |
{ | |
"name": "lastname", | |
"type": "string" | |
}, | |
{ | |
"name": "address", | |
"type": "Address" | |
} | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At least I haven't found a "AVRO-native" way to do this. Some ideas: