Search in sources :

Example 16 with Record

use of org.apache.nifi.repository.schema.Record in project nifi by apache.

the class EventIdFirstSchemaRecordReader method readRecord.

private StandardProvenanceEventRecord readRecord(final DataInputStream in, final long eventId, final long startOffset, final int recordLength) throws IOException {
    final InputStream limitedIn = new LimitingInputStream(in, recordLength);
    final Record eventRecord = recordReader.readRecord(limitedIn);
    if (eventRecord == null) {
        return null;
    }
    final StandardProvenanceEventRecord deserializedEvent = LookupTableEventRecord.getEvent(eventRecord, getFilename(), startOffset, getMaxAttributeLength(), firstEventId, systemTimeOffset, componentIds, componentTypes, queueIds, eventTypes);
    deserializedEvent.setEventId(eventId);
    return deserializedEvent;
}
Also used : DataInputStream(java.io.DataInputStream) LimitingInputStream(org.apache.nifi.stream.io.LimitingInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) LimitingInputStream(org.apache.nifi.stream.io.LimitingInputStream) Record(org.apache.nifi.repository.schema.Record) LookupTableEventRecord(org.apache.nifi.provenance.schema.LookupTableEventRecord)

Example 17 with Record

use of org.apache.nifi.repository.schema.Record in project nifi by apache.

the class LookupTableEventRecord method createContentClaimRecord.

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;
}
Also used : FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) RecordField(org.apache.nifi.repository.schema.RecordField) HashMap(java.util.HashMap) Record(org.apache.nifi.repository.schema.Record) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) RecordSchema(org.apache.nifi.repository.schema.RecordSchema)

Example 18 with Record

use of org.apache.nifi.repository.schema.Record in project nifi by apache.

the class LookupTableEventRecord method createExplicitSameOrNoneValue.

private NamedValue createExplicitSameOrNoneValue(final Record newValue, final Record oldValue, final Supplier<Record> recordSupplier) {
    if (newValue == null || EventFieldNames.NO_VALUE.equals(newValue.getSchema().getFields().get(0).getFieldName())) {
        final Map<RecordField, Object> lookupValues = Collections.singletonMap(LookupTableEventRecordFields.NO_VALUE, EventFieldNames.NO_VALUE);
        final Record record = new FieldMapRecord(lookupValues, LookupTableEventSchema.NO_VALUE_SCHEMA);
        final NamedValue namedValue = new NamedValue(EventFieldNames.NO_VALUE, record);
        return namedValue;
    } else if (newValue.equals(oldValue)) {
        final Map<RecordField, Object> lookupValues = Collections.singletonMap(LookupTableEventRecordFields.UNCHANGED_VALUE, EventFieldNames.UNCHANGED_VALUE);
        final Record record = new FieldMapRecord(lookupValues, LookupTableEventSchema.UNCHANGED_VALUE_SCHEMA);
        final NamedValue namedValue = new NamedValue(EventFieldNames.UNCHANGED_VALUE, record);
        return namedValue;
    }
    final Record record = recordSupplier.get();
    final NamedValue namedValue = new NamedValue(EventFieldNames.EXPLICIT_VALUE, record);
    return namedValue;
}
Also used : FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) RecordField(org.apache.nifi.repository.schema.RecordField) Record(org.apache.nifi.repository.schema.Record) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) NamedValue(org.apache.nifi.repository.schema.NamedValue) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with Record

use of org.apache.nifi.repository.schema.Record in project nifi by apache.

the class LookupTableEventRecord method getEvent.

