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