Search in sources :

Example 1 with MapEntryFieldValue

use of org.apache.nifi.record.path.MapEntryFieldValue in project nifi by apache.

the class SingularMapKeyPath method evaluate.

@Override
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    return parentResult.filter(Filters.fieldTypeFilter(RecordFieldType.MAP)).map(fieldValue -> {
        final DataType valueType = ((MapDataType) fieldValue.getField().getDataType()).getValueType();
        final RecordField elementField = new RecordField(fieldValue.getField().getFieldName(), valueType);
        return new MapEntryFieldValue(getMapValue(fieldValue), elementField, fieldValue, mapKey);
    });
}
Also used : RecordField(org.apache.nifi.serialization.record.RecordField) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) MapDataType(org.apache.nifi.serialization.record.type.MapDataType) DataType(org.apache.nifi.serialization.record.DataType) FieldValue(org.apache.nifi.record.path.FieldValue) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) MapDataType(org.apache.nifi.serialization.record.type.MapDataType)

Example 2 with MapEntryFieldValue

use of org.apache.nifi.record.path.MapEntryFieldValue in project nifi by apache.

the class MultiMapKeyPath method evaluate.

@Override
@SuppressWarnings("unchecked")
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    return parentResult.filter(Filters.fieldTypeFilter(RecordFieldType.MAP)).flatMap(fieldValue -> {
        final Map<String, ?> map = (Map<String, ?>) fieldValue.getValue();
        return mapKeys.stream().map(key -> {
            final DataType valueType = ((MapDataType) fieldValue.getField().getDataType()).getValueType();
            final RecordField elementField = new RecordField(fieldValue.getField().getFieldName(), valueType);
            return new MapEntryFieldValue(map.get(key), elementField, fieldValue, key);
        });
    });
}
Also used : RecordField(org.apache.nifi.serialization.record.RecordField) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) MapDataType(org.apache.nifi.serialization.record.type.MapDataType) DataType(org.apache.nifi.serialization.record.DataType) FieldValue(org.apache.nifi.record.path.FieldValue) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) MapDataType(org.apache.nifi.serialization.record.type.MapDataType) Map(java.util.Map)

Example 3 with MapEntryFieldValue

use of org.apache.nifi.record.path.MapEntryFieldValue in project nifi by apache.

the class WildcardIndexPath method evaluate.

@Override
@SuppressWarnings("unchecked")
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    return parentResult.filter(Filters.fieldTypeFilter(RecordFieldType.MAP, RecordFieldType.ARRAY)).flatMap(fieldValue -> {
        final RecordFieldType fieldType = fieldValue.getField().getDataType().getFieldType();
        final Object value = fieldValue.getValue();
        if (value == null) {
            return Stream.empty();
        }
        if (fieldType == RecordFieldType.MAP) {
            final Map<String, ?> map = (Map<String, ?>) value;
            return map.entrySet().stream().map(entry -> {
                final DataType valueType = ((MapDataType) fieldValue.getField().getDataType()).getValueType();
                final RecordField elementField = new RecordField(fieldValue.getField().getFieldName(), valueType);
                return new MapEntryFieldValue(entry.getValue(), elementField, fieldValue, entry.getKey());
            });
        } else {
            final Object[] array = (Object[]) value;
            return IntStream.range(0, array.length).mapToObj(index -> {
                final DataType elementDataType = ((ArrayDataType) fieldValue.getField().getDataType()).getElementType();
                final RecordField elementField = new RecordField(fieldValue.getField().getFieldName(), elementDataType);
                return new ArrayIndexFieldValue(array[index], elementField, fieldValue, index);
            });
        }
    });
}
Also used : RecordField(org.apache.nifi.serialization.record.RecordField) MapDataType(org.apache.nifi.serialization.record.type.MapDataType) ArrayIndexFieldValue(org.apache.nifi.record.path.ArrayIndexFieldValue) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) DataType(org.apache.nifi.serialization.record.DataType) MapDataType(org.apache.nifi.serialization.record.type.MapDataType) ArrayDataType(org.apache.nifi.serialization.record.type.ArrayDataType) ArrayIndexFieldValue(org.apache.nifi.record.path.ArrayIndexFieldValue) FieldValue(org.apache.nifi.record.path.FieldValue) MapEntryFieldValue(org.apache.nifi.record.path.MapEntryFieldValue) ArrayDataType(org.apache.nifi.serialization.record.type.ArrayDataType) RecordFieldType(org.apache.nifi.serialization.record.RecordFieldType) Map(java.util.Map)

Aggregations

FieldValue (org.apache.nifi.record.path.FieldValue)3 MapEntryFieldValue (org.apache.nifi.record.path.MapEntryFieldValue)3 DataType (org.apache.nifi.serialization.record.DataType)3 RecordField (org.apache.nifi.serialization.record.RecordField)3 MapDataType (org.apache.nifi.serialization.record.type.MapDataType)3 Map (java.util.Map)2 ArrayIndexFieldValue (org.apache.nifi.record.path.ArrayIndexFieldValue)1 RecordFieldType (org.apache.nifi.serialization.record.RecordFieldType)1 ArrayDataType (org.apache.nifi.serialization.record.type.ArrayDataType)1