@SuppressWarnings("unchecked")
public static StandardProvenanceEventRecord getEvent(final Record record, final String storageFilename, final long storageByteOffset, final int maxAttributeLength, final long eventIdStartOffset, final long startTimeOffset, final List<String> componentIds, final List<String> componentTypes, final List<String> queueIds, final List<String> eventTypes) {
    final Map<String, String> previousAttributes = truncateAttributes((Map<String, String>) record.getFieldValue(EventFieldNames.PREVIOUS_ATTRIBUTES), maxAttributeLength);
    final Map<String, String> updatedAttributes = truncateAttributes((Map<String, String>) record.getFieldValue(EventFieldNames.UPDATED_ATTRIBUTES), maxAttributeLength);
    final List<String> childUuids = (List<String>) record.getFieldValue(EventFieldNames.CHILD_UUIDS);
    final List<String> parentUuids = (List<String>) record.getFieldValue(EventFieldNames.PARENT_UUIDS);
    final StandardProvenanceEventRecord.Builder builder = new StandardProvenanceEventRecord.Builder();
    builder.setAlternateIdentifierUri((String) record.getFieldValue(EventFieldNames.ALTERNATE_IDENTIFIER));
    builder.setChildUuids(childUuids);
    builder.setDetails((String) record.getFieldValue(EventFieldNames.EVENT_DETAILS));
    builder.setParentUuids(parentUuids);
    builder.setPreviousAttributes(previousAttributes);
    builder.setRelationship((String) record.getFieldValue(EventFieldNames.RELATIONSHIP));
    builder.setSourceSystemFlowFileIdentifier((String) record.getFieldValue(EventFieldNames.SOURCE_SYSTEM_FLOWFILE_IDENTIFIER));
    builder.setTransitUri((String) record.getFieldValue(EventFieldNames.TRANSIT_URI));
    builder.setUpdatedAttributes(updatedAttributes);
    builder.setComponentId(readLookupValue(record.getFieldValue(EventFieldNames.COMPONENT_ID), componentIds));
    builder.setComponentType(readLookupValue(record.getFieldValue(EventFieldNames.COMPONENT_TYPE), componentTypes));
    builder.setSourceQueueIdentifier(readLookupValue(record.getFieldValue(EventFieldNames.SOURCE_QUEUE_IDENTIFIER), queueIds));
    // Determine the event type
    final Integer eventTypeOrdinal = (Integer) record.getFieldValue(EventFieldNames.EVENT_TYPE);
    ProvenanceEventType eventType;
    if (eventTypeOrdinal == null || eventTypeOrdinal > eventTypes.size() || eventTypeOrdinal < 0) {
        eventType = ProvenanceEventType.UNKNOWN;
    } else {
        try {
            eventType = ProvenanceEventType.valueOf(eventTypes.get(eventTypeOrdinal));
        } catch (final Exception e) {
            eventType = ProvenanceEventType.UNKNOWN;
        }
    }
    builder.setEventType(eventType);
    // Determine appropriate UUID for the event
    String uuid = null;
    switch(eventType) {
        case CLONE:
        case FORK:
        case REPLAY:
            if (parentUuids != null && !parentUuids.isEmpty()) {
                uuid = parentUuids.get(0);
            }
            break;
        case JOIN:
            if (childUuids != null && !childUuids.isEmpty()) {
                uuid = childUuids.get(0);
            }
            break;
    }
    if (uuid == null) {
        uuid = updatedAttributes == null ? null : updatedAttributes.get(CoreAttributes.UUID.key());
        if (uuid == null) {
            uuid = previousAttributes == null ? null : previousAttributes.get(CoreAttributes.UUID.key());
        }
    }
    builder.setFlowFileUUID(uuid);
    builder.setEventDuration((Integer) record.getFieldValue(EventFieldNames.EVENT_DURATION));
    builder.setEventTime(addLong((Integer) record.getFieldValue(EventFieldNames.EVENT_TIME), startTimeOffset));
    builder.setFlowFileEntryDate(addLong((Integer) record.getFieldValue(EventFieldNames.FLOWFILE_ENTRY_DATE), startTimeOffset));
    builder.setLineageStartDate(addLong((Integer) record.getFieldValue(EventFieldNames.LINEAGE_START_DATE), startTimeOffset));
    final Integer eventId = (Integer) record.getFieldValue(EventFieldNames.EVENT_IDENTIFIER);
    if (eventId != null) {
        builder.setEventId(eventId.longValue() + eventIdStartOffset);
    }
    builder.setStorageLocation(storageFilename, storageByteOffset);
    final Record previousClaimRecord = (Record) record.getFieldValue(EventFieldNames.PREVIOUS_CONTENT_CLAIM);
    if (previousClaimRecord != null) {
        builder.setPreviousContentClaim((String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
    }
    final Object contentClaimObject = record.getFieldValue(EventFieldNames.CONTENT_CLAIM);
    // NO_VALUE type
    builder.setCurrentContentClaim(null, null, null, null, 0L);
    if (contentClaimObject != null) {
        if (contentClaimObject instanceof String) {
            final String contentClaimDescription = (String) contentClaimObject;
            switch(contentClaimDescription) {
                case EventFieldNames.UNCHANGED_VALUE:
                    builder.setCurrentContentClaim((String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) previousClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
                    break;
            }
        } else if (contentClaimObject instanceof Record) {
            final Record currentClaimRecord = (Record) contentClaimObject;
            builder.setCurrentContentClaim((String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_CONTAINER), (String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SECTION), (String) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_IDENTIFIER), (Long) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_OFFSET), (Long) currentClaimRecord.getFieldValue(EventFieldNames.CONTENT_CLAIM_SIZE));
        }
    }
    return builder.build();
}
Also used : StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) List(java.util.List) Record(org.apache.nifi.repository.schema.Record) StandardProvenanceEventRecord(org.apache.nifi.provenance.StandardProvenanceEventRecord) FieldMapRecord(org.apache.nifi.repository.schema.FieldMapRecord) ProvenanceEventRecord(org.apache.nifi.provenance.ProvenanceEventRecord) ProvenanceEventType(org.apache.nifi.provenance.ProvenanceEventType)

Aggregations

Record (org.apache.nifi.repository.schema.Record)19 FieldMapRecord (org.apache.nifi.repository.schema.FieldMapRecord)7 ProvenanceEventRecord (org.apache.nifi.provenance.ProvenanceEventRecord)5 StandardProvenanceEventRecord (org.apache.nifi.provenance.StandardProvenanceEventRecord)5 RecordField (org.apache.nifi.repository.schema.RecordField)5 RecordSchema (org.apache.nifi.repository.schema.RecordSchema)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)4 LookupTableEventRecord (org.apache.nifi.provenance.schema.LookupTableEventRecord)4 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 SwapSummary (org.apache.nifi.controller.repository.SwapSummary)3 ContentClaim (org.apache.nifi.controller.repository.claim.ContentClaim)3 ResourceClaim (org.apache.nifi.controller.repository.claim.ResourceClaim)3 SchemaRecordReader (org.apache.nifi.repository.schema.SchemaRecordReader)3