use of org.apache.nifi.record.path.FieldValue in project nifi by apache.
the class UpdateRecord method processRelativePath.
private Record processRelativePath(final RecordPath replacementRecordPath, final Stream<FieldValue> destinationFields, Record record) {
final List<FieldValue> destinationFieldValues = destinationFields.collect(Collectors.toList());
for (final FieldValue fieldVal : destinationFieldValues) {
final RecordPathResult replacementResult = replacementRecordPath.evaluate(record, fieldVal);
final List<FieldValue> selectedFields = replacementResult.getSelectedFields().collect(Collectors.toList());
final Object replacementObject = getReplacementObject(selectedFields);
fieldVal.updateValue(replacementObject);
record = updateRecord(destinationFieldValues, selectedFields, record);
}
return record;
}
use of org.apache.nifi.record.path.FieldValue in project nifi by apache.
the class UpdateRecord method processAbsolutePath.
private Record processAbsolutePath(final RecordPath replacementRecordPath, final Stream<FieldValue> destinationFields, final Record record) {
final RecordPathResult replacementResult = replacementRecordPath.evaluate(record);
final List<FieldValue> selectedFields = replacementResult.getSelectedFields().collect(Collectors.toList());
final List<FieldValue> destinationFieldValues = destinationFields.collect(Collectors.toList());
return updateRecord(destinationFieldValues, selectedFields, record);
}
use of org.apache.nifi.record.path.FieldValue in project nifi by apache.
the class UpdateRecord method updateRecord.
private Record updateRecord(final List<FieldValue> destinationFields, final List<FieldValue> selectedFields, final Record record) {
if (destinationFields.size() == 1 && !destinationFields.get(0).getParentRecord().isPresent()) {
final Object replacement = getReplacementObject(selectedFields);
if (replacement == null) {
return record;
}
if (replacement instanceof Record) {
return (Record) replacement;
}
final List<RecordField> fields = selectedFields.stream().map(FieldValue::getField).collect(Collectors.toList());
final RecordSchema schema = new SimpleRecordSchema(fields);
final Record mapRecord = new MapRecord(schema, new HashMap<>());
for (final FieldValue selectedField : selectedFields) {
mapRecord.setValue(selectedField.getField().getFieldName(), selectedField.getValue());
}
return mapRecord;
} else {
for (final FieldValue fieldVal : destinationFields) {
fieldVal.updateValue(getReplacementObject(selectedFields));
}
return record;
}
}
use of org.apache.nifi.record.path.FieldValue in project nifi by apache.
the class ContainsRegex method test.
@Override
protected boolean test(final FieldValue fieldValue, final RecordPathEvaluationContext context) {
final Pattern pattern;
if (compiledPattern == null) {
final Optional<FieldValue> fieldValueOption = regexPath.evaluate(context).findFirst();
if (!fieldValueOption.isPresent()) {
return false;
}
final Object value = fieldValueOption.get().getValue();
if (value == null) {
return false;
}
final String regex = DataTypeUtils.toString(value, (String) null);
pattern = Pattern.compile(regex);
} else {
pattern = compiledPattern;
}
final String searchString = DataTypeUtils.toString(fieldValue.getValue(), (String) null);
if (searchString == null) {
return false;
}
return pattern.matcher(searchString).find();
}
use of org.apache.nifi.record.path.FieldValue in project nifi by apache.
the class Concat method evaluate.
@Override
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
Stream<FieldValue> concatenated = Stream.empty();
for (final RecordPathSegment valuePath : valuePaths) {
final Stream<FieldValue> stream = valuePath.evaluate(context);
concatenated = Stream.concat(concatenated, stream);
}
final StringBuilder sb = new StringBuilder();
concatenated.forEach(fv -> sb.append(DataTypeUtils.toString(fv.getValue(), (String) null)));
final RecordField field = new RecordField("concat", RecordFieldType.STRING.getDataType());
final FieldValue responseValue = new StandardFieldValue(sb.toString(), field, null);
return Stream.of(responseValue);
}
Aggregations