You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Russell Bateman <ru...@windofkeltia.com> on 2020/06/11 14:14:40 UTC

NiFi Expression Language in UpdateAttribute

I wnat to create an attribute, format-type, which I hoped would be set 
based on the in-coming flowfile name:

     ${ ${filename:endsWith( 'xml' )} : ifElse( 'XML', 'JSON' ) }

If the in-coming flowfile name is /sample.xml/, the result is 
nevertheless and always

format-type = JSON

I want it to be XML, obviously. What have I screwed up in my NEL syntax?

(Yes, I have tried taking out all the white space.)

Thanks,
Russ

Re: NiFi Expression Language in UpdateAttribute

Posted by Bryan Bende <bb...@gmail.com>.
Hello,

The EL docs have some good examples:

https://nifi.apache.org/docs/nifi-docs/html/expression-language-guide.html#ifelse

-Bryan


On Thu, Jun 11, 2020 at 10:14 AM Russell Bateman <ru...@windofkeltia.com>
wrote:

> I wnat to create an attribute, format-type, which I hoped would be set
> based on the in-coming flowfile name:
>
>     ${ ${filename:endsWith( 'xml' )} : ifElse( 'XML', 'JSON' ) }
>
> If the in-coming flowfile name is *sample.xml*, the result is
> nevertheless and always
>
>     format-type = JSON
>
> I want it to be XML, obviously. What have I screwed up in my NEL syntax?
>
> (Yes, I have tried taking out all the white space.)
>
> Thanks,
> Russ
>

Re: NiFi Expression Language in UpdateAttribute

Posted by Andy LoPresto <al...@apache.org>.
Russell,

I think it would be fine to include an example like this in the Expression Language Guide. You can submit a PR to add that if you like. 

Andy LoPresto
alopresto@apache.org
alopresto.apache@gmail.com
He/Him
PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69

> On Jun 11, 2020, at 7:31 AM, Russell Bateman <ru...@windofkeltia.com> wrote:
> 
> That solves confusion I had after and despite reading the NiFi Expression Language documentation. Having written documentation before, I get why it's never ending and danger-fraught to write "bigger" examples in such documentation, and we resist doing it, but that's what I needed to clear up in my head the combination of how the two constructs, endsWith and ifElse, work together.
> 
> Many thanks!
> 
> On 6/11/20 8:24 AM, Shawn Weeks wrote:
>> Your syntax is incorrect. Try this instead.
>>  
>> ${filename:endsWith('xml'):ifElse('XML','JSON')}
>>  
>> From: Russell Bateman <ru...@windofkeltia.com> <ma...@windofkeltia.com>
>> Reply-To: "users@nifi.apache.org" <ma...@nifi.apache.org> <us...@nifi.apache.org> <ma...@nifi.apache.org>
>> Date: Thursday, June 11, 2020 at 9:15 AM
>> To: NiFi Users <us...@nifi.apache.org> <ma...@nifi.apache.org>
>> Subject: NiFi Expression Language in UpdateAttribute
>>  
>> I wnat to create an attribute, format-type, which I hoped would be set based on the in-coming flowfile name:
>> 
>>     ${ ${filename:endsWith( 'xml' )} : ifElse( 'XML', 'JSON' ) }
>> 
>> If the in-coming flowfile name is sample.xml, the result is nevertheless and always
>> 
>>     format-type = JSON
>> 
>> I want it to be XML, obviously. What have I screwed up in my NEL syntax?
>> 
>> (Yes, I have tried taking out all the white space.)
>> 
>> Thanks,
>> Russ


Re: NiFi Expression Language in UpdateAttribute

Posted by Russell Bateman <ru...@windofkeltia.com>.
That solves confusion I had after and despite reading the NiFi 
Expression Language documentation. Having written documentation before, 
I get why it's never ending and danger-fraught to write "bigger" 
examples in such documentation, and we resist doing it, but that's what 
I needed to clear up in my head the combination of how the two 
constructs, endsWithand ifElse, work together.

Many thanks!

On 6/11/20 8:24 AM, Shawn Weeks wrote:
>
> Your syntax is incorrect. Try this instead.
>
> ${filename:endsWith('xml'):ifElse('XML','JSON')}
>
> *From: *Russell Bateman <ru...@windofkeltia.com>
> *Reply-To: *"users@nifi.apache.org" <us...@nifi.apache.org>
> *Date: *Thursday, June 11, 2020 at 9:15 AM
> *To: *NiFi Users <us...@nifi.apache.org>
> *Subject: *NiFi Expression Language in UpdateAttribute
>
> I wnat to create an attribute, format-type, which I hoped would be set 
> based on the in-coming flowfile name:
>
>     ${ ${filename:endsWith( 'xml' )} : ifElse( 'XML', 'JSON' ) }
>
> If the in-coming flowfile name is /sample.xml/, the result is 
> nevertheless and always
>
> format-type = JSON
>
> I want it to be XML, obviously. What have I screwed up in my NEL syntax?
>
> (Yes, I have tried taking out all the white space.)
>
> Thanks,
> Russ
>


Re: NiFi Expression Language in UpdateAttribute

Posted by Shawn Weeks <sw...@weeksconsulting.us>.
Your syntax is incorrect. Try this instead.

${filename:endsWith('xml'):ifElse('XML','JSON')}

From: Russell Bateman <ru...@windofkeltia.com>
Reply-To: "users@nifi.apache.org" <us...@nifi.apache.org>
Date: Thursday, June 11, 2020 at 9:15 AM
To: NiFi Users <us...@nifi.apache.org>
Subject: NiFi Expression Language in UpdateAttribute

I wnat to create an attribute, format-type, which I hoped would be set based on the in-coming flowfile name:

    ${ ${filename:endsWith( 'xml' )} : ifElse( 'XML', 'JSON' ) }

If the in-coming flowfile name is sample.xml, the result is nevertheless and always

    format-type = JSON

I want it to be XML, obviously. What have I screwed up in my NEL syntax?

(Yes, I have tried taking out all the white space.)

Thanks,
Russ