Forum Discussion
6 Replies
- aleungContributor III
here:
{ "DocumentRoot": { "Document": [ { "Metadata": { "id": "e0408dd2-6564-11e5-a3cb-512b7ad797bd", "asMap": { "global": { "doc_id": "e0408dd2-6564-11e5-a3cb-512b7ad797bd" } } }, "Data": { "id": "1", "first_name": "John", "last_name": "Doe", "gender": "M", "city": "Santa Ana", "state": "California", "street_address": "9 Melby Terrace", "zip_code": "92725" } }, { "Metadata": { "id": "e0408dd3-6564-11e5-a3cb-512b7ad797bd", "asMap": { "global": { "doc_id": "e0408dd3-6564-11e5-a3cb-512b7ad797bd" } } }, "Data": { "id": "2", "first_name": "Katy", "last_name": "Perry", "gender": "F", "city": "Flushing", "state": "New York", "street_address": "43 Golf View Street", "zip_code": "11355" } } ] } }
- andrew_holbrookNew Contributor III
@aleung (and I suppose @robin), thanks but what I’m looking for more of is how to change this function (pulled from here):
public void defineInputSchema(final SchemaProvider provider) { Schema colA = provider.createSchema(SnapType.STRING, COL_A); provider.getSchemaBuilder(INPUT_VIEW_NAME) .withChildSchema(colA) .build(); }
How do I do a nested schema?
- delContributor III
Hey @andrew_holbrook,
I’ve played around with this code and I believe I found your solution. Using your data sample from your original post:
You’ll need to import com.snaplogic.snap.schema.api.ObjectSchema into your class and then your code will look something like this:
private static final String DATA = "data"; private static final String NAME = "name"; private static final String VALUE = "value"; private static final String INPUT_VIEW_NAME = "input0"; private static final String OUTPUT_VIEW_NAME = "output0"; @Override public void defineInputSchema(final SchemaProvider provider) { ObjectSchema data = provider.createSchema(SnapType.COMPOSITE, DATA); Schema name = provider.createSchema(SnapType.STRING, NAME); Schema value = provider.createSchema(SnapType.BOOLEAN, VALUE); data.addChild(name); data.addChild(value); provider.getSchemaBuilder(INPUT_VIEW_NAME) .withChildSchema(data) .build(); }
I don’t know if SnapType.COMPOSITE is the correct type, but it seems to work for me.
- andrew_holbrookNew Contributor III
Thanks! Can’t wait to try this out!
- ryagnikNew Contributor
we had the same question but could not get any answer here, answer will be much appreciated here.
- andrew_holbrookNew Contributor III