@Test public void testComplexNestedStructureConversion() throws Exception { String[] directives = new String[] { "parse-as-json body", }; List<Row> rows = Arrays.asList( new Row("body", "{\n" + " \"name\" : {\n" + " \"fname\" : \"Joltie\",\n" + " \"lname\" : \"Root\"\n" + " },\n" + " \"boolean\" : true,\n" + " \"coordinates\" : [\n" + " 12.56,\n" + " 45.789\n" + " ],\n" + " \"numbers\" : [\n" + " 2," + " 2,\n" + " 3,\n" + " 4,\n" + " 5,\n" + " 6\n" + " ],\n" + " \"moves\" : [\n" + " { \"a\" : 1, \"b\" : \"X\", \"c\" : 2.8},\n" + " { \"a\" : 2, \"b\" : \"Y\", \"c\" : 232342.8},\n" + " { \"a\" : 3, \"b\" : \"Z\", \"c\" : null},\n" + " { \"a\" : 4, \"b\" : \"U\"}\n" + " ],\n" + " \"integer\" : 1,\n" + " \"double\" : 2.8,\n" + " \"float\" : 45.6,\n" + " \"aliases\" : [\n" + " \"root\",\n" + " \"joltie\",\n" + " \"bunny\"\n" + " ]\n" + "}") ); rows = TestingRig.execute(directives, rows); Row row = createUberRecord(rows); Json2Schema json2Schema = new Json2Schema(); RecordConvertor convertor = new RecordConvertor(); Schema schema = json2Schema.toSchema("superrecord", row); List<StructuredRecord> outputs = convertor.toStructureRecord(rows, schema); Assert.assertEquals(1, outputs.size()); Assert.assertEquals(6, ((List) outputs.get(0).get("body_numbers")).size()); }
public List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema) throws RecordConvertorException { List<StructuredRecord> results = new ArrayList<>(); for (Row row : rows) { StructuredRecord r = decodeRecord(row, schema); results.add(r); } return results; }
RecordConvertor implements Serializable { public List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema) throws RecordConvertorException { List<StructuredRecord> results = new ArrayList<>(); for (Row row : rows) { StructuredRecord r = decodeRecord(row, schema); results.add(r); } return results; } }
RecordConvertor implements Serializable { public List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema) throws RecordConvertorException { List<StructuredRecord> results = new ArrayList<>(); for (Row row : rows) { StructuredRecord r = decodeRecord(row, schema); results.add(r); } return results; }  }
RecordConvertor implements Serializable { public List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema) throws RecordConvertorException { List<StructuredRecord> results = new ArrayList<>(); for (Row row : rows) { StructuredRecord r = decodeRecord(row, schema); results.add(r); } return results; }  List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema); StructuredRecord decodeRecord(Row row, Schema schema); }
RecordConvertor implements Serializable { public List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema) throws RecordConvertorException { List<StructuredRecord> results = new ArrayList<>(); for (Row row : rows) { StructuredRecord r = decodeRecord(row, schema); results.add(r); } return results; }  List<StructuredRecord> toStructureRecord(List<Row> rows, Schema schema); StructuredRecord decodeRecord(Row row, Schema schema);  }