use of org.apache.nifi.record.path.StandardFieldValue 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);
}
use of org.apache.nifi.record.path.StandardFieldValue in project nifi by apache.
the class Format method evaluate.
@Override
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
final Stream<FieldValue> fieldValues = recordPath.evaluate(context);
return fieldValues.filter(fv -> fv.getValue() != null).map(fv -> {
final java.text.DateFormat dateFormat = getDateFormat(this.dateFormat, context);
if (dateFormat == null) {
return fv;
}
if (!(fv.getValue() instanceof Date) && !(fv.getValue() instanceof Number)) {
return fv;
}
final Date dateValue = DataTypeUtils.toDate(fv.getValue(), null, fv.getField().getFieldName());
final String formatted = dateFormat.format(dateValue);
return new StandardFieldValue(formatted, fv.getField(), fv.getParent().orElse(null));
});
}
use of org.apache.nifi.record.path.StandardFieldValue in project nifi by apache.
the class ReplaceRegex method evaluate.
@Override
public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
final Stream<FieldValue> fieldValues = recordPath.evaluate(context);
return fieldValues.filter(fv -> fv.getValue() != null).map(fv -> {
final String value = DataTypeUtils.toString(fv.getValue(), (String) null);
// Determine the Replacement Value
final String replacementValue = RecordPathUtils.getFirstStringValue(replacementValuePath, context);
if (replacementValue == null) {
return fv;
}
final Pattern pattern;
if (compiledPattern == null) {
final Optional<FieldValue> fieldValueOption = searchValuePath.evaluate(context).findFirst();
if (!fieldValueOption.isPresent()) {
return fv;
}
final Object fieldValue = fieldValueOption.get().getValue();
if (value == null) {
return fv;
}
final String regex = DataTypeUtils.toString(fieldValue, (String) null);
pattern = Pattern.compile(regex);
} else {
pattern = compiledPattern;
}
final String replaced = pattern.matcher(value).replaceAll(replacementValue);
return new StandardFieldValue(replaced, fv.getField(), fv.getParent().orElse(null));
});
}
use of org.apache.nifi.record.path.StandardFieldValue in project nifi by apache.
the class ToDate method evaluate.
@Override
public Stream<FieldValue> evaluate(RecordPathEvaluationContext context) {
final Stream<FieldValue> fieldValues = recordPath.evaluate(context);
return fieldValues.filter(fv -> fv.getValue() != null).map(fv -> {
if (!(fv.getValue() instanceof String)) {
return fv;
}
final java.text.DateFormat dateFormat = getDateFormat(this.dateFormat, context);
final Date dateValue;
try {
dateValue = DataTypeUtils.toDate(fv.getValue(), () -> dateFormat, fv.getField().getFieldName());
} catch (final Exception e) {
return fv;
}
if (dateValue == null) {
return fv;
}
return new StandardFieldValue(dateValue, fv.getField(), fv.getParent().orElse(null));
});
}
use of org.apache.nifi.record.path.StandardFieldValue in project nifi by apache.
the class ChildFieldPath method getChild.
private FieldValue getChild(final FieldValue fieldValue) {
if (!Filters.isRecord(fieldValue)) {
return missingChild(fieldValue);
}
final Record record = (Record) fieldValue.getValue();
if (record == null) {
return missingChild(fieldValue);
}
final Object value = record.getValue(childName);
if (value == null) {
return missingChild(fieldValue);
}
final Optional<RecordField> field = record.getSchema().getField(childName);
if (!field.isPresent()) {
return missingChild(fieldValue);
}
return new StandardFieldValue(value, field.get(), fieldValue);
}
Aggregations