You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Chris Herssens <ch...@gmail.com> on 2017/10/17 07:11:55 UTC

change type format in Avro Schema to int or null

Hello All,

I want to cast a string into an integer and if the string can't be cast it
should be replaced by NULL.
Using the ConvertRecord processor  with  type = [null,int] doesn't work.
Any ideas how I can do this ?

Regards,

Chris

Re: change type format in Avro Schema to int or null

Posted by Chris Herssens <ch...@gmail.com>.
Hello Mark,

What if you have more than one field to check ?  It would be nice to have
an option in the ConvertRecord processor, to replace invalid cast by NULL

Chris

On Tue, Oct 17, 2017 at 3:23 PM, Mark Payne <ma...@hotmail.com> wrote:

> Hey Chris,
>
> I'd recommend instead using ValidateRecord and routing the 'invalid'
> relationship to an UpdateRecord that sets the value
> to null. The valid relationship can then be routed where you'd like. When
> records are written out
> for the 'valid' relationship, that string will automatically be coerced
> into an int, if that's what the writer's
> schema has for the field type.
>
> Does that all make sense?
>
> Thanks
> -Mark
>
> > On Oct 17, 2017, at 3:11 AM, Chris Herssens <ch...@gmail.com>
> wrote:
> >
> > Hello All,
> >
> > I want to cast a string into an integer and if the string can't be cast
> it should be replaced by NULL.
> > Using the ConvertRecord processor  with  type = [null,int] doesn't work.
> > Any ideas how I can do this ?
> >
> > Regards,
> >
> > Chris
>
>

Re: change type format in Avro Schema to int or null

Posted by Mark Payne <ma...@hotmail.com>.
Hey Chris,

I'd recommend instead using ValidateRecord and routing the 'invalid' relationship to an UpdateRecord that sets the value
to null. The valid relationship can then be routed where you'd like. When records are written out
for the 'valid' relationship, that string will automatically be coerced into an int, if that's what the writer's
schema has for the field type.

Does that all make sense?

Thanks
-Mark

> On Oct 17, 2017, at 3:11 AM, Chris Herssens <ch...@gmail.com> wrote:
> 
> Hello All,
> 
> I want to cast a string into an integer and if the string can't be cast it should be replaced by NULL.
> Using the ConvertRecord processor  with  type = [null,int] doesn't work. 
> Any ideas how I can do this ?
> 
> Regards,
> 
> Chris