Apache NiFi:使用UpdateRecord验证字符串长度替换字段值失败求助
Let's get your UpdateRecord processor working correctly for validating my_column and replacing values as needed. The issue with your current expression is that you're trying to force conditional logic into replaceAll calls, which isn't the right approach—replaceAll is for regex-based substring replacement, not overall field condition checks.
What You Need to Do Instead
Use NiFi's Expression Language conditional (if-then-else) logic to handle the two validation rules in order:
- If the value contains any letters (uppercase or lowercase), replace it with
Wrong - If it's a numeric value but has a length ≤ 8, replace it with
Undefined - Otherwise, keep the original value
Correct Expression for my_column
Paste this into the Value field for my_column in UpdateRecord:
${field.value:matches('.*[a-zA-Z].*') ? 'Wrong' : (field.value:length():le(8) ? 'Undefined' : field.value)}
Breakdown of the Expression
field.value:matches('.*[a-zA-Z].*'): Checks if the value contains any letter (covers both uppercase and lowercase, matching your example)- If true → returns
Wrong
- If true → returns
- If no letters are found, we move to the second check:
field.value:length():le(8)- If the value's length is ≤8 → returns
Undefined
- If the value's length is ≤8 → returns
- If neither condition is met → returns the original
field.value
Why Your Original Expressions Failed
- Your first
replaceAll('[a-z]+|[a-z]+','Wrong')only replaces matching letter sequences, not the entire field. For example,rwed222would becomeWrong222instead of the fullWrongyou need. - Using
${field.value:length():le(8)}as the first argument toreplaceAllis invalid—replaceAllexpects a regex pattern, not a boolean value. That's why the length check never triggered correctly.
Quick Configuration Check
Make sure these settings are correct in UpdateRecord:
- Record Reader: CSV Reader (confirm it's set to use the first line as header)
- Record Writer: CSV Writer (keep header enabled)
- Replacement Value Strategy:
Literal Values
Testing with your sample input will now produce the exact expected output you shared.
内容的提问来源于stack exchange,提问作者Sachith Muhandiram

