You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Mike Thomsen <mi...@gmail.com> on 2019/03/22 12:54:38 UTC

Best way to convert a record to a Map

What's the best way to get a Map<String, Object> representation of a record?

Thanks,

Mike

Re: Best way to convert a record to a Map

Posted by Matt Burgess <ma...@apache.org>.
Mike,

In JoltTransformRecord I make the following call to do that:

Map<String, Object> recordMap = (Map<String, Object>)
DataTypeUtils.convertRecordFieldtoObject(record,
RecordFieldType.RECORD.getRecordDataType(record.getSchema()));

Regards,
Matt

On Fri, Mar 22, 2019 at 8:55 AM Mike Thomsen <mi...@gmail.com> wrote:
>
> What's the best way to get a Map<String, Object> representation of a record?
>
> Thanks,
>
> Mike

Re: Best way to convert a record to a Map

Posted by Andy LoPresto <al...@gmail.com>.
I would look at ConvertRecord to understand the process and then wrap those values in a map. 

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

> On Mar 22, 2019, at 14:26, Mike Thomsen <mi...@gmail.com> wrote:
> 
> Inside the processor.
> 
>> On Fri, Mar 22, 2019 at 9:24 AM Andy LoPresto <al...@gmail.com> wrote:
>> Probably using a ScriptedWriter with a couple lines of Groovy to form and serialize the Java map. Or are you asking about inside the processor execution?
>> 
>> Andy LoPresto
>> alopresto@apache.org
>> alopresto.apache@gmail.com
>> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>> 
>>> On Mar 22, 2019, at 13:54, Mike Thomsen <mi...@gmail.com> wrote:
>>> 
>>> What's the best way to get a Map<String, Object> representation of a record?
>>> 
>>> Thanks,
>>> 
>>> Mike

Re: Best way to convert a record to a Map

Posted by Mike Thomsen <mi...@gmail.com>.
Inside the processor.

On Fri, Mar 22, 2019 at 9:24 AM Andy LoPresto <al...@gmail.com>
wrote:

> Probably using a ScriptedWriter with a couple lines of Groovy to form and
> serialize the Java map. Or are you asking about inside the processor
> execution?
>
> Andy LoPresto
> alopresto@apache.org
> alopresto.apache@gmail.com
> PGP Fingerprint: 70EC B3E5 98A6 5A3F D3C4  BACE 3C6E F65B 2F7D EF69
>
> On Mar 22, 2019, at 13:54, Mike Thomsen <mi...@gmail.com> wrote:
>
> What's the best way to get a Map<String, Object> representation of a
> record?
>
> Thanks,
>
> Mike
>
>

Re: Best way to convert a record to a Map

Posted by Andy LoPresto <al...@gmail.com>.
Probably using a ScriptedWriter with a couple lines of Groovy to form and serialize the Java map. Or are you asking about inside the processor execution?

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

> On Mar 22, 2019, at 13:54, Mike Thomsen <mi...@gmail.com> wrote:
> 
> What's the best way to get a Map<String, Object> representation of a record?
> 
> Thanks,
> 
> Mike