Hello Isha, i just tried that now and it works and is perfect for my use
case, so problem solved.

That said, I think the type coercion in the reader and then the correct
formatting in the writer as I described in the first mail, should also work
based on the documentation.

So should this be filed as a bug or maybe the documentation should be
updated?

Thank you!


On 2024/12/05 14:02:55 Isha Lamboo wrote:
> Hi Bill,
>
> Have you tried setting the JsonRecordSetWriter to use your schema instead
of the JsonTreeReader?
> I think that should cause fields to be converted when the reader infers a
different schema than the writer uses.
>
> Regards,
>
> Isha
>
> Van: Bill Tsek <bi...@gmail.com>
> Verzonden: donderdag 5 december 2024 14:12
> Aan: users@nifi.apache.org
> Onderwerp: RE: Re: Nifi 2 type coercion on JsonTreeReader doesn't work
>
> You don't often get email from billtse...@gmail.com<ma...@gmail.com>.
Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
> Hello David thank you for your answer.
>
> What you described works, but is not what I'm trying to achieve.
> I don't want to change the schema, because I don't know the type of the
field in the input flowfile.
> I used int as an example but it could be some other type and I want to
convert it to string nevertheless.
>
> To my understanding, when I configure the schema on the reader with
string, the field should be coerced to string.
> This is described in the documentation of JsonTreeReader, in the
additional details section.
> Then as you say the writer will inherit the schema and also format the
field as a string.
>
> Correct me if I'm wrong or if this should be achieved some other way.
>
> As noted this used to work in nifi 1.14 and i didn't see any difference
in that matter in the documentation.
>
> Thanks again for your time.
>
> On 2024/12/05 11:49:07 Dávid Szabó wrote:
> > Hi Bill,
> >
> > If you want to change the schema of your record you have to set a
different
> > schema on your reader and writer, i.e. the reader should have the field
as
> > int and the writer as string.
> > If ConvertRecord sees that the schema does not change it will just
progress
> > the record as is without actually interpreting the schema.
> > You mentioned you did not change any default setting on
> > JsonRecordSetWriter. It means it is set to the "Inherit Record Schema"
> > strategy, which in your case just uses the schema set in the reader, so
> > ConvertRecord will not see a change in the schema.
> >
> > Regards,
> > David
> >
> >
> > Bill Tsek <bi...@gmail.com>> ezt írta (időpont: 2024. dec. 4., Sze,
> > 17:47):
> >
> > > Trying to convert a record's field from int to string using a schema,
the
> > > ConvertRecord processor, a JsonTreeReader and a JsonRecordSetWriter,
> > > doesn't seem to work.
> > >
> > > After the processor runs the field is still an int.
> > >
> > > The same example in nifi 1.14 works.
> > >
> > > Bellow I attached screenshots in order to reproduce.
> > >
> > > The flow:
> > >
> > > [image: image.png]
> > >
> > > The GenerateFlowFile properties:
> > > [image: image.png]
> > >
> > > The ConvertRecord properties:
> > > [image: image.png]
> > > The JsonTreeReader properties:
> > > [image: image.png]
> > > The schema.text:
> > > {
> > >    "type" : "record",
> > >    "namespace" : "schemas",
> > >    "name" : "foo",
> > >    "fields" : [
> > >       { "name" : "foo" , "type" : "string" }
> > >    ]
> > > }
> > >
> > > The JsonRecordSetWriter properties has not been changed.
> > >
> > > The ConvertRecord processor's output:
> > >
> > > [ {
> > >   "foo" : 5
> > > } ]
> > >
> > > Thanks
> > >
> >
>

Reply via email to