### Question:
AvroExhibit { public static Exhibit create(GenericRecord record) { Schema schema = record.getSchema(); ExhibitDescriptor desc = createDescriptor(schema); List<Object> attrValues = Lists.newArrayListWithExpectedSize(desc.attributes().size()); for (int i = 0; i < desc.attributes().size(); i++) { Object val = record.get(desc.attributes().get(i).name); if (val != null && desc.attributes().get(i).type == FieldType.STRING) { val = val.toString(); } attrValues.add(val); } Map<String, Frame> frames = Maps.newHashMap(); for (String frameName : desc.frames().keySet()) { List<GenericRecord> recs = Lists.newArrayList(); List<GenericRecord> raw = (List<GenericRecord>) record.get(frameName); if (raw != null) { for (GenericRecord rawRec : raw) { recs.add(getInnerRecord(rawRec)); } } frames.put(frameName, new AvroFrame((AvroObsDescriptor) desc.frames().get(frameName), recs)); } Map<String, Vec> vectors = Maps.newHashMap(); for (Map.Entry<String, FieldType> v : desc.vectors().entrySet()) { List vals = Arrays.asList((Object[]) record.get(v.getKey())); vectors.put(v.getKey(), VectorBuilder.build(v.getValue(), vals)); } return new SimpleExhibit(new SimpleObs(desc.attributes(), attrValues), frames, vectors); } private  AvroExhibit(); static ExhibitDescriptor createDescriptor(Schema schema); static Exhibit create(GenericRecord record); static Schema.Field getSchemaField(ObsDescriptor.Field f); static Schema getSchema(FieldType type);  }### Answer:
@Test public void testAvroExhibitFrame() { GenericData.Record in1 = new GenericData.Record(inner); in1.put("f1", null); in1.put("f2", true); in1.put("f3", 1729); GenericData.Record in2 = new GenericData.Record(inner); in2.put("f1", "josh"); in2.put("f3", 29); List<GenericData.Record> recs = Lists.newArrayList(in1, in2); GenericData.Record o1 = new GenericData.Record(outer1); o1.put("id", 17); o1.put("short", "jw"); o1.put("ifoo", recs); Exhibit exhibit = AvroExhibit.create(o1); assertEquals(17, exhibit.attributes().get("id")); assertEquals("jw", exhibit.attributes().get("short")); Frame f = exhibit.frames().get("ifoo"); assertNotNull(f); assertEquals("Num obs in Frame", 2, f.size()); assertEquals(null, f.$("f1").get(0)); assertEquals("josh", f.$("f1").get(1)); assertEquals(true, f.$("f2").get(0)); assertEquals(null, f.$("f2").get(1)); assertEquals(1729, f.$("f3").get(0)); assertEquals(29, f.$("f3").get(1)); }
@Test public void testAvroExhibitVector() { Schema simpleVectorRecordSchema = SchemaBuilder.record("rec").fields() .requiredInt("id") .name("vec").type(Schema.createArray(Schema.create(Schema.Type.DOUBLE))).noDefault() .endRecord(); GenericData.Record o1 = new GenericData.Record(simpleVectorRecordSchema); o1.put("id", 123); o1.put("vec", ImmutableList.of(1.0, 2.0, 3.0).toArray()); Exhibit exhibit = AvroExhibit.create(o1); assertEquals(123, exhibit.attributes().get("id")); Frame f = exhibit.frames().get("ifoo"); assertNull(f); Vec v = exhibit.vectors().get("vec"); assertNotNull(v); assertEquals("Num obs in Vector", 3, v.size()); assertEquals(1.0, v.get(0)); assertEquals(2.0, v.get(1)); assertEquals(3.0, v.get(2)); }