You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache NiFi:使用UpdateRecord验证字符串长度替换字段值失败求助

Fixing NiFi UpdateRecord for Column Validation & Replacement

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:

  1. If the value contains any letters (uppercase or lowercase), replace it with Wrong
  2. If it's a numeric value but has a length ≤ 8, replace it with Undefined
  3. 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 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 neither condition is met → returns the original field.value

Why Your Original Expressions Failed

  1. Your first replaceAll('[a-z]+|[a-z]+','Wrong') only replaces matching letter sequences, not the entire field. For example, rwed222 would become Wrong222 instead of the full Wrong you need.
  2. Using ${field.value:length():le(8)} as the first argument to replaceAll is invalid—replaceAll expects 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:06:47