Reply
Explorer
Posts: 27
Registered: ‎01-22-2014

Testing for key in hash

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.

Cloudera Employee
Posts: 146
Registered: ‎08-21-2013

Re: Testing for key in hash

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


Explorer
Posts: 27
Registered: ‎01-22-2014

Re: Testing for key in hash

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.

Highlighted
Cloudera Employee
Posts: 146
Registered: ‎08-21-2013

Re: Testing for key in hash

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

Explorer
Posts: 27
Registered: ‎01-22-2014

Re: Testing for key in hash

Thanks :-)

Also how can I test if _attachment_body contains a substring?

Cloudera Employee
Posts: 146
Registered: ‎08-21-2013

Re: Testing for key in hash

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.

Explorer
Posts: 27
Registered: ‎01-22-2014

Re: Testing for key in hash

Thanks ;-)