Skip to content

Instantly share code, notes, and snippets.

@rdblue
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdblue/9193726 to your computer and use it in GitHub Desktop.
Save rdblue/9193726 to your computer and use it in GitHub Desktop.
Test to catch parquet-mr #12
@Test
public void testArrayOfRecords() throws Exception {
Schema innerRecord = Schema.createRecord("InnerRecord", null, null, false);
Schema optionalString = optional(Schema.create(Schema.Type.STRING));
innerRecord.setFields(Lists.newArrayList(
new Schema.Field("s1", optionalString, null, NullNode.getInstance()),
new Schema.Field("s2", optionalString, null, NullNode.getInstance())
));
Schema schema = Schema.createRecord("HasArray", null, null, false);
schema.setFields(Lists.newArrayList(
new Schema.Field("myarray", Schema.createArray(optional(innerRecord)),
null, NullNode.getInstance())
));
System.err.println("Avro schema: " + schema.toString(true));
testConversion(schema, "message HasArray {\n" +
" optional group myarray (LIST) {\n" +
" repeated group array {\n" +
" optional binary s1 (UTF8);\n" +
" optional binary s2 (UTF8);\n" +
" }\n" +
" }\n" +
"}\n");
}
public static Schema optional(Schema original) {
return Schema.createUnion(Lists.newArrayList(original,
Schema.create(Schema.Type.NULL)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment