Record API fails to pull nested record

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Record API fails to pull nested record

Mike Thomsen
I'm trying to fetch an nested record (schema is attached). Code and error are below. When I step through it with a debugger, it looks like every nested record is just a LinkedHashMap and not a MapRecord now.

RecordPath sourcePath = recordPathCache.getCompiled("/associatedAddress/address");
RecordPathResult result = sourcePath.evaluate(record);
Optional<FieldValue> resultFV = result.getSelectedFields().findFirst();

Results in:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.apache.nifi.serialization.record.Record

at org.apache.nifi.record.path.paths.ChildFieldPath.getChild(ChildFieldPath.java:49)
at org.apache.nifi.record.path.paths.ChildFieldPath.lambda$evaluate$0(ChildFieldPath.java:71)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:405)
at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
at org.apache.nifi.graph.mapping.GremlinCodeGenerator.lambda$generate$1(GremlinCodeGenerator.java:36)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
Reply | Threaded
Open this post in threaded view
|

Re: Record API fails to pull nested record

Mike Thomsen
It's a problem in MapRecord. I originally just threw a JSON body at it.
When I specified that the inner records are MapRecords, it worked:

def mockRecord = new MapRecord(registry.retrieveSchema("DetailedUser"), [
    contact: new MapRecord(registry.retrieveSchema("ContactRecord"), [
        phoneNumber: "867-5309",
        email: "[hidden email]"
    ]),
    firstName: "Test",
    lastName: "User",
    associatedLocation: new
MapRecord(registry.retrieveSchema("AssociatedLocationRecord"), [
        daysAt: 50,
        purpose: "WORK",
        address: new MapRecord(registry.retrieveSchema("AddressRecord"), [
            street: "55 Main St",
            city: "Arlington",
            state: "VA",
            country: "USA"
        ])
    ])
])

On Fri, Jun 21, 2019 at 8:12 AM Mike Thomsen <[hidden email]> wrote:

> I'm trying to fetch an nested record (schema is attached). Code and error
> are below. When I step through it with a debugger, it looks like every
> nested record is just a LinkedHashMap and not a MapRecord now.
>
> RecordPath sourcePath =
> recordPathCache.getCompiled("/associatedAddress/address");
> RecordPathResult result = sourcePath.evaluate(record);
> Optional<FieldValue> resultFV = result.getSelectedFields().findFirst();
>
> Results in:
>
> java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to
> org.apache.nifi.serialization.record.Record
>
> at
> org.apache.nifi.record.path.paths.ChildFieldPath.getChild(ChildFieldPath.java:49)
> at
> org.apache.nifi.record.path.paths.ChildFieldPath.lambda$evaluate$0(ChildFieldPath.java:71)
> at
> java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
> at
> java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
> at java.util.stream.Streams$StreamBuilderImpl.tryAdvance(Streams.java:405)
> at
> java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
> at
> java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
> at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
> at
> java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
> at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
> at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
> at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
> at
> org.apache.nifi.graph.mapping.GremlinCodeGenerator.lambda$generate$1(GremlinCodeGenerator.java:36)
> at
> java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
> at
> java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
>