Forum Discussion
andrew_holbrook
8 years agoNew 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?
- del8 years agoContributor 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_holbrook8 years agoNew Contributor III
Thanks! Can’t wait to try this out!
- ryagnik8 years agoNew Contributor
we had the same question but could not get any answer here, answer will be much appreciated here.