I figured it out. The issue was that I had an array of records. I couldn't figure out the calls.
For posterity, SimpleRecordSchema oneSchema = new SimpleRecordSchema(fieldList) DataType oneValueType = RecordFieldType.RECORD.getRecordData(oneSchema) DataType allValues = RecordFieldType.ARRAY.getArrayDataType(oneValueType) Then you have to create a new schema using the new "allValues" dataType The trick was realizing that RecordFieldType.RECORD.getRecordData() takes a SCHEMA as its argument, not just a simple datatype. This allows you to build up complex values. Thanks for your help, Matt. -- Geoff -----Original Message----- From: Matt Burgess [mailto:mattyb...@apache.org] Sent: Monday, March 1, 2021 7:56 PM To: users@nifi.apache.org Subject: [EXTERNAL] Re: Some SimpleRecordSchema questions EXT email: be mindful of links/attachments. Geoffrey, In general you won't need to create your own DataType objects, instead you can use the RecordFieldType methods such as RecordFieldType.ARRAY.getArrayDataType(DataType elementType, boolean elementsNullable).getDataType(). So for an array of ints: myRecordFields.add(new RecordField("allMyIntegers", RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.INT.getDataType(), true))) If I misunderstood what you're trying to do please let me know and I'll help where I can. Regards, Matt On Fri, Feb 26, 2021 at 7:04 PM Greene (US), Geoffrey N <geoffrey.n.gre...@boeing.com> wrote: > > I’m writing a LookupService<Record> in Groovy for my ScriptedLookupService. > It is, as everyone had suggested, significantly faster than split/merge. > > > > I’m really very close to having it working. In fact, it works fine when my > <Record> is simple; a few strings. > > > > My situation, though, is that my service returns an ARRAY of records for a > single value. I can’t figure out how to construct the schema correctly. > > > > So far, I have > > public Optional<Record> lookup(Map<String,Object> coords) throws > LookupFailureException { > > oneValueSchemaFields.add(new RecordField("number", new > DataType(RecordFieldType.INT,""))) > > oneValueSchema = new SimpleRecordSchema(oneValueSchemaFields) > > > > // so far so good. But I need to return an ARRAY of these oneValueSchemas. > > def howDoIConstructThisSchema = new SimpleRecordSchema(??) > > > > String valueString =” [ {\“number\” : 1}, {\“number\” : 2},{ > \“number\”:3}]” > > def jsonSlurper = new groovy.json.JsonSlurper() > > def values = jsonSlurper.parseText(valueString) > > > > return Optional.ofNullable(new MapRecord(howDoIConstructThisSchema, > values)) > > } > > How do I construct the outer schema? How do you have one schema containing an > array of oneValueSchemas? There’s something stupid I am missing, I am sure. > > I did try just sending in oneValueSchema into the MapRecord constructor, but > it doesn’t appear that that worked either. Suggestions? > > > > Thanks > > > > > > > > > > > > > > > > > > > > > > > > Geoffrey Greene > >