Detect whether a flowfile has a particular attribute

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Detect whether a flowfile has a particular attribute

James McMahon
Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:

hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}

I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard? 

Thanks in advance for your insights. -Jim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

Mark Payne
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

James McMahon
So then if myAttribute does not even exist in a particular flowFile, the first expression will return a null value rather than throw an error. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 8:44 AM, Mark Payne <[hidden email]> wrote:
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

Mark Payne
Jim,

The first expression will return false. None of the expressions below will ever throw an Exception.

You could even chain them together like ${myAttribute:toLower():length():gt(4)} and if myAttribute does not
exist, it will return false, rather than throwing an Exception.

Thanks
-Mark


On Jun 8, 2017, at 9:32 AM, James McMahon <[hidden email]> wrote:

So then if myAttribute does not even exist in a particular flowFile, the first expression will return a null value rather than throw an error. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 8:44 AM, Mark Payne <[hidden email]> wrote:
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

James McMahon
I do understand now. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 9:34 AM, Mark Payne <[hidden email]> wrote:
Jim,

The first expression will return false. None of the expressions below will ever throw an Exception.

You could even chain them together like ${myAttribute:toLower():length():gt(4)} and if myAttribute does not
exist, it will return false, rather than throwing an Exception.

Thanks
-Mark


On Jun 8, 2017, at 9:32 AM, James McMahon <[hidden email]> wrote:

So then if myAttribute does not even exist in a particular flowFile, the first expression will return a null value rather than throw an error. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 8:44 AM, Mark Payne <[hidden email]> wrote:
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

Juan Sequeiros-2
Jim,

This might be related and coincidentally today we were talking with a coworker about the "advanced" button of UpdateAttribute and its ability to set attributes based on conditions.
It's pretty powerful. [1]
It might come in useful for your efforts.

On Thu, Jun 8, 2017 at 9:54 AM James McMahon <[hidden email]> wrote:
I do understand now. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 9:34 AM, Mark Payne <[hidden email]> wrote:
Jim,

The first expression will return false. None of the expressions below will ever throw an Exception.

You could even chain them together like ${myAttribute:toLower():length():gt(4)} and if myAttribute does not
exist, it will return false, rather than throwing an Exception.

Thanks
-Mark


On Jun 8, 2017, at 9:32 AM, James McMahon <[hidden email]> wrote:

So then if myAttribute does not even exist in a particular flowFile, the first expression will return a null value rather than throw an error. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 8:44 AM, Mark Payne <[hidden email]> wrote:
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Detect whether a flowfile has a particular attribute

James McMahon
Yes indeed, thank you Juan. I have used this advanced button to employ some fairly sophisticated expressions over many attributes. You are right: this has proven to be exceptionally helpful in our workflows here. -Jim

On Thu, Jun 8, 2017 at 12:26 PM, Juan Sequeiros <[hidden email]> wrote:
Jim,

This might be related and coincidentally today we were talking with a coworker about the "advanced" button of UpdateAttribute and its ability to set attributes based on conditions.
It's pretty powerful. [1]
It might come in useful for your efforts.

On Thu, Jun 8, 2017 at 9:54 AM James McMahon <[hidden email]> wrote:
I do understand now. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 9:34 AM, Mark Payne <[hidden email]> wrote:
Jim,

The first expression will return false. None of the expressions below will ever throw an Exception.

You could even chain them together like ${myAttribute:toLower():length():gt(4)} and if myAttribute does not
exist, it will return false, rather than throwing an Exception.

Thanks
-Mark


On Jun 8, 2017, at 9:32 AM, James McMahon <[hidden email]> wrote:

So then if myAttribute does not even exist in a particular flowFile, the first expression will return a null value rather than throw an error. Thank you very much Mark. -Jim

On Thu, Jun 8, 2017 at 8:44 AM, Mark Payne <[hidden email]> wrote:
Jim,

You can use the expression:

${myAttribute:isNull()}

Or, alternatively, depending on how you want to setup the route:

${myAttribute:notNull()}

If you want to check if the attribute contains 'True' somewhere within its value,
then you can use:

${myAttribute:contains('True')}

Thanks
-Mark


> On Jun 8, 2017, at 8:19 AM, James McMahon <[hidden email]> wrote:
>
> Good morning. I receive HTTP POSTs of various types of files. Some have a particular attribute myAttribute, some do not. I want to route the flowfiles to different workflow paths depending on the presence of this attribute. Can I use RouteAttribute and the expression language to do that, something like this:
>
> hasTheAttributeOfInterest           ${anyAttribute("myAttribute":contains('True')}
>
> I ask because the expression guide did not say whether a False is returned or the processor throws an error if the attribute does not exist in the flowfile. I may have missed that. I wanted to see if anyone in the group has experience in this regard?
>
> Thanks in advance for your insights. -Jim





Loading...