@Override public void readHeader(final DataInputStream in) throws IOException { final RecordSchema recoverySchema = RecordSchema.readFrom(in); reader = SchemaRecordReader.fromSchema(recoverySchema); }
default Object getFieldValue(RecordField field) { return getFieldValue(field.getFieldName()); }
private void writeRecordFields(final Record record, final OutputStream out, final byte[] buffer) throws IOException { writeRecordFields(record, record.getSchema(), out, buffer); }
@Override public SwapSummary getSwapSummary(final DataInputStream in, final String swapLocation, final ResourceClaimManager claimManager) throws IOException { final RecordSchema schema = RecordSchema.readFrom(in); final List<RecordField> summaryFields = schema.getField(SwapSchema.SWAP_SUMMARY).getSubFields(); final RecordField summaryRecordField = new ComplexRecordField(SwapSchema.SWAP_SUMMARY, Repetition.EXACTLY_ONE, summaryFields); final RecordSchema summarySchema = new RecordSchema(Collections.singletonList(summaryRecordField)); final Record summaryRecordParent = SchemaRecordReader.fromSchema(summarySchema).readRecord(in); final Record summaryRecord = (Record) summaryRecordParent.getFieldValue(SwapSchema.SWAP_SUMMARY); final SwapSummary swapSummary = SwapSummaryFieldMap.getSwapSummary(summaryRecord, claimManager); return swapSummary; }
public ContentClaimFieldMap(final ContentClaim contentClaim, final long contentClaimOffset, final RecordSchema schema) { this.contentClaim = contentClaim; this.contentClaimOffset = contentClaimOffset; this.schema = schema; final List<RecordField> resourceClaimFields = schema.getField(ContentClaimSchema.RESOURCE_CLAIM).getSubFields(); final RecordSchema resourceClaimSchema = new RecordSchema(resourceClaimFields); this.resourceClaimFieldMap = new ResourceClaimFieldMap(contentClaim.getResourceClaim(), resourceClaimSchema); }
private void writeRecordFields(final Record record, final RecordSchema schema, final OutputStream out, final byte[] buffer) throws IOException { final DataOutputStream dos = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); for (final RecordField field : schema.getFields()) { final Object value = record.getFieldValue(field); try { writeFieldRepetitionAndValue(field, value, dos, buffer); } catch (final Exception e) { throw new IOException("Failed to write field '" + field.getFieldName() + "'", e); } } }
private static RecordSchema buildSchema() { final List<RecordField> fields = new ArrayList<>(); fields.add(new SimpleRecordField(FieldNames.FIRST_EVENT_ID, FieldType.LONG, Repetition.EXACTLY_ONE)); fields.add(new SimpleRecordField(FieldNames.TIMESTAMP_OFFSET, FieldType.LONG, Repetition.EXACTLY_ONE)); fields.add(new SimpleRecordField(FieldNames.COMPONENT_IDS, FieldType.STRING, Repetition.ZERO_OR_MORE)); fields.add(new SimpleRecordField(FieldNames.COMPONENT_TYPES, FieldType.STRING, Repetition.ZERO_OR_MORE)); fields.add(new SimpleRecordField(FieldNames.QUEUE_IDS, FieldType.STRING, Repetition.ZERO_OR_MORE)); fields.add(new SimpleRecordField(FieldNames.EVENT_TYPES, FieldType.STRING, Repetition.ZERO_OR_MORE)); return new RecordSchema(fields); } }
private RepositoryRecord swapInRecord(final Record record) { final StandardRepositoryRecord repoRecord = createRecord(record); final String swapLocation = (String) record.getFieldValue(new SimpleRecordField(RepositoryRecordSchema.SWAP_LOCATION, FieldType.STRING, Repetition.EXACTLY_ONE)); repoRecord.setSwapLocation(swapLocation); final String queueId = (String) record.getFieldValue(RepositoryRecordSchema.QUEUE_IDENTIFIER); requireFlowFileQueue(repoRecord, queueId); return repoRecord; }
private Record readInlineRecord(final InputStream in) throws IOException { final List<RecordField> schemaFields = schema.getFields(); final Map<RecordField, Object> fields = new HashMap<>(schemaFields.size()); for (final RecordField field : schema.getFields()) { final Object value = readField(in, field); fields.put(field, value); } return new FieldMapRecord(fields, schema); }
public static Long getContentClaimOffset(final Record claimRecord) { return (Long) claimRecord.getFieldValue(ContentClaimSchema.CONTENT_CLAIM_OFFSET); } }
@Override public void writeHeader(final DataOutputStream out) throws IOException { writeSchema.writeTo(out); }
@Override public Record next() throws IOException { return readRecord(bufferedIn); }
@Override public void writeExternalFileReference(final File externalFile, final DataOutputStream out) throws IOException { new SchemaRecordWriter().writeExternalFileReference(out, externalFile); }
public void writeRecord(final Record record, final OutputStream out) throws IOException { // write sentinel value to indicate that there is a record. This allows the reader to then read one // byte and check if -1. If so, the reader knows there are no more records. If not, then the reader // knows that it should be able to continue reading. out.write(INLINE_RECORD_INDICATOR); final byte[] buffer = byteArrayCache.checkOut(); try { writeRecordFields(record, out, buffer); } finally { byteArrayCache.checkIn(buffer); } }
@Override public RepositoryRecord deserializeRecord(final DataInputStream in, final int version) throws IOException { if (recordIterator != null) { final RepositoryRecord record = nextRecord(); if (record != null) { return record; } recordIterator.close(); } recordIterator = reader.readRecords(in); if (recordIterator == null) { return null; } return nextRecord(); }
@Override public String toString() { return "SimpleRecordField[fieldName=" + fieldName + ", type=" + fieldType.name() + "]"; } }
@Override public boolean isMoreInExternalFile() throws IOException { return recordIterator != null && recordIterator.isNext(); } }
public FieldMapRecord(final Map<RecordField, Object> values, final RecordSchema schema) { this.schema = schema; this.values = convertFieldToName(values); }
public static SchemaRecordReader fromSchema(final RecordSchema schema) { return new SchemaRecordReader(schema); }
public FlowFileRecordFieldMap(final FlowFileRecord flowFile, final RecordSchema schema) { this.flowFile = flowFile; this.schema = schema; final RecordField contentClaimField = schema.getField(FlowFileSchema.CONTENT_CLAIM); contentClaimSchema = new RecordSchema(contentClaimField.getSubFields()); contentClaim = flowFile.getContentClaim() == null ? null : new ContentClaimFieldMap(flowFile.getContentClaim(), flowFile.getContentClaimOffset(), contentClaimSchema); }