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.

Testing for key in hash

Highlighted

Testing for key in hash

Explorer

Can you give me an example of how to test if @{} contains a particular key? I want to use an if command to test if @{} being passed to a command contains a particular key/value pair.

6 REPLIES 6

Re: Testing for key in hash

Expert Contributor
# test if field named "tenant" contains nothing but the value "foo"
if {
conditions : [
{ equals { tenant : [foo] } }
]
then : ...


Re: Testing for key in hash

Explorer
I want to test if a filed name exists at all. In your example I want to test if field named tenant exists in the hash or not.

Re: Testing for key in hash

Expert Contributor
# test if field named "tenant" contains at least one value
if {
conditions : [
{ not { equals { tenant : [] } } }
]
then : ...

Re: Testing for key in hash

Explorer
Thanks :-)

Also how can I test if _attachment_body contains a substring?

Re: Testing for key in hash

Expert Contributor
There's nothing built-in for that - use a "java" command with String.contains() or similar: http://kitesdk.org/docs/current/kite-morphlines/morphlinesReferenceGuide.html#java

Wolfgang.

Re: Testing for key in hash

Explorer
Thanks ;-)