public SwapSummaryFieldMap(final SwapSummary summary, final String queueIdentifier, final RecordSchema schema) { this.swapSummary = summary; this.queueIdentifier = queueIdentifier; this.schema = schema; final RecordField resourceClaimField = schema.getField(SwapSchema.RESOURCE_CLAIMS).getSubFields().get(0); final RecordSchema resourceClaimSchema = new RecordSchema(resourceClaimField.getSubFields()); final List<ResourceClaim> resourceClaims = summary.getResourceClaims(); claimCounts = new HashMap<>(); for (final ResourceClaim claim : resourceClaims) { final ResourceClaimFieldMap fieldMap = new ResourceClaimFieldMap(claim, resourceClaimSchema); final Integer count = claimCounts.get(fieldMap); if (count == null) { claimCounts.put(fieldMap, 1); } else { claimCounts.put(fieldMap, count + 1); } } }
private void writeField(final RecordField field, final DataOutputStream dos) throws IOException { dos.writeInt(4); // A field is made up of 4 "elements": Field Name, Field Type, Field Repetition, Sub-Fields. // For each of the elements, we write a String indicating the Element Name, a String indicating the Element Type, and // finally the Element data itself. dos.writeUTF(FIELD_NAME); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getFieldName()); dos.writeUTF(FIELD_TYPE); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getFieldType().name()); dos.writeUTF(REPETITION); dos.writeUTF(STRING_TYPE); dos.writeUTF(field.getRepetition().name()); dos.writeUTF(SUBFIELDS); dos.writeUTF(SUBFIELD_TYPE); final List<RecordField> subFields = field.getSubFields(); dos.writeInt(subFields.size()); // SubField is encoded as number of Sub-Fields followed by the fields themselves. for (final RecordField subField : subFields) { writeField(subField, dos); } }
private static Record createContentClaimRecord(final RecordSchema contentClaimSchema, final String container, final String section, final String identifier, final Long offset, final Long size) { if (container == null || section == null || identifier == null) { final Map<RecordField, Object> lookupValues = Collections.singletonMap(LookupTableEventRecordFields.NO_VALUE, EventFieldNames.NO_VALUE); final List<RecordField> noValueFields = Collections.singletonList(contentClaimSchema.getField(EventFieldNames.NO_VALUE)); return new FieldMapRecord(lookupValues, new RecordSchema(noValueFields)); } final Map<RecordField, Object> fieldValues = new HashMap<>(); fieldValues.put(EventRecordFields.CONTENT_CLAIM_CONTAINER, container); fieldValues.put(EventRecordFields.CONTENT_CLAIM_SECTION, section); fieldValues.put(EventRecordFields.CONTENT_CLAIM_IDENTIFIER, identifier); fieldValues.put(EventRecordFields.CONTENT_CLAIM_OFFSET, offset); fieldValues.put(EventRecordFields.CONTENT_CLAIM_SIZE, size); final List<RecordField> explicitClaimFields = contentClaimSchema.getField(EventFieldNames.EXPLICIT_VALUE).getSubFields(); final Record explicitClaimRecord = new FieldMapRecord(fieldValues, new RecordSchema(explicitClaimFields)); return explicitClaimRecord; }
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); }
final Map<Object, Object> map = (Map<Object, Object>) value; out.writeInt(map.size()); final List<RecordField> subFields = field.getSubFields(); final RecordField keyField = subFields.get(0); final RecordField valueField = subFields.get(1);
value.add(readFieldValue(in, field.getFieldType(), field.getFieldName(), field.getSubFields())); return readFieldValue(in, field.getFieldType(), field.getFieldName(), field.getSubFields()); } catch (final EOFException eof) { final EOFException exception = new EOFException("Failed to read field '" + field.getFieldName() + "'");
@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 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); }
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); }
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); }