@Test public void testSimpleTypeWithAttributeAsRecord() throws IOException, MalformedRecordException { InputStream is = new FileInputStream("src/test/resources/xml/people3.xml"); final List<RecordField> fields = new ArrayList<>(); final List<RecordField> nestedFields1 = new ArrayList<>(); nestedFields1.add(new RecordField("ID", RecordFieldType.STRING.getDataType())); nestedFields1.add(new RecordField("CONTENT", RecordFieldType.STRING.getDataType())); final DataType recordType1 = RecordFieldType.RECORD.getRecordDataType(new SimpleRecordSchema(nestedFields1)); fields.add(new RecordField("NAME", recordType1)); final List<RecordField> nestedFields2 = new ArrayList<>(); nestedFields2.add(new RecordField("ID", RecordFieldType.STRING.getDataType())); nestedFields2.add(new RecordField("CONTENT", RecordFieldType.INT.getDataType())); final DataType recordType2 = RecordFieldType.RECORD.getRecordDataType(new SimpleRecordSchema(nestedFields2)); fields.add(new RecordField("AGE", recordType2)); XMLRecordReader reader = new XMLRecordReader(is, new SimpleRecordSchema(fields), true, null, "CONTENT", dateFormat, timeFormat, timestampFormat, Mockito.mock(ComponentLog.class)); Record first = reader.nextRecord(true, true); assertTrue(first.getValue("NAME") instanceof Record); Record first_nested1 = (Record) first.getValue("NAME"); assertTrue(first.getValue("AGE") instanceof Record); Record first_nested2 = (Record) first.getValue("AGE"); assertEquals("name1", first_nested1.getValue("ID")); assertEquals("Cleve Butler", first_nested1.getValue("CONTENT")); assertEquals("age1", first_nested2.getValue("ID")); assertEquals(42, first_nested2.getValue("CONTENT")); Record second = reader.nextRecord(true, true); assertTrue(second.getValue("NAME") instanceof Record); Record second_nested1 = (Record) second.getValue("NAME"); assertTrue(second.getValue("AGE") instanceof Record); Record second_nested2 = (Record) second.getValue("AGE"); assertEquals("name2", second_nested1.getValue("ID")); assertEquals("Ainslie Fletcher", second_nested1.getValue("CONTENT")); assertEquals("age2", second_nested2.getValue("ID")); assertEquals(33, second_nested2.getValue("CONTENT")); }
@Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close(); }
XMLRecordReader implements RecordReader { @Override public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields) throws IOException, MalformedRecordException { if (currentRecordStartTag == null) { return null; } try { final Record record = parseRecord(currentRecordStartTag, this.schema, coerceTypes, dropUnknownFields); setNextRecordStartTag(); if (record != null) { return record; } else { return new MapRecord(this.schema, Collections.EMPTY_MAP); } } catch (XMLStreamException e) { throw new MalformedRecordException("Could not parse XML", e); } } XMLRecordReader(InputStream in, RecordSchema schema, boolean isArray, String attributePrefix, String contentFieldName,
                           final String dateFormat, final String timeFormat, final String timestampFormat, final ComponentLog logger); @Override Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFields); @Override RecordSchema getSchema(); @Override void close();  }