Apache NiFi HBase Lookup返回MapRecord,如何提取单一值?
Hey there! Let's work through this issue where your HBase Lookup is returning a MapRecord[{SERIAL_NUM=123456789}] instead of the raw value you need for hbase_integid. I’ve dealt with this exact scenario before, so here’s how to extract that value cleanly:
Why You’re Seeing MapRecord
First, a quick context: The HBase Lookup processor returns a Record object (in your case, a MapRecord) by default. This object wraps all the columns you queried from HBase, which is why you see the key-value pair structure instead of just the number.
Step-by-Step Solutions
You’ve got a couple straightforward ways to pull out the 123456789 value and assign it to hbase_integid:
Option 1: Use EvaluateJsonPath (Extract as Flow File Attribute)
If you want to first store the value as an attribute (useful if you need to reference it in other processors later):
- Add an EvaluateJsonPath processor right after your HBase Lookup.
- Set the
Destinationproperty toflowfile-attribute. - Add a new property:
- Name:
hbase_integid - Value:
$.SERIAL_NUM - This JSON Path expression targets the
SERIAL_NUMfield inside the returned Record.
- Name:
Option 2: Use UpdateRecord (Directly Modify Your JSON Flow File)
If you want to add the hbase_integid field directly to your output JSON data:
- Add an UpdateRecord processor after HBase Lookup.
- Configure the
Record ReadertoJsonTreeReaderandRecord WritertoJsonRecordSetWriter(make sure these are properly set up to handle your JSON schema). - In the
Record Path Valuesection, add a new entry:- Record Path:
/hbase_integid(this is the new field you want to add) - Value:
${record:value('/SERIAL_NUM')} - This NiFi Expression Language (NEL) call pulls the
SERIAL_NUMvalue from the HBase Lookup’s returned Record.
- Record Path:
Quick Tip
Double-check that your HBase Lookup has the Return Single Row option enabled. This ensures you only get one matching row back, which simplifies extracting the value (no need to handle multiple records).
Once you implement either of these, you’ll have the plain 123456789 value assigned to hbase_integid as needed!
内容的提问来源于stack exchange,提问作者erkan.oktay

