Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

Concatenate two JSON values

avatar
Explorer

I have a JSON dataset and need to create a unique key from it. No single field is unique, but the first two, together, are. What I want to convert from:

 

[{"airport":"KDEN", "runway":"16R", "length":16000}, ...]

 

and I want to concatenate the "airport" and "runway" values to create this:

 

[{"key":"KDEN/16R", "airport":"KDEN", "runway":"16R", "length":16000}, ...]

 

I've got it working with an ugly anti-pattern of SplitRecord, EvaluateJSONPath, UpdateAttribute, and AttributesToJSON  which changes each flow file to several thousand, but am looking for a better way to do this. 

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi,

 

There are multiple ways you can resolve this issue without having to do all processors you mentioned above. Some options:

1- QueryRecord

2- UpdateRecord

3- JsonJoltTransformation.

If you elect to use QueryRecord which is what is been suggested for such anti-pattern , then you can create new dynamic property on the QueryRecord to represent the new relationship which will have the result of the select statement with new Key field as follows :

SAMSAL_0-1675117781675.png

The select query syntax for the "AddKeyRel":

select *,airport||'/'||runway as key from FlowFile

The || symbol is used for concatenation in such query and processor.

 

The JsonTreeReader and the JsonRecordSetWriter are configured as follows:

SAMSAL_1-1675117960341.png

 

SAMSAL_2-1675117983804.png

 

If the helps please accept solution.

Thanks

 

 

 

View solution in original post

2 REPLIES 2

avatar
Super Guru

Hi,

 

There are multiple ways you can resolve this issue without having to do all processors you mentioned above. Some options:

1- QueryRecord

2- UpdateRecord

3- JsonJoltTransformation.

If you elect to use QueryRecord which is what is been suggested for such anti-pattern , then you can create new dynamic property on the QueryRecord to represent the new relationship which will have the result of the select statement with new Key field as follows :

SAMSAL_0-1675117781675.png

The select query syntax for the "AddKeyRel":

select *,airport||'/'||runway as key from FlowFile

The || symbol is used for concatenation in such query and processor.

 

The JsonTreeReader and the JsonRecordSetWriter are configured as follows:

SAMSAL_1-1675117960341.png

 

SAMSAL_2-1675117983804.png

 

If the helps please accept solution.

Thanks

 

 

 

avatar
Explorer

That worked perfectly. Thank you.