use of io.cdap.cdap.etl.mock.validation.MockFailureCollector in project hydrator-plugins by cdapio.
the class UnionSplitterTest method testOutputSchemas.
@Test
public void testOutputSchemas() {
Schema rec1Schema = Schema.recordOf("rec1", Schema.Field.of("x", Schema.of(Schema.Type.INT)), Schema.Field.of("y", Schema.of(Schema.Type.INT)));
Schema rec2Schema = Schema.recordOf("rec2", Schema.Field.of("y", Schema.of(Schema.Type.INT)), Schema.Field.of("z", Schema.of(Schema.Type.INT)));
Schema inputSchema = Schema.recordOf("union", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.unionOf(Schema.of(Schema.Type.NULL), Schema.of(Schema.Type.BOOLEAN), Schema.of(Schema.Type.BYTES), Schema.of(Schema.Type.INT), Schema.of(Schema.Type.LONG), Schema.of(Schema.Type.FLOAT), Schema.of(Schema.Type.DOUBLE), Schema.of(Schema.Type.STRING), rec1Schema, rec2Schema)));
// test with schema modification
Map<String, Schema> expected = new HashMap<>();
expected.put("null", Schema.recordOf("union.null", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.NULL))));
expected.put("boolean", Schema.recordOf("union.boolean", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.BOOLEAN))));
expected.put("bytes", Schema.recordOf("union.bytes", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.BYTES))));
expected.put("int", Schema.recordOf("union.int", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.INT))));
expected.put("long", Schema.recordOf("union.long", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.LONG))));
expected.put("float", Schema.recordOf("union.float", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.FLOAT))));
expected.put("double", Schema.recordOf("union.double", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.DOUBLE))));
expected.put("string", Schema.recordOf("union.string", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", Schema.of(Schema.Type.STRING))));
expected.put("rec1", Schema.recordOf("union.rec1", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", rec1Schema)));
expected.put("rec2", Schema.recordOf("union.rec2", Schema.Field.of("a", Schema.of(Schema.Type.LONG)), Schema.Field.of("b", rec2Schema)));
FailureCollector collector = new MockFailureCollector();
Map<String, Schema> actual = UnionSplitter.getOutputSchemas(inputSchema, "b", true, collector);
Assert.assertEquals(expected, actual);
Assert.assertEquals(0, collector.getValidationFailures().size());
// test without schema modification
expected.clear();
expected.put("null", changeName(inputSchema, "union.null"));
expected.put("boolean", changeName(inputSchema, "union.boolean"));
expected.put("bytes", changeName(inputSchema, "union.bytes"));
expected.put("int", changeName(inputSchema, "union.int"));
expected.put("long", changeName(inputSchema, "union.long"));
expected.put("float", changeName(inputSchema, "union.float"));
expected.put("double", changeName(inputSchema, "union.double"));
expected.put("string", changeName(inputSchema, "union.string"));
expected.put("rec1", changeName(inputSchema, "union.rec1"));
expected.put("rec2", changeName(inputSchema, "union.rec2"));
actual = UnionSplitter.getOutputSchemas(inputSchema, "b", false, collector);
Assert.assertEquals(expected, actual);
Assert.assertEquals(0, collector.getValidationFailures().size());
}
Aggregations