Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Advanced UpdateAttribute to conditionally append to an attribute

Highlighted

Advanced UpdateAttribute to conditionally append to an attribute

New Contributor

64447-updateattribute1.png

I am attempting to update an attribute based on incoming properties. Essentially I need to evaluate many incoming attributes and output a list in a new attribute based on the incoming attributes.

Here is an example:

The logic is IF attribute1="T" THEN ResultingAttribute="foo,"

IF attribute2="T" THEN ResultingAttribute="bar,"

IF attribute1="T"&&attribute2="T" THEN ResultingAttribute="foo,bar,"

Does anyone know how this can be accomplished using only 1 UpdateAttribute processor?

64450-updateattribute2.png

64449-updateattribute1.png

64448-updateattribute2.png

3 REPLIES 3

Re: Advanced UpdateAttribute to conditionally append to an attribute

Super Guru

@Joe Borowicz

Yes you can do that using Advance Usage,Change FlowFile Policy to use original.

Rule1:-

Conditions:-

${attribute1:equals("T")}

Actions:-

Attribute:-

ResultingAttribute

value:-

foo

62637-updateattribute-rule1.png

Rule2:-

Conditions:-

${attribute2:equals("T")}

Actions:-

Attribute:-

ResultingAttribute

value:-

foo

62638-updateattribute-rule2.png

Rule3:-

Conditions:-

${attribute1:equals("T"):and(${attribute2:equals("T")})}

Actions:-

Attribute:-

ResultingAttribute

value:-

foo,bar

62649-updateattribute-rule3.png

These rules will be evaluated in the order they placed i.e rule1 is checked first then rule2 is checked second rule3 checked third.

you can rearrange order of evaluation by click and drag.

Let us know if you having any issues..!!

Re: Advanced UpdateAttribute to conditionally append to an attribute

New Contributor

Thank you for your response. It certainly works for the simplified example I provided, but in my application it could be checking for more than 2 incoming attributes. As of now it would check for 5 attributes, and it would not be possible to add a rule for each possible combination of attributes flagged with "T."

Re: Advanced UpdateAttribute to conditionally append to an attribute

Super Guru

@Joe Borowicz

If you feel like it will not possible to keep all combinations then other options to acheive this use case would be:

Write a script(in java,groovy..etc) and check all the combinations, write the required attributes to the flowfile.

Refer to below link for scripting cook books:-

https://community.hortonworks.com/articles/75032/executescript-cookbook-part-1.html

(or)

By using Hive query:
store the data into HDFS then feed the PutHDFS processor success relation to selectHiveQL processor then run your logic by using SQL query with case statement in it then extract your required attributes from the flowfile contents.